-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestrandclassarr2norand.d
103 lines (92 loc) · 1.8 KB
/
testrandclassarr2norand.d
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import esdl.rand;
class Zoo {
}
class Foo {
void pre_randomize() {
import std.stdio;
// writeln("Foo: pre_randomize()");
}
void post_randomize() {
import std.stdio;
// writeln("Foo: post_randomize()");
}
// mixin randomization;
@rand private ubyte frop;
@rand private ubyte paaa;
@rand private ubyte maaa;
@rand private ubyte free;
constraint! q{
// frop > 50;
paaa + frop + maaa == 100;
paaa < 100;
maaa < 100;
} gt50;
public:
void display() {
import std.stdio;
writeln("frop is: ", frop, " paaa is: ", paaa,
" maaa is: ", maaa, " free is: ", free);
}
}
class Bar {
mixin randomization;
this() {
foos.length = 4;
foreach (i, ref foo1; foos) {
foo1.length = 4;
foreach (j, ref foo2; foo1) {
foo2 = new Foo;
foo2.frop = cast(ubyte) (i * 10 + j);
}
}
bar.length = 4;
foreach (i, ref f; bar) {
f.length = 4;
}
}
Zoo zoo;
@rand Foo[][] foos;
@rand ubyte[][] bar;
constraint!q{
// foos.length == 4;
// foos.length > 2;
foreach (i, foo1; foos) {
foreach (j, foo2; foo1) {
foo2.frop == bar[i][j];
}
}
} frop_cst;
void display() {
import std.stdio;
writefln("bar: %s", bar);
foreach (i, foo1; foos) {
foreach (j, foo2; foo1) {
writefln("i: %d, j: %d", i, j);
foo2.display();
}
}
}
void pre_randomize() {
import std.stdio;
// writeln("Bar: pre_randomize()");
}
void post_randomize() {
import std.stdio;
// writeln("Bar: post_randomize()");
}
}
void main()
{
import std.stdio;
Bar bar = new Bar();
bar.rand_mode!q{foos}(false);
for (size_t i=0; i!=1; ++i) {
bar.randomize();
bar.display();
}
bar.rand_mode!q{foos}(true);
for (size_t i=0; i!=1; ++i) {
bar.randomize();
bar.display();
}
}