@@ -10,93 +10,75 @@ import XCTest
10
10
@testable import EntropyString
11
11
12
12
class EntropyTests : XCTestCase {
13
- var powers : [ Entropy . Power ] !
14
-
15
- override func setUp( ) {
16
- super. setUp ( )
17
- powers = [ . ten01, . ten02, . ten03, . ten04, . ten05, . ten06, . ten07, . ten08, . ten09, . ten10,
18
- . ten11, . ten12, . ten13, . ten14, . ten15, . ten16, . ten17, . ten18, . ten19, . ten10,
19
- . ten21, . ten22, . ten23, . ten24, . ten25, . ten26, . ten27, . ten28, . ten29, . ten30] as [ Entropy . Power ]
20
-
21
- }
22
13
23
14
func testZeroEntropy( ) {
24
- entropyBits0 ( 0 , 0 , 0 )
25
- for power in powers {
26
- entropyBits0 ( 0 , power, 0 )
27
- }
15
+ entropyBits_r0 ( 0 , 0 , 0 )
28
16
}
29
17
30
- func testBitsFloatFloat ( ) {
31
- entropyBits2 ( 10 , 1000 , 15.46 )
32
- entropyBits2 ( 10 , 10000 , 18.78 )
33
- entropyBits2 ( 10 , 100000 , 22.10 )
18
+ func testBitsIntInt ( ) {
19
+ entropyBits_r2 ( 10 , 1000 , 15.46 )
20
+ entropyBits_r2 ( 10 , 10000 , 18.78 )
21
+ entropyBits_r2 ( 10 , 100000 , 22.10 )
34
22
35
- entropyBits2 ( 100 , 1000 , 22.24 )
36
- entropyBits2 ( 100 , 10000 , 25.56 )
37
- entropyBits2 ( 100 , 100000 , 28.88 )
23
+ entropyBits_r2 ( 100 , 1000 , 22.24 )
24
+ entropyBits_r2 ( 100 , 10000 , 25.56 )
25
+ entropyBits_r2 ( 100 , 100000 , 28.88 )
38
26
39
- entropyBits2 ( 1000 , 1000 , 28.90 )
40
- entropyBits2 ( 1000 , 10000 , 32.22 )
41
- entropyBits2 ( 1000 , 100000 , 35.54 )
27
+ entropyBits_r2 ( 1000 , 1000 , 28.90 )
28
+ entropyBits_r2 ( 1000 , 10000 , 32.22 )
29
+ entropyBits_r2 ( 1000 , 100000 , 35.54 )
42
30
43
- entropyBits2 ( 10000 , 1000 , 35.54 )
44
- entropyBits2 ( 10000 , 10000 , 38.86 )
45
- entropyBits2 ( 10000 , 100000 , 42.18 )
31
+ entropyBits_r2 ( 10000 , 1000 , 35.54 )
32
+ entropyBits_r2 ( 10000 , 10000 , 38.86 )
33
+ entropyBits_r2 ( 10000 , 100000 , 42.18 )
46
34
47
- entropyBits2 ( 100000 , 1000 , 42.19 )
48
- entropyBits2 ( 100000 , 10000 , 45.51 )
49
- entropyBits2 ( 100000 , 100000 , 48.83 )
35
+ entropyBits_r2 ( 100000 , 1000 , 42.19 )
36
+ entropyBits_r2 ( 100000 , 10000 , 45.51 )
37
+ entropyBits_r2 ( 100000 , 100000 , 48.83 )
50
38
}
51
39
52
- func testBitsFloatPower ( ) {
53
- entropyBits2 ( 10 , . ten03 , 15.46 )
54
- entropyBits2 ( 10 , . ten04 , 18.78 )
55
- entropyBits2 ( 10 , . ten05 , 22.10 )
40
+ func testBitsIntFloat ( ) {
41
+ entropyBits_r2 ( 10 , 1.0e03 , 15.46 )
42
+ entropyBits_r2 ( 10 , 1.0e04 , 18.78 )
43
+ entropyBits_r2 ( 10 , 1.0e05 , 22.10 )
56
44
57
- entropyBits2 ( 100 , . ten03 , 22.24 )
58
- entropyBits2 ( 100 , . ten04 , 25.56 )
59
- entropyBits2 ( 100 , . ten05 , 28.88 )
45
+ entropyBits_r2 ( 100 , 1.0e03 , 22.24 )
46
+ entropyBits_r2 ( 100 , 1.0e04 , 25.56 )
47
+ entropyBits_r2 ( 100 , 1.0e05 , 28.88 )
60
48
61
- entropyBits2 ( 1000 , . ten03 , 28.90 )
62
- entropyBits2 ( 1000 , . ten04 , 32.22 )
63
- entropyBits2 ( 1000 , . ten05 , 35.54 )
49
+ entropyBits_r2 ( 1000 , 1.0e03 , 28.90 )
50
+ entropyBits_r2 ( 1000 , 1.0e04 , 32.22 )
51
+ entropyBits_r2 ( 1000 , 1.0e05 , 35.54 )
64
52
65
- entropyBits2 ( 10000 , . ten03 , 35.54 )
66
- entropyBits2 ( 10000 , . ten04 , 38.86 )
67
- entropyBits2 ( 10000 , . ten05 , 42.18 )
53
+ entropyBits_r2 ( 10000 , 1.0e03 , 35.54 )
54
+ entropyBits_r2 ( 10000 , 1.0e04 , 38.86 )
55
+ entropyBits_r2 ( 10000 , 1.0e05 , 42.18 )
68
56
69
- entropyBits2 ( 100000 , . ten03 , 42.19 )
70
- entropyBits2 ( 100000 , . ten04 , 45.51 )
71
- entropyBits2 ( 100000 , . ten05 , 48.83 )
57
+ entropyBits_r2 ( 100000 , 1.0e03 , 42.19 )
58
+ entropyBits_r2 ( 100000 , 1.0e04 , 45.51 )
59
+ entropyBits_r2 ( 100000 , 1.0e05 , 48.83 )
72
60
}
73
61
74
- func testBitsPowerPower( ) {
75
- entropyBits2 ( . ten01, . ten03, 15.46 )
76
- entropyBits2 ( . ten01, . ten04, 18.78 )
77
- entropyBits2 ( . ten01, . ten05, 22.10 )
78
-
79
- entropyBits2 ( . ten02, . ten03, 22.24 )
80
- entropyBits2 ( . ten02, . ten04, 25.56 )
81
- entropyBits2 ( . ten02, . ten05, 28.88 )
62
+ func testBitsFloatFloat( ) {
63
+ entropyBits_r2 ( 1.0e01 , 1.0e03 , 15.46 )
64
+ entropyBits_r2 ( 1.0e01 , 1.0e04 , 18.78 )
65
+ entropyBits_r2 ( 1.0e01 , 1.0e05 , 22.10 )
82
66
83
- entropyBits2 ( . ten03 , . ten03 , 28.90 )
84
- entropyBits2 ( . ten03 , . ten04 , 32.22 )
85
- entropyBits2 ( . ten03 , . ten05 , 35.54 )
67
+ entropyBits_r2 ( 1.0e02 , 1.0e03 , 22.24 )
68
+ entropyBits_r2 ( 1.0e02 , 1.0e04 , 25.56 )
69
+ entropyBits_r2 ( 1.0e02 , 1.0e05 , 28.88 )
86
70
87
- entropyBits2 ( . ten04 , . ten03 , 35.54 )
88
- entropyBits2 ( . ten04 , . ten04 , 38.86 )
89
- entropyBits2 ( . ten04 , . ten05 , 42.18 )
71
+ entropyBits_r2 ( 1.0e03 , 1.0e03 , 28.90 )
72
+ entropyBits_r2 ( 1.0e03 , 1.0e04 , 32.22 )
73
+ entropyBits_r2 ( 1.0e03 , 1.0e05 , 35.54 )
90
74
91
- entropyBits2 ( . ten05 , . ten03 , 42.19 )
92
- entropyBits2 ( . ten05 , . ten04 , 45.51 )
93
- entropyBits2 ( . ten05 , . ten05 , 48.83 )
75
+ entropyBits_r2 ( 1.0e04 , 1.0e03 , 35.54 )
76
+ entropyBits_r2 ( 1.0e04 , 1.0e04 , 38.86 )
77
+ entropyBits_r2 ( 1.0e04 , 1.0e05 , 42.18 )
94
78
95
- for total in powers {
96
- for risk in powers {
97
- _ = Entropy . bits ( for: total, risk: risk)
98
- }
99
- }
79
+ entropyBits_r2 ( 1.0e05 , 1.0e03 , 42.19 )
80
+ entropyBits_r2 ( 1.0e05 , 1.0e04 , 45.51 )
81
+ entropyBits_r2 ( 1.0e05 , 1.0e05 , 48.83 )
100
82
}
101
83
102
84
func testPreshingTable( ) {
@@ -194,38 +176,17 @@ class EntropyTests: XCTestCase {
194
176
entropyBits0 ( . ten09, . ten30, 158 )
195
177
}
196
178
197
- func entropyBits0( _ numStrings: Float , _ risk: Float , _ expected: Float ) {
198
- let bits = Entropy . bits ( for: numStrings, risk: risk)
199
- XCTAssertEqual ( roundf ( bits) , expected)
200
- }
201
179
202
- func entropyBits0( _ numStrings: Float , _ risk: Entropy . Power , _ expected: Float ) {
203
- let bits = Entropy . bits ( for: numStrings, risk: risk)
204
- XCTAssertEqual ( roundf ( bits) , expected)
205
180
}
206
181
207
- func entropyBits0 ( _ numStrings: Entropy . Power , _ risk: Entropy . Power , _ expected: Float ) {
182
+ func entropyBits_r0 ( _ numStrings: Float , _ risk: Float , _ expected: Float ) {
208
183
let bits = Entropy . bits ( for: numStrings, risk: risk)
209
184
XCTAssertEqual ( roundf ( bits) , expected)
210
185
}
211
186
212
- func checkEqual2( _ num: Float , _ expected: Float ) {
213
- XCTAssertEqual ( roundf ( num * 100 ) / 100 , expected)
214
- }
215
-
216
- func entropyBits2( _ numStrings: Float , _ risk: Float , _ expected: Float ) {
217
- let bits = Entropy . bits ( for: numStrings, risk: risk)
218
- checkEqual2 ( bits, expected)
219
- }
220
-
221
- func entropyBits2( _ numStrings: Float , _ risk: Entropy . Power , _ expected: Float ) {
222
- let bits = Entropy . bits ( for: numStrings, risk: risk)
223
- checkEqual2 ( bits, expected)
224
- }
225
-
226
- func entropyBits2( _ numStrings: Entropy . Power , _ risk: Entropy . Power , _ expected: Float ) {
187
+ func entropyBits_r2( _ numStrings: Float , _ risk: Float , _ expected: Float ) {
227
188
let bits = Entropy . bits ( for: numStrings, risk: risk)
228
- checkEqual2 ( bits, expected)
189
+ XCTAssertEqual ( roundf ( bits* 100 ) / 100 , expected)
229
190
}
230
191
}
231
192
@@ -234,9 +195,9 @@ extension EntropyTests {
234
195
static var tests : [ ( String , ( EntropyTests ) -> ( ) throws -> ( ) ) ] {
235
196
return [
236
197
( " testZeroEntropy " , testZeroEntropy) ,
198
+ ( " testBitsIntInt " , testBitsIntInt) ,
199
+ ( " testBitsIntFloat " , testBitsIntFloat) ,
237
200
( " testBitsFloatFloat " , testBitsFloatFloat) ,
238
- ( " testBitsFloatPower " , testBitsFloatPower) ,
239
- ( " testBitsPowerPower " , testBitsPowerPower) ,
240
201
( " testPreshingTable " , testPreshingTable)
241
202
]
242
203
}
0 commit comments