Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DisSys Inc.
bsc-shamir
Commits
21377379
Commit
21377379
authored
Jun 04, 2020
by
Anders Jensen Løvig
Browse files
Addtitional agreement test
parent
e815b3a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
election/agreement_test.go
View file @
21377379
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
)
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment