File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -157,3 +157,26 @@ func TestChallenge(t *testing.T) {
157
157
t .Errorf ("didn't round trip: %v != %v" , back , pub )
158
158
}
159
159
}
160
+
161
+ // Test that NodePublic.Shard is uniformly distributed.
162
+ func TestShard (t * testing.T ) {
163
+ const N = 1_000
164
+ var shardCount [256 ]int
165
+ for i := 0 ; i < N ; i ++ {
166
+ shardCount [NewNode ().Public ().Shard ()]++
167
+ }
168
+ e := float64 (N ) / 256 // expected
169
+ var x2 float64 // chi-squared
170
+ for _ , c := range shardCount {
171
+ r := float64 (c ) - e // residual
172
+ x2 += r * r / e
173
+ }
174
+ t .Logf ("x^2 = %v" , x2 )
175
+ if x2 > 512 { // really want x^2 =~ (256 - 1), but leave slop
176
+ t .Errorf ("too much variation in shard distribution" )
177
+ for i , c := range shardCount {
178
+ rj := float64 (c ) - e
179
+ t .Logf ("shard[%v] = %v (off by %v)" , i , c , rj )
180
+ }
181
+ }
182
+ }
You can’t perform that action at this time.
0 commit comments