File: gen_test.js

package info (click to toggle)
node-configurable-http-proxy 4.5.3%2B~cs15.2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,580 kB
  • sloc: javascript: 10,340; sh: 27; makefile: 22
file content (38 lines) | stat: -rw-r--r-- 820 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// generates a test case to STDOUT

var no_dups = false; // set to true if you don't want duplicate inserts
var num_inserts = 100000;

function randInt(start, end) {
    return Math.floor(Math.random()*(end-start + 1)) + start;
}

function get_node_to_remove() {
    var idx = randInt(0, added.length - 1);
    return added.splice(idx, 1)[0];
}


var nums = [];
var added = [];
var ahash = {};
for(var i=0; i < num_inserts; i++) {
    do {
        var n = randInt(1, 1000000000);
    } while(no_dups && ahash[n]);
    added.push(n);
    nums.push(n);
    if(no_dups)
        ahash[n] = true;

    if(Math.random() < .3) {
        // remove a node
        nums.push(-get_node_to_remove());
    }
}

// remove the rest, randomly
while(added.length > 0)
    nums.push(-get_node_to_remove());

console.log(nums.join('\n'));