Small improvements to the threshold key generator tests

First of all, we should check both `p,p1` and `q,q1` in the `TestInitPsAndQs`. Moreover, it's better to operate on primes in `TestArePsAndQsGood` and in `TestInitShortcuts` because non-prime numbers are not allowed there in a real world and tests were a bit misleading because of it.
This commit is contained in:
Piotr Dyraga committed 2018-05-30 14:47:56 +02:00
1 parent 92c3842e5f
commit e10b02e420
1 file changed
+10 -12
+10 -12
View File
@@ -18,10 +18,8 @@ func TestGenerateSafePrimesOfThresholdKeyGenerator(t *testing.T) {
p, q, err := tkh.generateSafePrimes()
if err != nil {
t.Error(err)
return
}
AreSafePrimes(p, q, 10, t)
}
func TestInitPandP1(t *testing.T) {
@@ -31,7 +29,6 @@ func TestInitPandP1(t *testing.T) {
tkh.initPandP1()
AreSafePrimes(tkh.p, tkh.p1, 10, t)
}
func TestInitQandQ1(t *testing.T) {
@@ -49,23 +46,24 @@ func TestInitPsAndQs(t *testing.T) {
tkh.Random = rand.Reader
tkh.initPsAndQs()
AreSafePrimes(tkh.q, tkh.q1, 10, t)
AreSafePrimes(tkh.p, tkh.p1, 10, t)
AreSafePrimes(tkh.q, tkh.q1, 10, t)
}
func TestArePsAndQsGood(t *testing.T) {
tkh := new(ThresholdKeyGenerator)
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(6), b(5), b(4), b(3)
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(887), b(443), b(839), b(419)
if !tkh.arePsAndQsGood() {
t.Fail()
}
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(6), b(5), b(6), b(3)
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(887), b(443), b(887), b(443)
if tkh.arePsAndQsGood() {
t.Fail()
}
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(6), b(5), b(5), b(3)
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(887), b(443), b(443), b(221)
if tkh.arePsAndQsGood() {
t.Fail()
}
@@ -73,19 +71,19 @@ func TestArePsAndQsGood(t *testing.T) {
func TestInitShortcuts(t *testing.T) {
tkh := new(ThresholdKeyGenerator)
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(11), b(7), b(5), b(3)
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(839), b(419), b(887), b(443)
tkh.initShortcuts()
if n(tkh.n) != 11*5 {
if !reflect.DeepEqual(tkh.n, b(744193)) {
t.Error("wrong n", tkh.n)
}
if n(tkh.m) != 7*3 {
if !reflect.DeepEqual(tkh.m, b(185617)) {
t.Error("wrong m", tkh.m)
}
if n(tkh.nm) != 11*5*7*3 {
if !reflect.DeepEqual(tkh.nm, new(big.Int).Mul(b(744193), b(185617))) {
t.Error("wrong nm", tkh.nm)
}
if n(tkh.nSquare) != 11*5*11*5 {
if !reflect.DeepEqual(tkh.nSquare, new(big.Int).Mul(b(744193), b(744193))) {
t.Error("wrong nSquare", tkh.nSquare)
}
}