Debian Codegraph @

src/test/03-Modules/std01.ck

raw
1
2 [[1, 0, 10, 1],
3 [5, 0, 10, 5],
4 [-1, 0, 10, 0],
5 [15, 0, 10, 10]]
6 @=> int t1[][]; // Std.clamp
7
8 [[0.5, 0, 1, 0.5],
9 [2.0, 0, 1, 1],
10 [-10.0, 0, 1, 0],
11 [0.0, 0, 1, 0],
12 [1.0, 0, 1, 1]]
13 @=> float t2[][]; // Std.clampf
14
15 [[0.0, 1.0],
16 [-20.0, 0.1],
17 [20.0, 10],
18 [-60.0, 0.001]]
19 @=> float t3[][]; // Std.dbtolin
20
21 [[1.0, 0.0],
22 [0.1, -20.0],
23 [10.0, 20.0],
24 [0.001, -60.0]]
25 @=> float t4[][]; // Std.lintodb
26
27 for(int i; i < t1.size(); i++)
28 {
29 if(Std.clamp(t1[i][0], t1[i][1], t1[i][2]) != t1[i][3])
30 {
31 <<< "failure" >>>;
32 me.exit();
33 }
34 }
35
36 for(int i; i < t2.size(); i++)
37 {
38 if(Std.clampf(t2[i][0], t2[i][1], t2[i][2]) != t2[i][3])
39 {
40 <<< "failure" >>>;
41 me.exit();
42 }
43 }
44
45 for(int i; i < t3.size(); i++)
46 {
47 // test for floating point equivalence
48 // alternative 1.4.1.1 or later: Math.equal()
49 if( Math.fabs( Std.dbtolin(t3[i][0]) - t3[i][1] ) > 0.000001 )
50 // (FYI 1.4.1.1 and later can use Math.isEqual())
51 // if( !Math.isEqual( Std.dbtolin(t3[i][0]), t3[i][1] ) )
52 {
53 <<< "failure" >>>;
54 me.exit();
55 }
56 }
57
58 for(int i; i < t4.size(); i++)
59 {
60 if(Std.lintodb(t4[i][0]) != t4[i][1])
61 {
62 <<< "failure" >>>;
63 me.exit();
64 }
65 }
66
67 <<< "success" >>>;
68