|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package judgment
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
@ -33,7 +34,7 @@ func TestProposalTally_RegradeJudgmentsIntoSelf(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestProposalTally_RegradeJudgments_Failure1(t *testing.T) {
|
|
|
|
|
proposalTally := ProposalTally{Tally: []uint64{1, 2, 3, 4, 5, 6, 7}}
|
|
|
|
|
err := proposalTally.RegradeJudgments(0, 60)
|
|
|
|
|
err := proposalTally.RegradeJudgments(0, uint8(len(proposalTally.Tally)))
|
|
|
|
|
assert.Error(t, err, "Regrading should fail")
|
|
|
|
|
assert.Equal(t, uint64(1), proposalTally.Tally[0])
|
|
|
|
|
assert.Equal(t, uint64(2), proposalTally.Tally[1])
|
|
|
|
@ -56,3 +57,53 @@ func TestProposalTally_RegradeJudgments_Failure2(t *testing.T) {
|
|
|
|
|
assert.Equal(t, uint64(6), proposalTally.Tally[5])
|
|
|
|
|
assert.Equal(t, uint64(7), proposalTally.Tally[6])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestProposalTally_FillWithStaticDefault(t *testing.T) {
|
|
|
|
|
proposalTally := ProposalTally{Tally: []uint64{1, 2, 3, 4, 5, 6, 7}}
|
|
|
|
|
expectedTally := ProposalTally{Tally: []uint64{3, 2, 3, 4, 5, 6, 7}}
|
|
|
|
|
err := proposalTally.FillWithStaticDefault(30, 0)
|
|
|
|
|
assert.NoError(t, err, "Filling should succeed")
|
|
|
|
|
for i := 0; i < 7; i++ {
|
|
|
|
|
assert.Equal(t, expectedTally.Tally[i], proposalTally.Tally[i], fmt.Sprintf("Grade #%d", i))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestProposalTally_FillWithStaticDefaultNotZero(t *testing.T) {
|
|
|
|
|
proposalTally := ProposalTally{Tally: []uint64{0, 1, 0, 1, 0, 0, 1}}
|
|
|
|
|
expectedTally := ProposalTally{Tally: []uint64{0, 1, 1, 1, 0, 0, 1}}
|
|
|
|
|
err := proposalTally.FillWithStaticDefault(4, 2)
|
|
|
|
|
assert.NoError(t, err, "Filling should succeed")
|
|
|
|
|
for i := 0; i < 7; i++ {
|
|
|
|
|
assert.Equal(t, expectedTally.Tally[i], proposalTally.Tally[i], fmt.Sprintf("Grade #%d", i))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestProposalTally_FillWithStaticDefaultNoop(t *testing.T) {
|
|
|
|
|
proposalTally := ProposalTally{Tally: []uint64{0, 1, 2, 1, 0, 0, 1}}
|
|
|
|
|
expectedTally := ProposalTally{Tally: []uint64{0, 1, 2, 1, 0, 0, 1}}
|
|
|
|
|
err := proposalTally.FillWithStaticDefault(5, 5)
|
|
|
|
|
assert.NoError(t, err, "Filling should succeed")
|
|
|
|
|
for i := 0; i < 7; i++ {
|
|
|
|
|
assert.Equal(t, expectedTally.Tally[i], proposalTally.Tally[i], fmt.Sprintf("Grade #%d", i))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestProposalTally_FillWithStaticDefaultFailureGradeTooHigh(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.FillWithStaticDefault(12, 200)
|
|
|
|
|
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))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestProposalTally_FillWithStaticDefaultFailureAmountToLow(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.FillWithStaticDefault(5, 0)
|
|
|
|
|
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))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|