|
|
|
@ -107,3 +107,79 @@ func TestProposalTally_FillWithStaticDefaultFailureAmountToLow(t *testing.T) {
|
|
|
|
|
assert.Equal(t, expectedTally.Tally[i], proposalTally.Tally[i], fmt.Sprintf("Grade #%d", i))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestProposalTally_FillWithStaticDefaultSuccesses(t *testing.T) {
|
|
|
|
|
type test struct {
|
|
|
|
|
name string
|
|
|
|
|
amountOfJudges uint64
|
|
|
|
|
defaultGrade uint8
|
|
|
|
|
input ProposalTally
|
|
|
|
|
expected ProposalTally
|
|
|
|
|
}
|
|
|
|
|
tests := []test{
|
|
|
|
|
{
|
|
|
|
|
name: "Basic usage",
|
|
|
|
|
amountOfJudges: 30,
|
|
|
|
|
defaultGrade: 0,
|
|
|
|
|
input: ProposalTally{Tally: []uint64{1, 2, 3, 4, 5, 6, 7}},
|
|
|
|
|
expected: ProposalTally{Tally: []uint64{3, 2, 3, 4, 5, 6, 7}},
|
|
|
|
|
},
|
|
|
|
|
// …
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
proposalTally := tt.input
|
|
|
|
|
expectedTally := tt.expected
|
|
|
|
|
err := proposalTally.FillWithStaticDefault(tt.amountOfJudges, tt.defaultGrade)
|
|
|
|
|
assert.NoError(t, err, "Filling should succeed")
|
|
|
|
|
for i := 0; i < len(proposalTally.Tally); i++ {
|
|
|
|
|
assert.Equal(t, expectedTally.Tally[i], proposalTally.Tally[i], fmt.Sprintf("Grade #%d", i))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestProposalTally_FillWithMedianDefaultSuccesses(t *testing.T) {
|
|
|
|
|
type test struct {
|
|
|
|
|
name string
|
|
|
|
|
amountOfJudges uint64
|
|
|
|
|
input ProposalTally
|
|
|
|
|
expected ProposalTally
|
|
|
|
|
}
|
|
|
|
|
tests := []test{
|
|
|
|
|
{
|
|
|
|
|
name: "Basic usage",
|
|
|
|
|
amountOfJudges: 30,
|
|
|
|
|
input: ProposalTally{Tally: []uint64{1, 2, 3, 4, 5, 6, 7}},
|
|
|
|
|
expected: ProposalTally{Tally: []uint64{1, 2, 3, 4, 7, 6, 7}},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Lots of zeroes",
|
|
|
|
|
amountOfJudges: 5,
|
|
|
|
|
input: ProposalTally{Tally: []uint64{0, 0, 0, 1, 0, 0, 1}},
|
|
|
|
|
expected: ProposalTally{Tally: []uint64{0, 0, 0, 4, 0, 0, 1}},
|
|
|
|
|
},
|
|
|
|
|
// …
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
proposalTally := tt.input
|
|
|
|
|
expectedTally := tt.expected
|
|
|
|
|
err := proposalTally.FillWithMedianDefault(tt.amountOfJudges)
|
|
|
|
|
assert.NoError(t, err, "Filling should succeed")
|
|
|
|
|
for i := 0; i < len(proposalTally.Tally); i++ {
|
|
|
|
|
assert.Equal(t, expectedTally.Tally[i], proposalTally.Tally[i], fmt.Sprintf("Grade #%d", i))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestProposalTally_FillWithMedianDefaultFailureAmountToLow(t *testing.T) {
|
|
|
|
|
proposalTally := ProposalTally{Tally: []uint64{0, 1, 0, 1, 2, 3, 4}}
|
|
|
|
|
expectedTally := ProposalTally{Tally: []uint64{0, 1, 0, 1, 2, 3, 4}}
|
|
|
|
|
err := proposalTally.FillWithMedianDefault(5)
|
|
|
|
|
assert.Error(t, err, "Filling should fail")
|
|
|
|
|
for i := 0; i < 7; i++ {
|
|
|
|
|
assert.Equal(t, expectedTally.Tally[i], proposalTally.Tally[i], fmt.Sprintf("Grade #%d", i))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|