|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
package judgment
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"math"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -20,7 +20,6 @@ func TestReadmeDemo(t *testing.T) {
|
|
|
|
|
deliberator := &MajorityJudgment{}
|
|
|
|
|
result, err := deliberator.Deliberate(poll)
|
|
|
|
|
assert.NoError(t, err, "Deliberation should succeed")
|
|
|
|
|
fmt.Printf("Result: %v\n", result)
|
|
|
|
|
assert.Len(t, result.Proposals, len(poll.Proposals), "There should be as many results as there are tallies.")
|
|
|
|
|
assert.Equal(t, 4, result.Proposals[0].Rank, "Rank of proposal A")
|
|
|
|
|
assert.Equal(t, 1, result.Proposals[1].Rank, "Rank of proposal B")
|
|
|
|
@ -40,6 +39,20 @@ func TestNoProposals(t *testing.T) {
|
|
|
|
|
assert.Len(t, result.Proposals, len(poll.Proposals), "There should be as many results as there are tallies.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestIncoherentTally(t *testing.T) {
|
|
|
|
|
poll := &PollTally{
|
|
|
|
|
AmountOfJudges: 2, // not 8 as it should
|
|
|
|
|
Proposals: []*ProposalTally{
|
|
|
|
|
{Tally: []uint64{4, 4}},
|
|
|
|
|
{Tally: []uint64{2, 6}},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
deliberator := &MajorityJudgment{}
|
|
|
|
|
result, err := deliberator.Deliberate(poll)
|
|
|
|
|
assert.Error(t, err, "Deliberation should fail")
|
|
|
|
|
assert.Nil(t, result, "Deliberation result should be nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMishapedTally(t *testing.T) {
|
|
|
|
|
poll := &PollTally{
|
|
|
|
|
AmountOfJudges: 10,
|
|
|
|
@ -67,3 +80,20 @@ func TestUnbalancedTally(t *testing.T) {
|
|
|
|
|
assert.Error(t, err, "Deliberation should fail")
|
|
|
|
|
assert.Nil(t, result, "Deliberation result should be nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExcessivelyBigTally(t *testing.T) {
|
|
|
|
|
// math.MaxInt64 + 1 is a valid uint64 value, but we need to cast to int internally so it overflows
|
|
|
|
|
poll := &PollTally{
|
|
|
|
|
AmountOfJudges: math.MaxInt64 + 1,
|
|
|
|
|
Proposals: []*ProposalTally{
|
|
|
|
|
{Tally: []uint64{math.MaxInt64, 1}},
|
|
|
|
|
{Tally: []uint64{math.MaxInt64, 1}},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
deliberator := &MajorityJudgment{}
|
|
|
|
|
result, err := deliberator.Deliberate(poll)
|
|
|
|
|
if assert.Error(t, err, "Deliberation should fail") {
|
|
|
|
|
//println(err.Error())
|
|
|
|
|
}
|
|
|
|
|
assert.Nil(t, result, "Deliberation result should be nil")
|
|
|
|
|
}
|
|
|
|
|