-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
99 lines (94 loc) · 3.12 KB
/
tests.js
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
const consoleErrorStyle = "color: red; font-weight: bold;"
const consoleGoodStyle = "color: green; font-weight: bold;"
let test_pr = null;
const myTests = [
{
name: "PositionTest1",
desc: "Test that position is calculated correctly",
func: () => {
test_pr.setProgress(0.5);
return test_pr.pos.x === 50 && test_pr.pos.y === 0;
}
},
{
name: "PositionTest2",
desc: "Test that position is calculated correctly",
func: () => {
test_pr.setProgress(0.4);
return test_pr.pos.x === 80 && test_pr.pos.y === 40;
}
},
{
name: "PositionTest3",
desc: "Test that position is calculated correctly",
func: () => {
test_pr.setProgress(0.9);
return test_pr.pos.x === 70 && test_pr.pos.y === 40;
}
},
{
name: "PositionTest4",
desc: "Test that position is calculated correctly",
func: () => {
let pr2 = new RectanglePolyRhythm2d({
xRhythm: 2,
yRhythm: 3,
init_pos: createVector(10, 10),
xBounds: new Bounds(10, 90),
yBounds: new Bounds(10, 90),
})
pr2.setProgress(0);
return pr2.pos.x === 10 && pr2.pos.y === 10;
}
},
{
name: "RhythmListValidationTest1",
desc: "Test that the Patch class validates rhythm lists correctly",
func: () => {
let lst = [0,1,2,3,4,5,6,7,8];
return Patch.rhythmListIsValid(lst);
}
},
{
name: "RhythmListValidationTest2",
desc: "Test that the Patch class validates rhythm lists correctly",
func: () => {
let lst = [-1,0,1,2,3,4,5,6,7,8];
return !Patch.rhythmListIsValid(lst);
}
},
{
name: "ColorValidationTest1",
desc: "Test that the Patch class validates RGB values correctly",
func: () => {
validValues = Patch.colorValuesValidation([-9, 255, 0]);
return !validValues[0] && validValues[1] && validValues[2];
}
},
{
name: "ColorValidationTest4",
desc: "Test that the Patch class validates RGB values correctly",
func: () => {
validValues = Patch.colorValuesValidation([255, 256, -1]);
return validValues[0] && !validValues[1] && !validValues[2];
}
}
]
function runTests(){
test_pr = new RectanglePolyRhythm2d({
xRhythm: 3,
yRhythm: 4,
init_pos: createVector(0, 0),
size: createVector(10, 10),
xBounds: new Bounds(0, 100),
yBounds: new Bounds(0, 100),
})
for(let t of myTests){
// I know, "'== true' bad!" but heres the issue: javascript type coercion.
// I need to know that t.func() actually returned a boolean true value, not just any old truthy value (of which there are many...)
if (t.func() === true)
console.log(`${t.name}: %cPASSED`, consoleGoodStyle);
else
console.log(`${t.name}: %cFAILED`, consoleErrorStyle, `\nDescription: ${t.desc}`);
}
}