예제 #1
0
        public void ExportPositionsTest()
        {
            this.objTest.AddStpBallotBallot(1, new int[] { 5, 6, 7 }, 0, 0);
            this.objTest.AddStpBallotBallot(2, new int[] { 100 }, 3, 5 + 6 + 7);

            this.objTest.AddStpContBallot(new int[] { 2, 1, 2 }, 0);
            this.objTest.AddStpContBallot(new[] { 3 }, 3);

            this.objTest.AddStpCandBallot(5 + 6 + 7 + 100);

            // count is the maximum number of candidates in a contest
            this.objTest.AddStpParty(7);

            this.objTest.LoadStpParams();
            BallotPdfTestObject.SetIdentifierFace(
                this.objTest.parameters, PaperSide.Front);
            this.objTest.SetTarget(0.12, 0.08, 0, 0, 0.0035, 100);

            int selectedId = 1;
            MatrixPtyCstPaperBallot ballot = new MatrixPtyCstPaperBallot(
                this.objTest.ballots,
                this.objTest.contests,
                this.objTest.candidates,
                this.objTest.parameters,
                this.objTest.contlist,
                this.objTest.candlist,
                this.objTest.parties,
                this.objTest.target,
                selectedId,
                1,
                1);

            Ballot doBallot = ballot.ExportPositions();

            Assert.IsNotNull(doBallot);
            Assert.IsNotEmpty(doBallot.Cards);
            Assert.AreEqual(doBallot.BallotStyleId, selectedId);
            Assert.IsNotEmpty(doBallot.Cards[0].Faces);
            Assert.AreEqual(doBallot.Cards[0].Faces[0].Marks.Count, 5 + 6 + 7);

            List <int> markIds   = new List <int>();
            bool       uniqueIds = true;

            foreach (Card card in doBallot.Cards)
            {
                foreach (Face face in card.Faces)
                {
                    markIds.Clear();
                    uniqueIds = true;
                    foreach (Mark mark in face.Marks)
                    {
                        uniqueIds = uniqueIds &&
                                    (markIds.Contains(mark.Id) == false);
                        markIds.Add(mark.Id);
                    }

                    Assert.IsTrue(uniqueIds);
                }
            }
        }
예제 #2
0
 public void FixtureSetup()
 {
     this.mockData = new BallotPdfTestObject();
 }
예제 #3
0
        public void FaceReductionTest_OddFacesWithBarcodeInTheBack()
        {
            // add a ballot style with 2 contests, each contest has 2 candidates
            // ballot style 3
            // contest 1
            // candidate 1
            // candidate 2
            // contest 2
            // candidate 3
            // candidate 4
            this.mockData.AddStpBallotContest(3, 1, 1, 0, 2, 1);

            // add a page break on this contest to place it entirely on another
            // face. (contest display format == 1 means page break)
            this.mockData.AddStpBallotContest(3, 2, 2, 1, 2, 3);

            // add a second ballot style
            // ballot style 4
            // contest 1
            // candidate 1
            // candidate 2
            // contest 3
            // candidate 5
            // candidate 6
            this.mockData.AddStpBallotContest(4, 1, 1, 0, 2, 1);

            // add a page break on this contest to place it entirely on another
            // face. At this point, front faces are identical for both ballots
            // back faces are not
            this.mockData.AddStpBallotContest(4, 3, 3, 1, 2, 5);

            // add a third face to test that a 4th empty face is added just for
            // the barcode
            this.mockData.AddStpBallotContest(4, 4, 4, 1, 10, 7);

            // now add header texts for all contests
            // 4 contests, 1 text per contest, first id is 1
            this.mockData.AddStpContBallot(new int[] { 1, 1, 1, 1 }, 1);

            // add candidate texts for all candidates
            // 16 candidates total, first candidate id is 1
            this.mockData.AddStpCandBallot(16, 1);

            // load parameters from DB
            this.mockData.LoadStpParams();
            this.mockData.SetTarget(0.12, 0.08, 0, 0, 0.0035, 100);

            // make sure the barcode location is on the back of the paper
            BallotPdfTestObject.SetIdentifierFace(
                this.mockData.parameters, PaperSide.Back);

            // make sure that at least 1 field is included on the barcode
            BallotPdfTestObject.SetIdentifierMask(this.mockData.parameters, 1);

            int cardCount = 0, faceCount = 0;

            // create paper ballot objects for both ballot styles
            PaperBallot ballot1 = new PaperBallot(
                this.mockData.ballots,
                this.mockData.contests,
                this.mockData.candidates,
                this.mockData.parameters,
                this.mockData.target,
                3,
                cardCount,
                faceCount);

            // for the second ballot, we already have 1 card and 2 faces
            cardCount += ballot1.CardCount;
            faceCount += ballot1.FaceCount;
            PaperBallot ballot2 = new PaperBallot(
                this.mockData.ballots,
                this.mockData.contests,
                this.mockData.candidates,
                this.mockData.parameters,
                this.mockData.target,
                4,
                cardCount,
                faceCount);

            // create a paper binder
            PaperBinder binder = new PaperBinder();

            binder.AddBallot(ballot1);
            binder.AddBallot(ballot2);

            binder.Generate(OutputFolder);

            // wait a few seconds to let the PDF library flush all docs
            System.Threading.Thread.Sleep(4000);

            string[] files = Directory.GetFiles(OutputFolder, "*.pdf");

            // 1 face is reused, and 1 blank face is added so 5 files
            // should be found
            Assert.AreEqual(5, files.Length);
        }
