ballot_test.go 1.07 KB
Newer Older
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
1
2
3
package election

import (
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
4
	"bsc-shamir/crypto/common"
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
5
6
7
8
	"math/big"
	"testing"
)

9
func TestBallotZero(t *testing.T) {
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
10
	params := common.DefaultParams()
11
12
13
14
15
16
17
	ballots := CreateBallots(5, []*big.Int{
		big.NewInt(1),
		big.NewInt(2),
		big.NewInt(3),
		big.NewInt(4),
		big.NewInt(5),
	}, big.NewInt(0))
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
18
	for i, ballot := range ballots {
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
19
		if !ballot.Verify(params) {
20
			t.Errorf("Failed to verify ballot %s\n", i)
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
21
22
		}
	}
23
}
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
24

25
26
func TestBallotOne(t *testing.T) {
	params := common.DefaultParams()
Anders Jensen Løvig's avatar
Merge    
Anders Jensen Løvig committed
27
	ballots := CreateBallots(5, []*big.Int{
28
29
30
31
32
33
		big.NewInt(1),
		big.NewInt(2),
		big.NewInt(3),
		big.NewInt(4),
		big.NewInt(5),
	}, big.NewInt(1))
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
34
	for i, ballot := range ballots {
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
35
		if !ballot.Verify(params) {
36
			t.Errorf("Failed to verify ballot %s\n", i)
Anders Jensen Løvig's avatar
Anders Jensen Løvig committed
37
38
39
		}
	}
}
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

func TestBallotHash(t *testing.T) {
	ballots := CreateBallots(5, []*big.Int{
		big.NewInt(1),
		big.NewInt(2),
		big.NewInt(3),
		big.NewInt(4),
		big.NewInt(5),
	}, big.NewInt(1))

	h := ballots["1"].Hash()
	t.Log("Hash", h)

	for i, ballot := range ballots {
		if ballot.Hash() != h {
			t.Errorf("Ballot %s have hash %s", i, h)
		}
	}
}