Commit 21377379 authored by Anders Jensen Løvig's avatar Anders Jensen Løvig
Browse files

Addtitional agreement test

parent e815b3a5
package election
import (
"math/big"
"strconv"
"testing"
"github.com/google/uuid"
......@@ -79,3 +81,81 @@ func TestMaxSubset(t *testing.T) {
t.Error()
}
}
func TestBallotIntersect(t *testing.T) {
lists := []BallotList{
map[string]uuid.UUID{},
map[string]uuid.UUID{},
map[string]uuid.UUID{},
}
xs := createXS(3)
ballots := createAllBallots([]*big.Int{
big.NewInt(0), big.NewInt(1), big.NewInt(0), big.NewInt(0),
big.NewInt(1), big.NewInt(0), big.NewInt(1), big.NewInt(0),
big.NewInt(0), big.NewInt(1),
}, 3, 2, xs)
for _, bmap := range ballots {
for id, b := range bmap {
i, _ := strconv.Atoi(string(id))
lists[i-1][b.Hash()] = b.ID
}
}
inter := Intersection(lists)
if len(inter) != 10 {
t.Error()
}
for i := 0; i < len(lists); i++ {
count := 0
for h := range lists[i] {
if _, ok := inter[h]; ok {
count++
}
}
if count != 10 {
t.Error(i)
}
}
}
func TestBallotMaxSubset(t *testing.T) {
lists := []BallotList{
map[string]uuid.UUID{},
map[string]uuid.UUID{},
map[string]uuid.UUID{},
}
xs := createXS(3)
ballots := createAllBallots([]*big.Int{
big.NewInt(0), big.NewInt(1), big.NewInt(0), big.NewInt(0),
big.NewInt(1), big.NewInt(0), big.NewInt(1), big.NewInt(0),
big.NewInt(0), big.NewInt(1),
}, 3, 2, xs)
for _, bmap := range ballots {
for id, b := range bmap {
i, _ := strconv.Atoi(string(id))
lists[i-1][b.Hash()] = b.ID
}
}
inter := MaxSubset(2, lists)
if len(inter) != 10 {
t.Error()
}
for i := 0; i < len(lists); i++ {
count := 0
for h := range lists[i] {
if _, ok := inter[h]; ok {
count++
}
}
if count != 10 {
t.Error(i)
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment