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 |
// This is a tests simulation type!
import static oms3.SimBuilder.instance as OMS3
OMS3.tests {
// the component to test.
model (classname:"ex09.Component")
// Run this test once, the pre closure sets the @In before execution,
// the 'post' closure test the @Out after execution.
test(name:"1: single call",
// this is a closure, 'c' is the component
pre: { c ->
// fields can be accessed
c.tempC = 30
},
post:{ c ->
// using groovy asserts
assert c.tempF == 86.0
//println c.tempF
//more statements can follow here.
}
)
// Run this test against each input value from 'data'
test(name:"2: multiple data input",
// data set with inputs
data:['tempC', 1, 2, 3, 5, 6, 7 ],
post:{ c ->
print c.tempF
}
)
// Random number generator within the script.
Random r = new Random()
// Run this test 100 times, let a single test fail if it runs
// longer than 200ms. Create random 'tempC' values from 10 ... 15 degC as input;
// test if the output falls in a expected range.
test(name: "3: randomized input", count: 100, timeout:200,
pre:{ c ->
c.tempC = 10 + (5 * r.nextDouble())
},
post:{ c->
assert c.tempF > 50 && c.tempF < 59
}
)
}
|