package terminology import "testing" // TestThePreCallContestReadsDisagreementAndNotVolume pins the predicate the routing of the next pack will // stand on. Each case is one arm, and the two that matter for money are the last two: a candidate nobody // rendered is not agreement, and a dominant leader is not a contest. func TestThePreCallContestReadsDisagreementAndNotVolume(t *testing.T) { v := func(dst string, chunks int) Variant { return Variant{Dst: dst, Chunks: chunks, Forms: 1} } for _, tc := range []struct { name string cand Candidate opts ContestOpts want Contest }{ { name: "one convention is never a contest, however many chunks proposed it", cand: Candidate{Variants: []Variant{v("Фан Юань", 12)}}, opts: ContestOpts{MinConventions: 2}, want: Contest{Conventions: 1, LeaderShare: 1}, }, { // ⛔ THE DIFFERENCE BETWEEN THE TWO NUMBERS, and the reason the predicate reads the second one: // «Море истинной ци» and «море истинной ци» are ONE decision written two ways. Spread counts 2, // Conventions counts 1, and a predicate on Spread would send a normalization nit to a second // paid model. name: "one convention written two ways is a spread of two and a contest of none", cand: Candidate{Variants: []Variant{{Dst: "Море истинной ци", Chunks: 3, Forms: 2}}}, opts: ContestOpts{MinConventions: 2}, want: Contest{Conventions: 1, LeaderShare: 1}, }, { name: "two conventions at a tie is the contest the word means", cand: Candidate{Variants: []Variant{v("селение Сюн", 1), v("крепость рода Сюн", 1)}}, opts: ContestOpts{MinConventions: 2}, want: Contest{Contested: true, Conventions: 2, LeaderShare: 0.5}, }, { name: "a dominant leader settles it when the caller asks for dominance", cand: Candidate{Variants: []Variant{v("Фан Юань", 9), v("Фан Юаньский", 1)}}, opts: ContestOpts{MinConventions: 2, MaxLeaderShare: 0.75}, want: Contest{Conventions: 2, LeaderShare: 0.9}, }, { name: "and the SAME candidate is contested when the caller does not ask for dominance — the arm is the caller's, not the engine's", cand: Candidate{Variants: []Variant{v("Фан Юань", 9), v("Фан Юаньский", 1)}}, opts: ContestOpts{MinConventions: 2}, want: Contest{Contested: true, Conventions: 2, LeaderShare: 0.9}, }, { name: "no draft rendered it at all: not a contest, and NOT agreement", cand: Candidate{Variants: nil}, opts: ContestOpts{MinConventions: 2}, want: Contest{Unsupported: true}, }, { // A channel can carry a rendering without a chunk count behind it. Reporting the leader's share // as 1 would call that dominance and settle a contest nobody won. name: "renderings with no chunk count behind them are not a dominant leader", cand: Candidate{Variants: []Variant{v("селение Сюн", 0), v("крепость рода Сюн", 0)}}, opts: ContestOpts{MinConventions: 2, MaxLeaderShare: 0.75}, want: Contest{Contested: true, Conventions: 2, LeaderShare: 0}, }, } { t.Run(tc.name, func(t *testing.T) { got := tc.cand.Contest(tc.opts) if got != tc.want { t.Errorf("Contest = %+v, want %+v", got, tc.want) } }) } }