예제 #4
0
        public void FaceReductionTest_AllDifferent()
        {
            // add a ballot style with 2 contests, each contest has 2 candidates
            // ballot style 1
            // contest 1
            // candidate 1
            // candidate 2
            // contest 2
            // candidate 3
            // candidate 4
            this.mockData.AddStpBallotContest(1, 1, 1, 0, 2, 1);

            // add a page break on this contest to place it entirely on another
            // face. (contest display format == 1 means page break)
            this.mockData.AddStpBallotContest(1, 2, 2, 1, 2, 3);

            // add a second ballot style
            // ballot style 2
            // contest 1
            // candidate 1
            // candidate 2
            // contest 3
            // candidate 5
            // candidate 6
            this.mockData.AddStpBallotContest(2, 1, 1, 0, 2, 1);

            // add a page break on this contest to place it entirely on another
            // face. At this point, front faces are identical for both ballots
            // back faces are not
            this.mockData.AddStpBallotContest(2, 3, 3, 1, 2, 5);

            // now add header texts for all contests
            // 3 contests, 1 text per contest, first id is 1
            this.mockData.AddStpContBallot(new int[] { 1, 1, 1 }, 1);

            // add candidate texts for all candidates
            // 6 candidates total, first candidate id is 1
            this.mockData.AddStpCandBallot(6, 1);

            // load parameters from DB
            this.mockData.LoadStpParams();
            this.mockData.SetTarget(0.12, 0.08, 0, 0, 0.0035, 100);

            // make sure the barcode location is on the front of the paper
            // take the parameters entry set and set the IdentifierLocation
            // parameter to Front
            BallotPdfTestObject.SetIdentifierFace(
                this.mockData.parameters, PaperSide.Front);

            // make sure that at least 1 field is included on the barcode
            BallotPdfTestObject.SetIdentifierMask(this.mockData.parameters, 1);

            // create paper ballot objects for both ballot styles
            PaperBallot ballot1 = new PaperBallot(
                this.mockData.ballots,
                this.mockData.contests,
                this.mockData.candidates,
                this.mockData.parameters,
                this.mockData.target,
                1,
                0,
                0),

            // for the second ballot, we already have 1 card and
            // 2 faces
                        ballot2 = new PaperBallot(
                this.mockData.ballots,
                this.mockData.contests,
                this.mockData.candidates,
                this.mockData.parameters,
                this.mockData.target,
                2,
                1,
                2);

            // create a paper binder
            PaperBinder binder = new PaperBinder();

            binder.AddBallot(ballot1);
            binder.AddBallot(ballot2);

            binder.Generate(OutputFolder);

            // wait a few seconds to let the PDF library flush all docs
            System.Threading.Thread.Sleep(4000);

            string[] files = Directory.GetFiles(OutputFolder, "*.pdf");
            Assert.AreEqual(4, files.Length);
        }
예제 #5
0
 public void FixtureSetup()
 {
     this.objTest = new BallotPdfTestObject();
 }
