feat: output the sorted proposals as well, for convenience

main
Dominique Merle 3 years ago
parent b994893b34
commit 96a30a0a03

@ -26,6 +26,19 @@ func TestReadmeDemo(t *testing.T) {
assert.Equal(t, 2, result.Proposals[2].Rank, "Rank of proposal C")
assert.Equal(t, 3, result.Proposals[3].Rank, "Rank of proposal D")
assert.Equal(t, 4, result.Proposals[4].Rank, "Rank of proposal E")
assert.Equal(t, 1, result.ProposalsSorted[0].Rank, "Rank of sorted proposal A")
assert.Equal(t, 2, result.ProposalsSorted[1].Rank, "Rank of sorted proposal 1")
assert.Equal(t, 3, result.ProposalsSorted[2].Rank, "Rank of sorted proposal 2")
assert.Equal(t, 4, result.ProposalsSorted[3].Rank, "Rank of sorted proposal 3")
assert.Equal(t, 4, result.ProposalsSorted[4].Rank, "Rank of sorted proposal 4")
assert.Equal(t, 1, result.ProposalsSorted[0].Index, "Index of sorted proposal A")
assert.Equal(t, 2, result.ProposalsSorted[1].Index, "Index of sorted proposal 1")
assert.Equal(t, 3, result.ProposalsSorted[2].Index, "Index of sorted proposal 2")
assert.Equal(t, 0, result.ProposalsSorted[3].Index, "Index of sorted proposal 3")
assert.Equal(t, 4, result.ProposalsSorted[4].Index, "Index of sorted proposal 4")
}
func TestNoProposals(t *testing.T) {

@ -1,11 +1,12 @@
package judgment
type PollResult struct {
Proposals ProposalsResults // Matches the order of the input proposals' tallies
Proposals ProposalsResults // matches the order of the input proposals' tallies
ProposalsSorted ProposalsResults // same Results, but sorted by Rank this time
}
type ProposalResult struct {
Index int // index of the proposal in the input proposals' tallies
Index int // index of the proposal in the input proposals' tallies. Useful with ProposalSorted
Rank int // Rank starts at 1 (best) and goes upwards. Equal Proposals share the same rank.
Score string // higher lexicographically → better rank
Analysis *ProposalAnalysis

Loading…
Cancel
Save