@@ -20,23 +20,23 @@ final class HistogramDataAccessTests: XCTestCase {
20
20
private static let numberOfSignificantValueDigits = SignificantDigits . three
21
21
private static let value : UInt64 = 4
22
22
23
- private static var histogram = Histogram < UInt64 > ( highestTrackableValue: highestTrackableValue, numberOfSignificantValueDigits: numberOfSignificantValueDigits)
23
+ private var histogram = Histogram < UInt64 > ( highestTrackableValue: highestTrackableValue, numberOfSignificantValueDigits: numberOfSignificantValueDigits)
24
24
25
- private static var scaledHistogram = Histogram < UInt64 > (
25
+ private var scaledHistogram = Histogram < UInt64 > (
26
26
lowestDiscernibleValue: 1_000 ,
27
27
highestTrackableValue: highestTrackableValue * 512 ,
28
28
numberOfSignificantValueDigits: numberOfSignificantValueDigits
29
29
)
30
30
31
- private static var rawHistogram = Histogram < UInt64 > ( highestTrackableValue: highestTrackableValue, numberOfSignificantValueDigits: numberOfSignificantValueDigits)
31
+ private var rawHistogram = Histogram < UInt64 > ( highestTrackableValue: highestTrackableValue, numberOfSignificantValueDigits: numberOfSignificantValueDigits)
32
32
33
- private static var scaledRawHistogram = Histogram < UInt64 > (
33
+ private var scaledRawHistogram = Histogram < UInt64 > (
34
34
lowestDiscernibleValue: 1_000 ,
35
35
highestTrackableValue: highestTrackableValue * 512 ,
36
36
numberOfSignificantValueDigits: numberOfSignificantValueDigits
37
37
)
38
38
39
- override static func setUp( ) {
39
+ override func setUp( ) {
40
40
// Log hypothetical scenario: 100 seconds of "perfect" 1msec results, sampled
41
41
// 100 times per second (10,000 results), followed by a 100 second pause with
42
42
// a single (100 second) recorded result. Recording is done indicating an expected
@@ -54,33 +54,33 @@ final class HistogramDataAccessTests: XCTestCase {
54
54
}
55
55
56
56
func testScalingEquivalence( ) {
57
- XCTAssertEqual ( Self . histogram. mean * 512 , Self . scaledHistogram. mean, accuracy: Self . scaledHistogram. mean * 0.000001 , " averages should be equivalent " )
58
- XCTAssertEqual ( Self . histogram. totalCount, Self . scaledHistogram. totalCount, " total count should be the same " )
59
- XCTAssertEqual ( Self . scaledHistogram. highestEquivalentForValue ( Self . histogram. valueAtPercentile ( 99.0 ) * 512 ) ,
60
- Self . scaledHistogram. highestEquivalentForValue ( Self . scaledHistogram. valueAtPercentile ( 99.0 ) ) , " 99%'iles should be equivalent " )
61
- XCTAssertEqual ( Self . scaledHistogram. highestEquivalentForValue ( Self . histogram. max * 512 ) , Self . scaledHistogram. max, " Max should be equivalent " )
57
+ XCTAssertEqual ( histogram. mean * 512 , scaledHistogram. mean, accuracy: scaledHistogram. mean * 0.000001 , " averages should be equivalent " )
58
+ XCTAssertEqual ( histogram. totalCount, scaledHistogram. totalCount, " total count should be the same " )
59
+ XCTAssertEqual ( scaledHistogram. highestEquivalentForValue ( histogram. valueAtPercentile ( 99.0 ) * 512 ) ,
60
+ scaledHistogram. highestEquivalentForValue ( scaledHistogram. valueAtPercentile ( 99.0 ) ) , " 99%'iles should be equivalent " )
61
+ XCTAssertEqual ( scaledHistogram. highestEquivalentForValue ( histogram. max * 512 ) , scaledHistogram. max, " Max should be equivalent " )
62
62
}
63
63
64
64
func testTotalCount( ) {
65
65
// The overflow value should count in the total count:
66
- XCTAssertEqual ( 10_001 , Self . rawHistogram. totalCount, " Raw total count is 10,001 " )
67
- XCTAssertEqual ( 20_000 , Self . histogram. totalCount, " Total count is 20,000 " )
66
+ XCTAssertEqual ( 10_001 , rawHistogram. totalCount, " Raw total count is 10,001 " )
67
+ XCTAssertEqual ( 20_000 , histogram. totalCount, " Total count is 20,000 " )
68
68
}
69
69
70
70
func testMax( ) {
71
- XCTAssertTrue ( Self . histogram. valuesAreEquivalent ( 100 * 1_000 * 1_000 , Self . histogram. max) )
71
+ XCTAssertTrue ( histogram. valuesAreEquivalent ( 100 * 1_000 * 1_000 , histogram. max) )
72
72
}
73
73
74
74
func testMin( ) {
75
- XCTAssertTrue ( Self . histogram. valuesAreEquivalent ( 1_000 , Self . histogram. min) )
75
+ XCTAssertTrue ( histogram. valuesAreEquivalent ( 1_000 , histogram. min) )
76
76
}
77
77
78
78
func testMean( ) {
79
79
let expectedRawMean = ( ( 10_000.0 * 1_000 ) + ( 1.0 * 100_000_000 ) ) / 10_001 // direct avg. of raw results
80
80
let expectedMean = ( 1_000.0 + 50_000_000.0 ) / 2 // avg. 1 msec for half the time, and 50 sec for other half
81
81
// We expect to see the mean to be accurate to ~3 decimal points (~0.1%):
82
- XCTAssertEqual ( expectedRawMean, Self . rawHistogram. mean, accuracy: expectedRawMean * 0.001 , " Raw mean is \( expectedRawMean) +/- 0.1% " )
83
- XCTAssertEqual ( expectedMean, Self . histogram. mean, accuracy: expectedMean * 0.001 , " Mean is \( expectedMean) +/- 0.1% " )
82
+ XCTAssertEqual ( expectedRawMean, rawHistogram. mean, accuracy: expectedRawMean * 0.001 , " Raw mean is \( expectedRawMean) +/- 0.1% " )
83
+ XCTAssertEqual ( expectedMean, histogram. mean, accuracy: expectedMean * 0.001 , " Mean is \( expectedMean) +/- 0.1% " )
84
84
}
85
85
86
86
func testStdDeviation( ) {
@@ -97,9 +97,9 @@ final class HistogramDataAccessTests: XCTestCase {
97
97
let expectedStdDev = ( expectedSquareDeviationSum / 20_000 ) . squareRoot ( )
98
98
99
99
// We expect to see the standard deviations to be accurate to ~3 decimal points (~0.1%):
100
- XCTAssertEqual ( expectedRawStdDev, Self . rawHistogram. stdDeviation, accuracy: expectedRawStdDev * 0.001 ,
100
+ XCTAssertEqual ( expectedRawStdDev, rawHistogram. stdDeviation, accuracy: expectedRawStdDev * 0.001 ,
101
101
" Raw standard deviation is \( expectedRawStdDev) +/- 0.1% " )
102
- XCTAssertEqual ( expectedStdDev, Self . histogram. stdDeviation, accuracy: expectedStdDev * 0.001 ,
102
+ XCTAssertEqual ( expectedStdDev, histogram. stdDeviation, accuracy: expectedStdDev * 0.001 ,
103
103
" Standard deviation is \( expectedStdDev) +/- 0.1% " )
104
104
}
105
105
@@ -140,33 +140,33 @@ final class HistogramDataAccessTests: XCTestCase {
140
140
}
141
141
142
142
func testValueAtPercentile( ) {
143
- XCTAssertEqual ( 1_000.0 , Double ( Self . rawHistogram. valueAtPercentile ( 30.0 ) ) ,
143
+ XCTAssertEqual ( 1_000.0 , Double ( rawHistogram. valueAtPercentile ( 30.0 ) ) ,
144
144
accuracy: 1_000.0 * 0.001 , " raw 30%'ile is 1 msec +/- 0.1% " )
145
- XCTAssertEqual ( 1_000.0 , Double ( Self . rawHistogram. valueAtPercentile ( 99.0 ) ) ,
145
+ XCTAssertEqual ( 1_000.0 , Double ( rawHistogram. valueAtPercentile ( 99.0 ) ) ,
146
146
accuracy: 1_000.0 * 0.001 , " raw 99%'ile is 1 msec +/- 0.1% " )
147
- XCTAssertEqual ( 1_000.0 , Double ( Self . rawHistogram. valueAtPercentile ( 99.99 ) ) ,
147
+ XCTAssertEqual ( 1_000.0 , Double ( rawHistogram. valueAtPercentile ( 99.99 ) ) ,
148
148
accuracy: 1_000.0 * 0.001 , " raw 99.99%'ile is 1 msec +/- 0.1% " )
149
149
150
- XCTAssertEqual ( 100_000_000.0 , Double ( Self . rawHistogram. valueAtPercentile ( 99.999 ) ) ,
150
+ XCTAssertEqual ( 100_000_000.0 , Double ( rawHistogram. valueAtPercentile ( 99.999 ) ) ,
151
151
accuracy: 100_000_000.0 * 0.001 , " raw 99.999%'ile is 100 sec +/- 0.1% " )
152
- XCTAssertEqual ( 100_000_000.0 , Double ( Self . rawHistogram. valueAtPercentile ( 100.0 ) ) ,
152
+ XCTAssertEqual ( 100_000_000.0 , Double ( rawHistogram. valueAtPercentile ( 100.0 ) ) ,
153
153
accuracy: 100_000_000.0 * 0.001 , " raw 100%'ile is 100 sec +/- 0.1% " )
154
154
155
- XCTAssertEqual ( 1_000.0 , Double ( Self . histogram. valueAtPercentile ( 30.0 ) ) ,
155
+ XCTAssertEqual ( 1_000.0 , Double ( histogram. valueAtPercentile ( 30.0 ) ) ,
156
156
accuracy: 1_000.0 * 0.001 , " 30%'ile is 1 msec +/- 0.1% " )
157
- XCTAssertEqual ( 1_000.0 , Double ( Self . histogram. valueAtPercentile ( 50.0 ) ) ,
157
+ XCTAssertEqual ( 1_000.0 , Double ( histogram. valueAtPercentile ( 50.0 ) ) ,
158
158
accuracy: 1_000.0 * 0.001 , " 50%'ile is 1 msec +/- 0.1% " )
159
159
160
- XCTAssertEqual ( 50_000_000.0 , Double ( Self . histogram. valueAtPercentile ( 75.0 ) ) ,
160
+ XCTAssertEqual ( 50_000_000.0 , Double ( histogram. valueAtPercentile ( 75.0 ) ) ,
161
161
accuracy: 50_000_000.0 * 0.001 , " 75%'ile is 50 sec +/- 0.1% " )
162
162
163
- XCTAssertEqual ( 80_000_000.0 , Double ( Self . histogram. valueAtPercentile ( 90.0 ) ) ,
163
+ XCTAssertEqual ( 80_000_000.0 , Double ( histogram. valueAtPercentile ( 90.0 ) ) ,
164
164
accuracy: 80_000_000.0 * 0.001 , " 90%'ile is 80 sec +/- 0.1% " )
165
- XCTAssertEqual ( 98_000_000.0 , Double ( Self . histogram. valueAtPercentile ( 99.0 ) ) ,
165
+ XCTAssertEqual ( 98_000_000.0 , Double ( histogram. valueAtPercentile ( 99.0 ) ) ,
166
166
accuracy: 98_000_000.0 * 0.001 , " 99%'ile is 98 sec +/- 0.1% " )
167
- XCTAssertEqual ( 100_000_000.0 , Double ( Self . histogram. valueAtPercentile ( 99.999 ) ) ,
167
+ XCTAssertEqual ( 100_000_000.0 , Double ( histogram. valueAtPercentile ( 99.999 ) ) ,
168
168
accuracy: 100_000_000.0 * 0.001 , " 99.999%'ile is 100 sec +/- 0.1% " )
169
- XCTAssertEqual ( 100_000_000.0 , Double ( Self . histogram. valueAtPercentile ( 100.0 ) ) ,
169
+ XCTAssertEqual ( 100_000_000.0 , Double ( histogram. valueAtPercentile ( 100.0 ) ) ,
170
170
accuracy: 100_000_000.0 * 0.001 , " 100%'ile is 100 sec +/- 0.1% " )
171
171
}
172
172
@@ -181,41 +181,41 @@ final class HistogramDataAccessTests: XCTestCase {
181
181
}
182
182
183
183
func testPercentileAtOrBelowValue( ) {
184
- XCTAssertEqual ( 99.99 , Self . rawHistogram. percentileAtOrBelowValue ( 5_000 ) ,
184
+ XCTAssertEqual ( 99.99 , rawHistogram. percentileAtOrBelowValue ( 5_000 ) ,
185
185
accuracy: 0.0001 , " Raw percentile at or below 5 msec is 99.99% +/- 0.0001 " )
186
- XCTAssertEqual ( 50.0 , Self . histogram. percentileAtOrBelowValue ( 5_000 ) ,
186
+ XCTAssertEqual ( 50.0 , histogram. percentileAtOrBelowValue ( 5_000 ) ,
187
187
accuracy: 0.0001 , " Percentile at or below 5 msec is 50% +/- 0.0001% " )
188
- XCTAssertEqual ( 100.0 , Self . histogram. percentileAtOrBelowValue ( 100_000_000 ) ,
188
+ XCTAssertEqual ( 100.0 , histogram. percentileAtOrBelowValue ( 100_000_000 ) ,
189
189
accuracy: 0.0001 , " Percentile at or below 100 sec is 100% +/- 0.0001% " )
190
190
}
191
191
192
192
func testCountWithinRange( ) {
193
- XCTAssertEqual ( 10_000 , Self . rawHistogram. count ( within: 1_000 ... 1_000 ) ,
193
+ XCTAssertEqual ( 10_000 , rawHistogram. count ( within: 1_000 ... 1_000 ) ,
194
194
" Count of raw values between 1 msec and 1 msec is 1 " )
195
- XCTAssertEqual ( 1 , Self . rawHistogram. count ( within: 5_000 ... 150_000_000 ) ,
195
+ XCTAssertEqual ( 1 , rawHistogram. count ( within: 5_000 ... 150_000_000 ) ,
196
196
" Count of raw values between 5 msec and 150 sec is 1 " )
197
- XCTAssertEqual ( 10_000 , Self . histogram. count ( within: 5_000 ... 150_000_000 ) ,
197
+ XCTAssertEqual ( 10_000 , histogram. count ( within: 5_000 ... 150_000_000 ) ,
198
198
" Count of values between 5 msec and 150 sec is 10,000 " )
199
199
}
200
200
201
201
func testCountForValue( ) {
202
- XCTAssertEqual ( 0 , Self . rawHistogram. count ( within: 10_000 ... 10_010 ) ,
202
+ XCTAssertEqual ( 0 , rawHistogram. count ( within: 10_000 ... 10_010 ) ,
203
203
" Count of raw values at 10 msec is 0 " )
204
- XCTAssertEqual ( 1 , Self . histogram. count ( within: 10_000 ... 10_010 ) ,
204
+ XCTAssertEqual ( 1 , histogram. count ( within: 10_000 ... 10_010 ) ,
205
205
" Count of values at 10 msec is 0 " )
206
- XCTAssertEqual ( 10_000 , Self . rawHistogram. countForValue ( 1_000 ) ,
206
+ XCTAssertEqual ( 10_000 , rawHistogram. countForValue ( 1_000 ) ,
207
207
" Count of raw values at 1 msec is 10,000 " )
208
- XCTAssertEqual ( 10_000 , Self . histogram. countForValue ( 1_000 ) ,
208
+ XCTAssertEqual ( 10_000 , histogram. countForValue ( 1_000 ) ,
209
209
" Count of values at 1 msec is 10,000 " )
210
210
}
211
211
212
212
func testPercentiles( ) {
213
- for iv in Self . histogram. percentiles ( ticksPerHalfDistance: 5 ) {
213
+ for iv in histogram. percentiles ( ticksPerHalfDistance: 5 ) {
214
214
XCTAssertEqual (
215
- iv. value, Self . histogram. highestEquivalentForValue ( Self . histogram. valueAtPercentile ( iv. percentile) ) ,
215
+ iv. value, histogram. highestEquivalentForValue ( histogram. valueAtPercentile ( iv. percentile) ) ,
216
216
" Iterator value: \( iv. value) , count: \( iv. count) , percentile: \( iv. percentile) \n " +
217
- " histogram valueAtPercentile( \( iv. percentile) ): \( Self . histogram. valueAtPercentile ( iv. percentile) ) , " +
218
- " highest equivalent value: \( Self . histogram. highestEquivalentForValue ( Self . histogram. valueAtPercentile ( iv. percentile) ) ) "
217
+ " histogram valueAtPercentile( \( iv. percentile) ): \( histogram. valueAtPercentile ( iv. percentile) ) , " +
218
+ " highest equivalent value: \( histogram. highestEquivalentForValue ( histogram. valueAtPercentile ( iv. percentile) ) ) "
219
219
)
220
220
}
221
221
}
@@ -255,7 +255,7 @@ final class HistogramDataAccessTests: XCTestCase {
255
255
256
256
// Iterate data using linear buckets of 100 msec each.
257
257
var index = 0
258
- for iv in Self . rawHistogram. linearBucketValues ( valueUnitsPerBucket: 100_000 /* 100 msec */ ) {
258
+ for iv in rawHistogram. linearBucketValues ( valueUnitsPerBucket: 100_000 /* 100 msec */ ) {
259
259
let countAddedInThisBucket = iv. countAddedInThisIterationStep
260
260
if index == 0 {
261
261
XCTAssertEqual ( 10_000 , countAddedInThisBucket, " Raw Linear 100 msec bucket # 0 added a count of 10000 " )
@@ -272,7 +272,7 @@ final class HistogramDataAccessTests: XCTestCase {
272
272
// Iterate data using linear buckets of 10 msec each.
273
273
index = 0
274
274
var totalAddedCounts : UInt64 = 0
275
- for iv in Self . histogram. linearBucketValues ( valueUnitsPerBucket: 10_000 /* 10 msec */ ) {
275
+ for iv in histogram. linearBucketValues ( valueUnitsPerBucket: 10_000 /* 10 msec */ ) {
276
276
let countAddedInThisBucket = iv. countAddedInThisIterationStep
277
277
if index == 0 {
278
278
XCTAssertEqual ( 10_000 , countAddedInThisBucket, " Linear 1 sec bucket # 0 [ \( iv. prevValue) .. \( iv. value) ] added a count of 10000 " )
@@ -292,7 +292,7 @@ final class HistogramDataAccessTests: XCTestCase {
292
292
// Iterate data using linear buckets of 1 msec each.
293
293
index = 0
294
294
totalAddedCounts = 0
295
- for iv in Self . histogram. linearBucketValues ( valueUnitsPerBucket: 1_000 /* 1 msec */ ) {
295
+ for iv in histogram. linearBucketValues ( valueUnitsPerBucket: 1_000 /* 1 msec */ ) {
296
296
let countAddedInThisBucket = iv. countAddedInThisIterationStep
297
297
if index == 1 {
298
298
XCTAssertEqual ( 10_000 , countAddedInThisBucket, " Linear 1 sec bucket # 0 [ \( iv. prevValue) .. \( iv. value) ] added a count of 10000 " )
@@ -319,7 +319,7 @@ final class HistogramDataAccessTests: XCTestCase {
319
319
func testLogarithmicBucketValues( ) {
320
320
// Iterate raw data using logarithmic buckets starting at 10 msec.
321
321
var index = 0
322
- for iv in Self . rawHistogram. logarithmicBucketValues ( valueUnitsInFirstBucket: 10_000 /* 10 msec */, logBase: 2 ) {
322
+ for iv in rawHistogram. logarithmicBucketValues ( valueUnitsInFirstBucket: 10_000 /* 10 msec */, logBase: 2 ) {
323
323
let countAddedInThisBucket = iv. countAddedInThisIterationStep
324
324
if index == 0 {
325
325
XCTAssertEqual ( 10_000 , countAddedInThisBucket, " Raw Logarithmic 10 msec bucket # 0 added a count of 10000 " )
@@ -334,7 +334,7 @@ final class HistogramDataAccessTests: XCTestCase {
334
334
335
335
index = 0
336
336
var totalAddedCounts : UInt64 = 0
337
- for iv in Self . histogram. logarithmicBucketValues ( valueUnitsInFirstBucket: 10_000 /* 10 msec */, logBase: 2 ) {
337
+ for iv in histogram. logarithmicBucketValues ( valueUnitsInFirstBucket: 10_000 /* 10 msec */, logBase: 2 ) {
338
338
let countAddedInThisBucket = iv. countAddedInThisIterationStep
339
339
if index == 0 {
340
340
XCTAssertEqual ( 10_000 , countAddedInThisBucket,
@@ -350,7 +350,7 @@ final class HistogramDataAccessTests: XCTestCase {
350
350
func testRecordedValues( ) {
351
351
// Iterate raw data by stepping through every value that has a count recorded:
352
352
var index = 0
353
- for iv in Self . rawHistogram. recordedValues ( ) {
353
+ for iv in rawHistogram. recordedValues ( ) {
354
354
let countAddedInThisBucket = iv. countAddedInThisIterationStep
355
355
if index == 0 {
356
356
XCTAssertEqual ( 10_000 , countAddedInThisBucket, " Raw recorded value bucket # 0 added a count of 10000 " )
@@ -363,7 +363,7 @@ final class HistogramDataAccessTests: XCTestCase {
363
363
364
364
index = 0
365
365
var totalAddedCounts : UInt64 = 0
366
- for iv in Self . histogram. recordedValues ( ) {
366
+ for iv in histogram. recordedValues ( ) {
367
367
let countAddedInThisBucket = iv. countAddedInThisIterationStep
368
368
if index == 0 {
369
369
XCTAssertEqual ( 10_000 , countAddedInThisBucket,
@@ -385,11 +385,11 @@ final class HistogramDataAccessTests: XCTestCase {
385
385
var totalValueToThisPoint : UInt64 = 0
386
386
387
387
// Iterate raw data by stepping through every value that has a count recorded:
388
- for v in Self . rawHistogram. allValues ( ) {
388
+ for v in rawHistogram. allValues ( ) {
389
389
let countAddedInThisBucket = v. countAddedInThisIterationStep
390
390
if index == 1_000 {
391
391
XCTAssertEqual ( 10_000 , countAddedInThisBucket, " Raw allValues bucket # 0 added a count of 10000 " )
392
- } else if Self . histogram. valuesAreEquivalent ( v. value, 100_000_000 ) {
392
+ } else if histogram. valuesAreEquivalent ( v. value, 100_000_000 ) {
393
393
XCTAssertEqual ( 1 , countAddedInThisBucket, " Raw allValues value bucket # \( index) added a count of 1 " )
394
394
} else {
395
395
XCTAssertEqual ( 0 , countAddedInThisBucket, " Raw allValues value bucket # \( index) added a count of 0 " )
@@ -400,12 +400,12 @@ final class HistogramDataAccessTests: XCTestCase {
400
400
XCTAssertEqual ( totalValueToThisPoint, v. totalValueToThisValue, " total Value should match " )
401
401
index += 1
402
402
}
403
- XCTAssertEqual ( Self . histogram. counts. count, index, " index should be equal to counts array length " )
403
+ XCTAssertEqual ( histogram. counts. count, index, " index should be equal to counts array length " )
404
404
405
405
index = 0
406
406
var totalAddedCounts : UInt64 = 0
407
407
408
- for v in Self . histogram. allValues ( ) {
408
+ for v in histogram. allValues ( ) {
409
409
let countAddedInThisBucket = v. countAddedInThisIterationStep
410
410
if index == 1_000 {
411
411
XCTAssertEqual ( 10_000 , countAddedInThisBucket,
@@ -415,10 +415,10 @@ final class HistogramDataAccessTests: XCTestCase {
415
415
" The count in AllValues bucket # \( index) " +
416
416
" is exactly the amount added since the last iteration " )
417
417
totalAddedCounts += countAddedInThisBucket
418
- XCTAssertTrue ( Self . histogram. valuesAreEquivalent ( Self . histogram. valueFromIndex ( index) , v. value) , " valueFromIndex() should be equal to value " )
418
+ XCTAssertTrue ( histogram. valuesAreEquivalent ( histogram. valueFromIndex ( index) , v. value) , " valueFromIndex() should be equal to value " )
419
419
index += 1
420
420
}
421
- XCTAssertEqual ( Self . histogram. counts. count, index, " index should be equal to counts array length " )
421
+ XCTAssertEqual ( self . histogram. counts. count, index, " index should be equal to counts array length " )
422
422
XCTAssertEqual ( 20_000 , totalAddedCounts, " Total added counts should be 20000 " )
423
423
}
424
424
0 commit comments