-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSchulzeMethodTests.cs
More file actions
85 lines (66 loc) · 2.25 KB
/
SchulzeMethodTests.cs
File metadata and controls
85 lines (66 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.Linq;
using AlgorithmsAndDataStructures.Algorithms.Graph.Voting;
using Xunit;
namespace AlgorithmsAndDataStructures.Tests.Algorithm.Graph.Voting;
public class SchulzeMethodTests
{
[Fact]
public void ComplexVote()
{
var sut = new SchulzeMethod();
var ballots = new int[20][];
for (var i = 0; i < 10; i++)
{
ballots[i] = new int[3];
ballots[i][0] = 0;
ballots[i][1] = 1;
ballots[i][2] = 2;
}
for (var i = 10; i < 15; i++)
{
ballots[i] = new int[3];
ballots[i][0] = 1;
ballots[i][1] = 2;
ballots[i][2] = 0;
}
for (var i = 15; i < 20; i++)
{
ballots[i] = new int[3];
ballots[i][0] = 2;
ballots[i][1] = 0;
ballots[i][2] = 1;
}
var ballotWinners = sut.GetWinners(ballots);
Assert.Equal(0, ballotWinners.First().Candidate);
Assert.Equal(2, ballotWinners.First().Score);
Assert.Equal(1, ballotWinners.Skip(1).First().Candidate);
Assert.Equal(1, ballotWinners.Skip(1).First().Score);
Assert.Equal(2, ballotWinners.Skip(2).First().Candidate);
Assert.Equal(0, ballotWinners.Skip(2).First().Score);
}
[Fact]
public void BaseVote()
{
var sut = new SchulzeMethod();
var ballots = new int[3][];
ballots[0] = new int[3];
ballots[0][0] = 0;
ballots[0][1] = 1;
ballots[0][2] = 2;
ballots[1] = new int[3];
ballots[1][0] = 2;
ballots[1][1] = 1;
ballots[1][2] = 0;
ballots[2] = new int[3];
ballots[2][0] = 1;
ballots[2][1] = 2;
ballots[2][2] = 0;
var ballotWinners = sut.GetWinners(ballots);
Assert.Equal(1, ballotWinners.First().Candidate);
Assert.Equal(2, ballotWinners.First().Score);
Assert.Equal(2, ballotWinners.Skip(1).First().Candidate);
Assert.Equal(1, ballotWinners.Skip(1).First().Score);
Assert.Equal(0, ballotWinners.Skip(2).First().Candidate);
Assert.Equal(0, ballotWinners.Skip(2).First().Score);
}
}