@@ -0,0 +1,29 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExpectedGuessDeterministic(t *testing.T) {
|
||||
a := ExpectedGuess("task_x", "seed", "client", 7, 28)
|
||||
b := ExpectedGuess("task_x", "seed", "client", 7, 28)
|
||||
if a != b {
|
||||
t.Fatalf("not deterministic: %s != %s", a, b)
|
||||
}
|
||||
n, ok := new(big.Int).SetString(a, 10)
|
||||
if !ok || n.Sign() < 0 || n.BitLen() > 28 {
|
||||
t.Fatalf("guess outside range: %s", a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore(t *testing.T) {
|
||||
if Score(big.NewInt(0), 32) != 100 {
|
||||
t.Fatal("exact hit must score 100")
|
||||
}
|
||||
near := Score(big.NewInt(1), 32)
|
||||
far := Score(new(big.Int).Lsh(big.NewInt(1), 30), 32)
|
||||
if near <= far {
|
||||
t.Fatalf("near score %f should exceed far %f", near, far)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user