예제 #6
0
        public void FaceReductionTest_OddFacesWithBarcodeInTheBack()
        {
            // add a ballot style with 2 contests, each contest has 2 candidates
            // ballot style 1
            // contest 1
            // candidate 1
            // candidate 2
            // contest 2
            // candidate 3
            // candidate 4
            this.objTest.AddStpBallotContest(1, 1, 1, 0, 2, 1);

            // add a page break on this contest to place it entirely on another
            // face. (contest display format == 1 means page break)
            this.objTest.AddStpBallotContest(1, 2, 2, 1, 2, 3);

            // add a second ballot style
            // ballot style 2
            // contest 1
            // candidate 1
            // candidate 2
            // contest 3
            // candidate 5
            // candidate 6
            this.objTest.AddStpBallotContest(2, 1, 1, 0, 2, 1);

            // add a page break on this contest to place it entirely on another
            // face. At this point, front faces are identical for both ballots
            // back faces are not
            this.objTest.AddStpBallotContest(2, 3, 3, 1, 2, 5);

            // add a third face to test that a 4th empty face is added just for
            // the barcode
            this.objTest.AddStpBallotContest(2, 4, 4, 1, 10, 7);

            // now add header texts for all contests
            // 4 contests, 1 text per contest, first id is 1
            this.objTest.AddStpContBallot(new int[] { 1, 1, 1, 1 }, 1);

            // add candidate texts for all candidates
            // 16 candidates total, first candidate id is 1
            this.objTest.AddStpCandBallot(16, 1);

            // load parameters from DB
            this.objTest.LoadStpParams();
            this.objTest.SetTarget(0.12, 0.08, 0, 0, 0.0035, 100);

            // make sure the barcode location is on the back of the paper
            BallotPdfTestObject.SetIdentifierFace(
                this.objTest.parameters, PaperSide.Back);

            // make sure that at least 1 field is included on the barcode
            BallotPdfTestObject.SetIdentifierMask(this.objTest.parameters, 1);

            // create paper ballot objects for both ballot styles
            PaperBallot ballot1 = new PaperBallot(
                this.objTest.ballots,
                this.objTest.contests,
                this.objTest.candidates,
                this.objTest.parameters,
                this.objTest.target,
                1,
                1,
                1),

            // for the second ballot, we already have 1 card and
            // 2 faces
                        ballot2 = new PaperBallot(
                this.objTest.ballots,
                this.objTest.contests,
                this.objTest.candidates,
                this.objTest.parameters,
                this.objTest.target,
                2,
                2,
                3);

            ballot1.Precinct = 1;
            ballot2.Precinct = 2;

            // create a definition binder and add both ballots
            // the definition binder should be smart enough to notice that the
            // first face of both ballot cards are identical, resulting in only
            // 3 faces for 2 cards, 1 card per ballot
            DefinitionBinder binder = new DefinitionBinder();

            binder.AddBallot(ballot1.ExportPositions());
            binder.AddBallot(ballot2.ExportPositions());

            // generated PDFs to manually compare barcodes
            PaperBinder binder2 = new PaperBinder();

            binder2.AddBallot(ballot1);
            binder2.AddBallot(ballot2);
            binder2.Generate(@"..\..\TestData");

            // save files for further inspection
            this.objTest.Serialize(
                @"..\..\TestData\Ballots.B.xml",
                binder.Ballots,
                typeof(BallotList));
            this.objTest.Serialize(
                @"..\..\TestData\Cards.B.xml", binder.Cards, typeof(CardList));
            this.objTest.Serialize(
                @"..\..\TestData\Faces.B.xml", binder.Faces, typeof(FaceList));

            // check the results
            // 3 faces expected, not 4 even though there are 2 cards,
            // 2 faces each
            Assert.AreEqual(5, binder.Faces.Count);

            // 3 cards, 1 + 2
            Assert.AreEqual(3, binder.Cards.Count);

            // the second face of both cards are the same
            Assert.AreEqual(binder.Cards[0].Faces[1].Id,
                            binder.Cards[1].Faces[1].Id);

            // verify face ids
            Assert.AreEqual(1, binder.Cards[0].Faces[0].Id);
            Assert.AreEqual(2, binder.Cards[0].Faces[1].Id);

            // the second card reuses the first face
            Assert.AreEqual(3, binder.Cards[1].Faces[0].Id);
            Assert.AreEqual(2, binder.Cards[1].Faces[1].Id);
            Assert.AreEqual(5, binder.Cards[2].Faces[0].Id);

            // an additional blank face just for the barcode
            Assert.AreEqual(6, binder.Cards[2].Faces[1].Id);

            // verify card ids
            Assert.AreEqual(1, binder.Cards[0].Id);
            Assert.AreEqual(2, binder.Cards[1].Id);
            Assert.AreEqual(3, binder.Cards[2].Id);

            // verify ballot ids
            Assert.AreEqual(1, binder.Ballots[0].Id);
            Assert.AreEqual(2, binder.Ballots[1].Id);
        }
