@@ -35,8 +35,8 @@ import org.mockito.kotlin.mock
35
35
import org.mockito.kotlin.whenever
36
36
import org.robolectric.ParameterizedRobolectricTestRunner
37
37
38
- private var enables = 1
39
- private var disables = 1
38
+ private var enables = 0
39
+ private var disables = 0
40
40
41
41
@RunWith(ParameterizedRobolectricTestRunner ::class )
42
42
class ContributesRemoteFeatureCodeGeneratorBucketAssignmentTest (private val testCase : TestCase ) {
@@ -62,12 +62,19 @@ class ContributesRemoteFeatureCodeGeneratorBucketAssignmentTest(private val test
62
62
63
63
@Test
64
64
fun `test probability` () {
65
- fun isWithinRange (): Boolean {
66
- if (testCase.run < 9000 ) return true // small sample sizes will have high variance
65
+ fun assertWithinRange () {
66
+ if (testCase.run < 9000 ) return // small sample sizes will have high variance
67
67
val allowableDeviation = (enables + disables) / 2 * 6.0f / 100 // allowable deviation of 6%
68
68
69
69
// Check if the absolute difference between the two numbers is within the allowable deviation
70
- return abs(enables - disables) <= allowableDeviation
70
+ val difference = abs(enables - disables)
71
+ assertTrue(
72
+ " Given sample size of ${enables + disables} , the allowable deviation (6%) is: $allowableDeviation , " +
73
+ " but actual difference was $difference " +
74
+ " (enables=$enables " +
75
+ " , disables=$disables )" ,
76
+ difference <= allowableDeviation,
77
+ )
71
78
}
72
79
73
80
val feature = generatedFeatureNewInstance()
@@ -103,7 +110,7 @@ class ContributesRemoteFeatureCodeGeneratorBucketAssignmentTest(private val test
103
110
} else {
104
111
disables++
105
112
}
106
- assertTrue(isWithinRange() )
113
+ assertWithinRange( )
107
114
}
108
115
109
116
data class TestCase (val rollout : Int , val run : Int )
@@ -112,7 +119,7 @@ class ContributesRemoteFeatureCodeGeneratorBucketAssignmentTest(private val test
112
119
@ParameterizedRobolectricTestRunner.Parameters ()
113
120
fun parameters (): List <TestCase > {
114
121
val l = mutableListOf<TestCase >()
115
- repeat(10000 ) {
122
+ repeat(10_000 ) {
116
123
l.add(TestCase (run = it, rollout = 50 ))
117
124
}
118
125
0 commit comments