From 96a30a0a0393648f25fd0ebf672d2a55991c7553 Mon Sep 17 00:00:00 2001 From: domi41 Date: Sun, 4 Jul 2021 06:43:56 +0200 Subject: [PATCH] feat: output the sorted proposals as well, for convenience --- majorityjudgment_test.go | 13 +++++++++++++ result.go | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/majorityjudgment_test.go b/majorityjudgment_test.go index 0719a87..9c28e19 100644 --- a/majorityjudgment_test.go +++ b/majorityjudgment_test.go @@ -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) { diff --git a/result.go b/result.go index 7236d2b..e8d7929 100644 --- a/result.go +++ b/result.go @@ -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