예제 #7
0
        public void FaceReductionTest()
        {
            // add a ballot style with 2 contests, each contest has 2 candidates
            // ballot style 1
            // contest 1
            // candidate 1
            // candidate 2
            // contest 2
            // candidate 3
            // candidate 4
            this.objTest.AddStpBallotContest(1, 1, 1, 0, 2, 1);

            // add a page break on this contest to place it entirely on another
            // face. (contest display format == 1 means page break)
            this.objTest.AddStpBallotContest(1, 2, 2, 1, 2, 3);

            // add a second ballot style
            // ballot style 2
            // contest 1
            // candidate 1
            // candidate 2
            // contest 3
            // candidate 5
            // candidate 6
            this.objTest.AddStpBallotContest(2, 1, 1, 0, 2, 1);

            // add a page break on this contest to place it entirely on another
            // face. At this point, front faces are identical for both ballots
            // back faces are not
            this.objTest.AddStpBallotContest(2, 3, 3, 1, 2, 5);

            // now add header texts for all contests
            // 3 contests, 1 text per contest, first id is 1
            this.objTest.AddStpContBallot(new int[] { 1, 1, 1 }, 1);

            // add candidate texts for all candidates
            // 6 candidates total, first candidate id is 1
            this.objTest.AddStpCandBallot(6, 1);

            // load parameters from DB
            this.objTest.LoadStpParams();
            this.objTest.SetTarget(0.12, 0.08, 0, 0, 0.0035, 100);

            // make sure the barcode location is on the front of the paper
            BallotPdfTestObject.SetIdentifierFace(
                this.objTest.parameters, PaperSide.Front);

            // create paper ballot objects for both ballot styles
            PaperBallot ballot1 = new PaperBallot(
                this.objTest.ballots,
                this.objTest.contests,
                this.objTest.candidates,
                this.objTest.parameters,
                this.objTest.target,
                1,
                0,
                0),

            // for the second ballot, we already have 1 card and
            // 2 faces
                        ballot2 = new PaperBallot(
                this.objTest.ballots,
                this.objTest.contests,
                this.objTest.candidates,
                this.objTest.parameters,
                this.objTest.target,
                2,
                1,
                2);

            // create a definition binder and add both ballots
            // the definition binder should be smart enough to notice that the
            // first face of both ballot cards are identical, resulting in only
            // 3 faces for 2 cards, 1 card per ballot
            DefinitionBinder binder = new DefinitionBinder();

            binder.AddBallot(ballot1.ExportPositions());
            binder.AddBallot(ballot2.ExportPositions());

            // save files for further inspection
            this.objTest.Serialize(
                @"..\..\TestData\Ballots.xml",
                binder.Ballots,
                typeof(BallotList));
            this.objTest.Serialize(
                @"..\..\TestData\Cards.xml", binder.Cards, typeof(CardList));
            this.objTest.Serialize(
                @"..\..\TestData\Faces.xml", binder.Faces, typeof(FaceList));

            // check the results
            // 3 faces expected, not 4 even though there are 2 cards, 2 \
            // faces each
            Assert.AreEqual(3, binder.Faces.Count);

            // 2 cards, 1 for each ballot style
            Assert.AreEqual(2, binder.Cards.Count);

            // the first face of both cards are the same
            Assert.AreEqual(
                binder.Cards[0].Faces[0].Id,
                binder.Cards[1].Faces[0].Id);

            // verify face ids
            Assert.AreEqual(0, binder.Cards[0].Faces[0].Id);
            Assert.AreEqual(1, binder.Cards[0].Faces[1].Id);
            Assert.AreEqual(0, binder.Cards[1].Faces[0].Id);
            Assert.AreEqual(3, binder.Cards[1].Faces[1].Id);

            // verify card ids
            Assert.AreEqual(0, binder.Cards[0].Id);
            Assert.AreEqual(1, binder.Cards[1].Id);

            // verify ballot ids
            Assert.AreEqual(1, binder.Ballots[0].Id);
            Assert.AreEqual(2, binder.Ballots[1].Id);

            // verify ballot style ids
            Assert.AreEqual(1, binder.Ballots[0].BallotStyleId);
            Assert.AreEqual(2, binder.Ballots[1].BallotStyleId);
        }