|
1 |
| -require_relative "../../setup_test" |
2 |
| -require_relative "../../../lib/sonicpi/lang/core" |
3 |
| - |
4 |
| -module SonicPi |
5 |
| - class RandomTester < Minitest::Test |
6 |
| - include SonicPi::Lang::Core |
7 |
| - |
8 |
| - def test_rand |
9 |
| - use_random_source :white |
10 |
| - rand_reset |
11 |
| - assert_equal(rand, 0.75006103515625) |
12 |
| - assert_equal(rand, 0.733917236328125) |
13 |
| - assert_equal(rand, 0.464202880859375) |
14 |
| - assert_equal(rand, 0.24249267578125) |
15 |
| - end |
16 |
| - |
17 |
| - def test_rand_type |
18 |
| - use_random_source :white |
19 |
| - rand_reset |
20 |
| - assert_equal(rand, 0.75006103515625) |
21 |
| - assert_equal(rand, 0.733917236328125) |
22 |
| - use_random_source :white |
23 |
| - rand_reset |
24 |
| - assert_equal(rand, 0.75006103515625) |
25 |
| - assert_equal(rand, 0.733917236328125) |
26 |
| - use_random_source :pink |
27 |
| - rand_reset |
28 |
| - assert_equal(rand, 0.47808837890625) |
29 |
| - assert_equal(rand, 0.56011962890625) |
30 |
| - use_random_source :light_pink |
31 |
| - rand_reset |
32 |
| - assert_equal(rand, 0.53851318359375) |
33 |
| - assert_equal(rand, 0.54705810546875) |
34 |
| - use_random_source :dark_pink |
35 |
| - rand_reset |
36 |
| - assert_equal(rand, 0.442596435546875) |
37 |
| - assert_equal(rand, 0.443756103515625) |
38 |
| - use_random_source :perlin |
39 |
| - rand_reset |
40 |
| - assert_equal(rand, 0.546478271484375) |
41 |
| - assert_equal(rand, 0.573150634765625) |
42 |
| - with_random_source :white do |
43 |
| - # matches 3rd value from test_rand |
44 |
| - # index is not reset when changing type |
45 |
| - assert_equal(rand, 0.464202880859375) |
46 |
| - end |
47 |
| - |
48 |
| - # last stream type was perlin |
49 |
| - assert_equal(rand, 0.597015380859375) |
50 |
| - |
51 |
| - # return to default |
52 |
| - use_random_source :white |
53 |
| - end |
54 |
| - |
55 |
| - def test_rand_reset |
56 |
| - rand_reset |
57 |
| - assert_equal(rand, 0.75006103515625) |
58 |
| - assert_equal(rand, 0.733917236328125) |
59 |
| - rand_reset |
60 |
| - assert_equal(rand, 0.75006103515625) |
61 |
| - assert_equal(rand, 0.733917236328125) |
62 |
| - end |
63 |
| - |
64 |
| - def test_rand_skip |
65 |
| - rand_reset |
66 |
| - assert_equal(rand, 0.75006103515625) |
67 |
| - rand_skip |
68 |
| - assert_equal(rand, 0.464202880859375) |
69 |
| - end |
70 |
| - |
71 |
| - def test_rand_skip_with_args |
72 |
| - rand_reset |
73 |
| - assert_equal(rand, 0.75006103515625) |
74 |
| - rand_skip(1) |
75 |
| - assert_equal(rand, 0.464202880859375) |
76 |
| - rand_skip(0) |
77 |
| - assert_equal(rand, 0.24249267578125) |
78 |
| - end |
79 |
| - |
80 |
| - def test_rand_multi_skip |
81 |
| - rand_reset |
82 |
| - assert_equal(rand, 0.75006103515625) |
83 |
| - rand_skip(2) |
84 |
| - assert_equal(rand, 0.24249267578125) |
85 |
| - end |
86 |
| - |
87 |
| - def test_rand_multi_skip2 |
88 |
| - rand_reset |
89 |
| - 99.times{rand} |
90 |
| - a = rand |
91 |
| - rand_reset |
92 |
| - rand_skip(99) |
93 |
| - assert_equal(rand, a) |
94 |
| - end |
95 |
| - |
96 |
| - def test_rand_back |
97 |
| - rand_reset |
98 |
| - a = rand |
99 |
| - b = rand |
100 |
| - c = rand |
101 |
| - rand_back |
102 |
| - assert_equal(rand, c) |
103 |
| - rand_back(2) |
104 |
| - assert_equal(rand, b) |
105 |
| - assert_equal(rand, c) |
106 |
| - rand_back(3) |
107 |
| - assert_equal(rand, a) |
108 |
| - assert_equal(rand, b) |
109 |
| - assert_equal(rand, c) |
110 |
| - end |
111 |
| - |
112 |
| - def test_rrand_handles_0_range |
113 |
| - assert_equal(1, rrand(1,1)) |
114 |
| - end |
115 |
| - |
116 |
| - def test_rrand_i_handles_0_range |
117 |
| - assert_equal(1, rrand_i(1,1)) |
118 |
| - end |
119 |
| - |
120 |
| - def test_rand_handles_0 |
121 |
| - number = rand(0) |
122 |
| - assert(number >= 0 && number < 1) |
123 |
| - end |
124 |
| - |
125 |
| - def test_rand_i_handles_0 |
126 |
| - number = rand_i(0) |
127 |
| - assert(number == 0) |
128 |
| - end |
129 |
| - |
130 |
| - def test_rand_only_returns_floats |
131 |
| - assert_equal(Float, rand(0..10).class) |
132 |
| - assert_equal(Float, rand(1).class) |
133 |
| - end |
134 |
| - |
135 |
| - def test_rand_i_only_returns_ints |
136 |
| - assert_equal(Integer, rand_i(0..10).class) |
137 |
| - assert_equal(Integer, rand_i(1.5).class) |
138 |
| - end |
139 |
| - |
140 |
| - def test_rand_look |
141 |
| - rand_reset |
142 |
| - assert_equal(rand_look, 0.75006103515625) |
143 |
| - |
144 |
| - rand_reset |
145 |
| - assert_equal(rand_look(0.5), 0.375030517578125) |
146 |
| - end |
147 |
| - |
148 |
| - def test_rand_i_look |
149 |
| - rand_reset |
150 |
| - assert_equal(rand_i_look, 1) |
151 |
| - |
152 |
| - rand_reset |
153 |
| - assert_equal(rand_i_look(100), 75) |
154 |
| - end |
155 |
| - end |
156 |
| -end |
| 1 | +require_relative "../../setup_test" |
| 2 | +require_relative "../../../lib/sonicpi/lang/core" |
| 3 | + |
| 4 | +module SonicPi |
| 5 | + class RandomTester < Minitest::Test |
| 6 | + include SonicPi::Lang::Core |
| 7 | + |
| 8 | + def test_rand |
| 9 | + use_random_source :white |
| 10 | + rand_reset |
| 11 | + assert_equal(rand, 0.75006103515625) |
| 12 | + assert_equal(rand, 0.733917236328125) |
| 13 | + assert_equal(rand, 0.464202880859375) |
| 14 | + assert_equal(rand, 0.24249267578125) |
| 15 | + end |
| 16 | + |
| 17 | + def test_rand_type |
| 18 | + use_random_source :white |
| 19 | + rand_reset |
| 20 | + assert_equal(rand, 0.75006103515625) |
| 21 | + assert_equal(rand, 0.733917236328125) |
| 22 | + use_random_source :white |
| 23 | + rand_reset |
| 24 | + assert_equal(rand, 0.75006103515625) |
| 25 | + assert_equal(rand, 0.733917236328125) |
| 26 | + use_random_source :pink |
| 27 | + rand_reset |
| 28 | + assert_equal(rand, 0.47808837890625) |
| 29 | + assert_equal(rand, 0.56011962890625) |
| 30 | + use_random_source :light_pink |
| 31 | + rand_reset |
| 32 | + assert_equal(rand, 0.53851318359375) |
| 33 | + assert_equal(rand, 0.54705810546875) |
| 34 | + use_random_source :dark_pink |
| 35 | + rand_reset |
| 36 | + assert_equal(rand, 0.442596435546875) |
| 37 | + assert_equal(rand, 0.443756103515625) |
| 38 | + use_random_source :perlin |
| 39 | + rand_reset |
| 40 | + assert_equal(rand, 0.546478271484375) |
| 41 | + assert_equal(rand, 0.573150634765625) |
| 42 | + with_random_source :white do |
| 43 | + # matches 3rd value from test_rand |
| 44 | + # index is not reset when changing type |
| 45 | + assert_equal(rand, 0.464202880859375) |
| 46 | + end |
| 47 | + |
| 48 | + # last stream type was perlin |
| 49 | + assert_equal(rand, 0.597015380859375) |
| 50 | + |
| 51 | + # return to default |
| 52 | + use_random_source :white |
| 53 | + end |
| 54 | + |
| 55 | + def test_rand_reset |
| 56 | + rand_reset |
| 57 | + assert_equal(rand, 0.75006103515625) |
| 58 | + assert_equal(rand, 0.733917236328125) |
| 59 | + rand_reset |
| 60 | + assert_equal(rand, 0.75006103515625) |
| 61 | + assert_equal(rand, 0.733917236328125) |
| 62 | + end |
| 63 | + |
| 64 | + def test_rand_skip |
| 65 | + rand_reset |
| 66 | + assert_equal(rand, 0.75006103515625) |
| 67 | + rand_skip |
| 68 | + assert_equal(rand, 0.464202880859375) |
| 69 | + end |
| 70 | + |
| 71 | + def test_rand_skip_with_args |
| 72 | + rand_reset |
| 73 | + assert_equal(rand, 0.75006103515625) |
| 74 | + rand_skip(1) |
| 75 | + assert_equal(rand, 0.464202880859375) |
| 76 | + rand_skip(0) |
| 77 | + assert_equal(rand, 0.24249267578125) |
| 78 | + end |
| 79 | + |
| 80 | + def test_rand_multi_skip |
| 81 | + rand_reset |
| 82 | + assert_equal(rand, 0.75006103515625) |
| 83 | + rand_skip(2) |
| 84 | + assert_equal(rand, 0.24249267578125) |
| 85 | + end |
| 86 | + |
| 87 | + def test_rand_multi_skip2 |
| 88 | + rand_reset |
| 89 | + 99.times{rand} |
| 90 | + a = rand |
| 91 | + rand_reset |
| 92 | + rand_skip(99) |
| 93 | + assert_equal(rand, a) |
| 94 | + end |
| 95 | + |
| 96 | + def test_rand_back |
| 97 | + rand_reset |
| 98 | + a = rand |
| 99 | + b = rand |
| 100 | + c = rand |
| 101 | + rand_back |
| 102 | + assert_equal(rand, c) |
| 103 | + rand_back(2) |
| 104 | + assert_equal(rand, b) |
| 105 | + assert_equal(rand, c) |
| 106 | + rand_back(3) |
| 107 | + assert_equal(rand, a) |
| 108 | + assert_equal(rand, b) |
| 109 | + assert_equal(rand, c) |
| 110 | + end |
| 111 | + |
| 112 | + def test_rrand_handles_0_range |
| 113 | + assert_equal(1, rrand(1,1)) |
| 114 | + end |
| 115 | + |
| 116 | + def test_rrand_i_handles_0_range |
| 117 | + assert_equal(1, rrand_i(1,1)) |
| 118 | + end |
| 119 | + |
| 120 | + def test_rand_handles_0 |
| 121 | + number = rand(0) |
| 122 | + assert(number >= 0 && number < 1) |
| 123 | + end |
| 124 | + |
| 125 | + def test_rand_i_handles_0 |
| 126 | + number = rand_i(0) |
| 127 | + assert(number == 0) |
| 128 | + end |
| 129 | + |
| 130 | + def test_rand_only_returns_floats |
| 131 | + assert_equal(Float, rand(0..10).class) |
| 132 | + assert_equal(Float, rand(1).class) |
| 133 | + end |
| 134 | + |
| 135 | + def test_rand_i_only_returns_ints |
| 136 | + assert_equal(Integer, rand_i(0..10).class) |
| 137 | + assert_equal(Integer, rand_i(1.5).class) |
| 138 | + end |
| 139 | + |
| 140 | + def test_rand_look |
| 141 | + rand_reset |
| 142 | + assert_equal(rand_look, 0.75006103515625) |
| 143 | + |
| 144 | + rand_reset |
| 145 | + assert_equal(rand_look(0.5), 0.375030517578125) |
| 146 | + end |
| 147 | + |
| 148 | + def test_rand_i_look |
| 149 | + rand_reset |
| 150 | + assert_equal(rand_i_look, 1) |
| 151 | + |
| 152 | + rand_reset |
| 153 | + assert_equal(rand_i_look(100), 75) |
| 154 | + end |
| 155 | + end |
| 156 | +end |
0 commit comments