public void QCumulativeCandidateVoteTests(bool yesCheck, long yesVotes, long expectedResultLong) { const bool doesntMatter2 = false; const long doesntMatter3 = 0; const int doesntMatter4 = 0; const int doesntMatter5 = 1; var candidatePoint = new QCumCandidatePoint(doesntMatter5, Fields.VotesDocField(yesVotes.FL())); var qCum = new QCumulative(doesntMatter5, new List <QCumCandidatePoint> { candidatePoint }, new QCumulativeAdditionalMarks(Fields.CheckBoxDocField(yesCheck), Fields.CheckBoxDocField(doesntMatter2), Fields.VotesDocField(doesntMatter3.FL()), Fields.CheckBoxDocField(doesntMatter2), Fields.VotesDocField(doesntMatter3.FL(), doesntMatter4))); var result = _calculator.GetVotesForCandidateField(qCum, candidatePoint); var expected = new FractionLong(expectedResultLong); Assert.That(result, Is.EqualTo(expected)); }
public void QCumulativeTests(bool yesCheck, int firstVote, int secondVote, int thirdVote, bool noCheck, int noVotes, bool absCheck, int absVotes, AmountOfStockSubmited expected) { var allowedVotesAmount = new FractionLong(100); var qCum = new QCumulative(1, new List <QCumCandidatePoint> { new QCumCandidatePoint(1, Fields.VotesDocField(firstVote)), new QCumCandidatePoint(2, Fields.VotesDocField(secondVote)), new QCumCandidatePoint(3, Fields.VotesDocField(thirdVote)), }, new QCumulativeAdditionalMarks( Fields.CheckBoxDocField(yesCheck), Fields.CheckBoxDocField(noCheck), Fields.VotesDocField(noVotes), Fields.CheckBoxDocField(absCheck), Fields.VotesDocField(absVotes)) ) { PositionsCount = 10 }; var result = _calculator.GetAmountOfStockSubmited(qCum, allowedVotesAmount); Assert.That(result, Is.EqualTo(expected)); }
public MultivariantVotingQCumulativeRule(QCumulative question, BulletinAdditionalMarks additionalMarks, Func <NumberOfChecks> numberOfChecks, Func <AdditionalChecks> additionalChecks) { Question = question; AdditionalMarks = additionalMarks; _numberOfChecks = numberOfChecks; _additionalChecks = additionalChecks; }
public QCumulativeFractionDistributionRule(QCumulative question, Func <List <FractionLong> > allowedVotesAmountFractions, Func <AdditionalChecks> additionalChecks, bool isADR, Func <bool> hasInstructions) { _allowedVotesAmountFractions = allowedVotesAmountFractions; _hasInstructions = hasInstructions; _isADR = isADR; _additionalChecks = additionalChecks; Question = question; }
private static QCumulative GetQCumulative(int positionsCount, FractionLong assigned) { var qCumulative = new QCumulative(1, GetCandidatePoints(assigned), GetAdditionalMarks()); qCumulative.AdditionalMarks.YesCheckBoxField.Value = true; qCumulative.PositionsCount = positionsCount; return(qCumulative); }
public QCumulativeTableRule(QCumulative qCumulative, BulletinAdditionalMarks additionalMarks, Func <PackStatus> packStatus, Func <bool> trustExists, Func <AmountOfStockSubmited> amountOfStockSubmited, Func <NumberOfChecks> numberOfChecks, Func <AdditionalChecks> additionalChecks, Func <CumYesIs> cumChecks) { _packStatus = packStatus; _trustExists = trustExists; _amountOfStockSubmited = amountOfStockSubmited; _numberOfChecks = numberOfChecks; _additionalChecks = additionalChecks; _cumChecks = cumChecks; Question = qCumulative; AdditionalMarks = additionalMarks; }
public void TestFixtureSetUp() { _invalidQCum1 = GetQCumulative(candidate1ErrorLevel: ErrorLevel.WasntChecked, candidate2ErrorLevel: ErrorLevel.Error, candidate3ErrorLevel: ErrorLevel.Valid, candidate4ErrorLevel: ErrorLevel.Valid, candidate5ErrorLevel: ErrorLevel.WasntChecked, yesCheckBoxErrorLevel: ErrorLevel.Valid, noCheckBoxErrorLevel: ErrorLevel.WasntChecked, noVotesErrorLevel: ErrorLevel.Valid, abstainedCheckBoxErrorLevel: ErrorLevel.WasntChecked, abstainedVotesErrorLevel: ErrorLevel.Valid); _validQCum = GetQCumulative(candidate1ErrorLevel: ErrorLevel.WasntChecked, candidate2ErrorLevel: ErrorLevel.WasntChecked, candidate3ErrorLevel: ErrorLevel.Valid, candidate4ErrorLevel: ErrorLevel.Valid, candidate5ErrorLevel: ErrorLevel.WasntChecked, yesCheckBoxErrorLevel: ErrorLevel.Valid, noCheckBoxErrorLevel: ErrorLevel.WasntChecked, noVotesErrorLevel: ErrorLevel.Valid, abstainedCheckBoxErrorLevel: ErrorLevel.WasntChecked, abstainedVotesErrorLevel: ErrorLevel.Valid); _invalidQCum2 = GetQCumulative(candidate1ErrorLevel: ErrorLevel.WasntChecked, candidate2ErrorLevel: ErrorLevel.WasntChecked, candidate3ErrorLevel: ErrorLevel.Valid, candidate4ErrorLevel: ErrorLevel.Valid, candidate5ErrorLevel: ErrorLevel.WasntChecked, yesCheckBoxErrorLevel: ErrorLevel.Valid, noCheckBoxErrorLevel: ErrorLevel.WasntChecked, noVotesErrorLevel: ErrorLevel.Valid, abstainedCheckBoxErrorLevel: ErrorLevel.Error, abstainedVotesErrorLevel: ErrorLevel.Valid); var questions = new List <Question> { _invalidQCum1, _validQCum, _invalidQCum2 }; var bulletin = TestBulletinModel.Create(questions); var checker = new QuestionValidityChecker(new CandidateValidityChecker(), new AdrQuestionValidityChecker()); _invalidQuestions = checker.GetInvalidQuestions(bulletin); }
public static RuleNode GetQCumulativeTableRule(QCumulative qCumulative, BulletinAdditionalMarks additionalMarks, Func <PackStatus> packStatus, Func <bool> trustExists, Func <AmountOfStockSubmited> amountOfStockSubmited, Func <NumberOfChecks> numberOfChecks, Func <AdditionalChecks> additionalChecks, Func <CumYesIs> cumChecks) { return(RuleBuilder .RootRule(new InCaseOfSimplePackQCumulativeWithNoAdditionalMarksAlwaysPassesRule(qCumulative, additionalMarks, packStatus, amountOfStockSubmited, numberOfChecks, additionalChecks, cumChecks)) .AddRule(new MultivariantVotingQCumulativeRule(qCumulative, additionalMarks, numberOfChecks, additionalChecks)) .AddRule(new QCumulativeTableRule(qCumulative, additionalMarks, packStatus, trustExists, amountOfStockSubmited, numberOfChecks, additionalChecks, cumChecks)) .GetRoot()); }
public InCaseOfSimplePackQCumulativeWithNoAdditionalMarksAlwaysPassesRule(QCumulative qCumulative, BulletinAdditionalMarks additionalMarks, Func <PackStatus> packStatus, Func <AmountOfStockSubmited> amountOfStockSubmited, Func <NumberOfChecks> numberOfChecks, Func <AdditionalChecks> additionalChecks, Func <CumYesIs> cumChecks) { _packStatus = packStatus; _amountOfStockSubmited = amountOfStockSubmited; _numberOfChecks = numberOfChecks; _additionalChecks = additionalChecks; _cumChecks = cumChecks; Question = qCumulative; AdditionalMarks = additionalMarks; }
public AmountOfStockSubmited GetAmountOfStockSubmited(QCumulative qCum, FractionLong allowedVotesAmount) { if (qCum.AdditionalMarks.YesCheckBoxField.Value == true && qCum.CandidatePoints.Sum(c => c.VotesDocField.Value) == FractionLong.Zero) { return(AmountOfStockSubmited.VotesArentSubmited); } var pairs = new List <KeyValuePair <bool, FractionLong> > { new KeyValuePair <bool, FractionLong>(qCum.AdditionalMarks.YesCheckBoxField.Value, qCum.CandidatePoints.Sum(c => c.VotesDocField.Value)), new KeyValuePair <bool, FractionLong>(qCum.AdditionalMarks.NoCheckBoxField.Value, qCum.AdditionalMarks.NoVotesField.Value), new KeyValuePair <bool, FractionLong>(qCum.AdditionalMarks.AbstainedCheckBoxField.Value, qCum.AdditionalMarks.AbstainedVotesField.Value), }; return(GetAmountOfStockSubmittedFor(pairs, allowedVotesAmount)); }
private static NumberOfChecks GetNumberOfChecks(QCumulative qCum) { var checks = new List <CheckBoxDocField> { qCum.AdditionalMarks.YesCheckBoxField, qCum.AdditionalMarks.NoCheckBoxField, qCum.AdditionalMarks.AbstainedCheckBoxField }; if (checks.All(c => c.Value == false)) { throw new ArgumentOutOfRangeException(string.Empty, "�� ����� �� ����� �����"); } if (checks.Where(c => c.Value == true).Count() == 1) { return(NumberOfChecks.Single); } else { return(NumberOfChecks.Multiple); } }
private static RuleNode GetQCumulativeTableRule(BulletinScreenModelBase bulletin, QCumulative qCum, FractionLong allowedVotesAmount) { return(GetQCumulativeTableRule(qCum, bulletin.AdditionalMarks, () => bulletin.PackStatus, () => bulletin.TrustExists, () => AmountOfStockSubmitedCalculator.GetAmountOfStockSubmited(qCum, allowedVotesAmount), () => GetNumberOfChecks(qCum), () => BulletinAdditionalMarksToAdditionalChecksEnumConverter.ConvertToAdditionalChecksEnum(bulletin.AdditionalMarks), () => qCum.AdditionalMarks.YesCheckBoxField.Value ? CumYesIs.Checked : CumYesIs.NotChecked)); }
private static void SetVoteFieldsThatDontHaveCorrespondingChecksSetAsWasntChecked(QCumulative question) { if (question.AdditionalMarks.YesCheckBoxField.Value == false) { question.CandidatePoints.ForEach(cp => cp.VotesDocField.ErrorLevel = ErrorLevel.WasntChecked); } if (question.AdditionalMarks.NoCheckBoxField.Value == false) { question.AdditionalMarks.NoVotesField.ErrorLevel = ErrorLevel.WasntChecked; } if (question.AdditionalMarks.AbstainedCheckBoxField.Value == false) { question.AdditionalMarks.AbstainedVotesField.ErrorLevel = ErrorLevel.WasntChecked; } }
public AdrMustHaveExactVotesSpreadedWithMinimalSpredForQCum(QCumulative qCumulative, Func <FractionLong> allowedVotesAmount, bool isADRBulletin) { _allowedVotesAmount = allowedVotesAmount; _isADRBulletin = isADRBulletin; QCumulative = qCumulative; }
public QCumulativeWarningRule(QCumulative question, BulletinAdditionalMarks additionalMarks, Func <FractionLong> allowedVotesAmount) { _allowedVotesAmount = allowedVotesAmount; Question = question; AdditionalMarks = additionalMarks; }
public QCumulativeMustHaveAtLeastOneSelectionRule(QCumulative question) { Question = question; }