예제 #1
0
        public void CountTest()
        {
            var a = new StvBallot();

            Assert.Throws <ArgumentException>(() => a.Add(-1));
            Assert.Throws <ArgumentException>(() => a.Add(0));
            Assert.Throws <ArgumentException>(() => a.Add(int.MinValue));
            Assert.Throws <ArgumentException>(() => a.Add(int.MaxValue));
            a.Add((int)(int.MaxValue * 2d / 3d));
            Assert.Throws <OverflowException>(() => a.Add((int)(int.MaxValue * 2d / 3d)));



            //Assert.Throws<ArgumentException>(() => a.AddWeight(double.NaN));
            //Assert.Throws<ArgumentException>(() => a.AddWeight(double.MaxValue));
            //Assert.Throws<ArgumentException>(() => a.AddWeight(double.PositiveInfinity));
            //Assert.Throws<ArgumentException>(() => a.AddWeight(0));
            //Assert.Throws<ArgumentException>(() => a.AddWeight(-1));

            //a.AddWeight(10);
            //Assert.Throws<ArgumentException>(() => a.AddWeight(double.MaxValue * (1d / 3d)));

            //var b = new StvBallot();
            //b.AddWeight(double.MaxValue * (1d / 3d));
            //Assert.Throws<ArgumentException>(() => b.AddWeight(10));

            //b.AddWeight(double.MaxValue * (1d / 3d));
            //Assert.Throws<ArgumentException>(() => a.AddWeight(double.MaxValue * (2d / 3d)));
        }
예제 #2
0
        public void EmptyBallotsTest()
        {
            var a = new StvBallot();

            Assert.IsNotNull(a.OrderedCandidatesIds);
            Assert.IsTrue(a.HasSame(null));
            Assert.IsTrue(a.HasSame(new int[0]));
        }
예제 #3
0
        public void CompareTest()
        {
            var a = new StvBallot(new[] { 1, 2 });

            Assert.IsFalse(a.HasSame(null));
            Assert.IsFalse(a.HasSame(new int[] { }));
            Assert.IsFalse(a.HasSame(new int[] { 1 }));
            Assert.IsFalse(a.HasSame(new int[] { 1, 2, 3 }));
            Assert.IsFalse(a.HasSame(new int[] { 1, 3 }));
            Assert.IsTrue(a.HasSame(new int[] { 1, 2 }));
        }
예제 #4
0
 public StvBallotWithWeight(StvBallot ballot)
 {
     this.ballot = ballot;
     Weight      = ballot.Count;
 }