5 // random uint less than n
6 fn under(r : rand::rng, n : uint) -> uint { assert n != 0u; r.next() as uint % n }
8 // random choice from a vec
9 fn choice<T: copy>(r : rand::rng, v : [const T]) -> T { assert vec::len(v) != 0u; v[under(r, vec::len(v))] }
11 // k in n chance of being true
12 fn likelihood(r : rand::rng, k : uint, n : uint) -> bool { under(r, n) < k }
15 const iters : uint = 1000u;
16 const vlen : uint = 100u;
25 mut b : ~maybe_pointy,
26 mut c : @maybe_pointy,
31 mut m : [maybe_pointy],
32 mut n : [mut maybe_pointy],
33 mut o : {x : int, y : maybe_pointy}
35 // To add: objects; ifaces; anything type-parameterized?
37 fn empty_pointy() -> @pointy {
48 mut o : {x : 0, y : none}
52 fn nopP(_x : @pointy) { }
55 fn test_cycles(r : rand::rng, k: uint, n: uint)
57 let v : [mut @pointy] = [mut];
59 // Create a graph with no edges
61 v += [mut empty_pointy()];
64 // Fill in the graph with random edges, with density k/n
66 if (likelihood(r, k, n)) { v[i].a = p(choice(r, v)); }
67 if (likelihood(r, k, n)) { v[i].b = ~p(choice(r, v)); }
68 if (likelihood(r, k, n)) { v[i].c = @p(choice(r, v)); }
70 if (likelihood(r, k, n)) { v[i].f = bind nopP(choice(r, v)); }
71 //if (false) { v[i].g = bind (fn~(_x: @pointy) { })(choice(r, v)); }
72 // https://github.com/mozilla/rust/issues/1899
74 if (likelihood(r, k, n)) { v[i].m = [p(choice(r, v))]; }
75 if (likelihood(r, k, n)) { v[i].n += [mut p(choice(r, v))]; }
76 if (likelihood(r, k, n)) { v[i].o = {x: 0, y: p(choice(r, v))}; }
79 // Drop refs one at a time
89 test_cycles(r, i, iters);