Inheritance: IModulusWeightMapping
コード例 #1
0
 public void ExceptionFiveValidationTestSumCheck()
 {
     var details = new BankAccountDetails("938611", "07806039");
     var mapping = new ModulusWeightMapping("012345 012346 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 0 5");
     var actual = _check.GetModulusSum(details, mapping);
     Assert.AreEqual(51, actual);
 }
コード例 #2
0
 public void ExceptionFiveFirstCheckCorrectSecondIncorrect()
 {
     var details = new BankAccountDetails("938063", "15764273");
     var mapping = new ModulusWeightMapping("012345 012346 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 0 5");
     var actual = _check.GetModulusSum(details, mapping);
     Assert.AreEqual(58, actual);
 }
コード例 #3
0
 private static ModulusWeightMapping ZeroiseUtoB(ModulusWeightMapping weightMapping)
 {
     return(new ModulusWeightMapping(weightMapping)
     {
         WeightValues = weightMapping.WeightValues.Select((wv, index) => index < 8 ? 0 : wv).ToArray()
     });
 }
コード例 #4
0
 public void CalculatesSumAsExpected()
 {
     var details = new BankAccountDetails("499273", "12345678");
     var mapping = new ModulusWeightMapping("012345 012346 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 1");
     var actual = _check.GetModulusSum(details, mapping);
     Assert.AreEqual(70,actual);
 }
コード例 #5
0
 public void CalculatesExceptionSixTestCaseCorrectly()
 {
     var details = new BankAccountDetails("202959", "63748472");
     var mapping = new ModulusWeightMapping("012345 012346 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 1");
     var actual = _check.GetModulusSum(details, mapping);
     Assert.AreEqual(60,actual);
 }
コード例 #6
0
 //938000 938696 Mod11 7 6 5 4 3 2 7 6 5 4 3 2 0 0 5
 //938000 938696 DblAl 2 1 2 1 2 1 2 1 2 1 2 1 2 0 5
 public void ExceptionFiveDoubleAlternateWhenBothPass()
 {
     var details = new BankAccountDetails("938063", "55065200");
     var mapping = new ModulusWeightMapping("938000 938696 DblAl 2 1 2 1 2 1 2 1 2 1 2 1 2 0 5");
     var actual = _check.GetModulusSum(details, mapping);
     Assert.AreEqual(40,actual);
     Assert.AreEqual(0,actual%10);
 }
コード例 #7
0
 protected bool ProcessWeightingRule(BankAccountDetails bankAccountDetails, ModulusWeightMapping modulusWeightMapping)
 {
     var weightingSum = new StandardModulusCheck().GetModulusSum(bankAccountDetails,modulusWeightMapping);
     var remainder = weightingSum%Modulus;
     return modulusWeightMapping.Exception == 4
                ? bankAccountDetails.AccountNumber.GetExceptionFourCheckValue == remainder
                : remainder == 0;
 }
コード例 #8
0
 public ModulusWeightMapping(ModulusWeightMapping original)
 {
     WeightValues = new int[14];
     Array.Copy(original.WeightValues, WeightValues, 14);
     Algorithm     = original.Algorithm;
     SortCodeStart = original.SortCodeStart;
     SortCodeEnd   = original.SortCodeEnd;
     Exception     = original.Exception;
 }
コード例 #9
0
 public ModulusWeightMapping(ModulusWeightMapping original)
 {
     WeightValues = new int[14];
     Array.Copy(original.WeightValues, WeightValues, 14);
     Algorithm = original.Algorithm;
     SortCodeStart = original.SortCodeStart;
     SortCodeEnd = original.SortCodeEnd;
     Exception = original.Exception;
 }
コード例 #10
0
 public void ExceptionOneChangesSum()
 {
     var details = new BankAccountDetails("123456", "12345678");
     var mapping = new ModulusWeightMapping("012345 012346 dblal 1 2 3 4 5 6 7 8 9 10 11 12 13 14");
     var withNoException = _check.GetModulusSum(details, mapping);
     mapping = new ModulusWeightMapping("012345 012346 dblal 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1");
     var withException = _check.GetModulusSum(details, mapping);
     Assert.IsTrue(withNoException + 27 == withException);
 }
コード例 #11
0
 public void CanLoadWeightingValues()
 {
     var actual = new ModulusWeightMapping("230872 230872 DBLAL    2    1    2    1    2    1    2    1    2    1    2    1    2    1");
     var expectedWeightValues = new[] {2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1};
     for(var i = 0; i<actual.WeightValues.Count(); i++)
     {
         Assert.AreEqual(actual.WeightValues.ElementAt(i),expectedWeightValues[i]);
     }
 }
コード例 #12
0
 private bool InitialSecondCheck(BankAccountDetails bankAccountDetails, IModulusWeightMapping mapping)
 {
     var alternativeWeightMapping = new ModulusWeightMapping(mapping)
                                        {
                                            WeightValues =
                                                bankAccountDetails
                                                .GetExceptionTwoAlternativeWeights(
                                                    mapping.WeightValues)
                                        };
     return ProcessWeightingRule(bankAccountDetails, alternativeWeightMapping);
 }
 /// For the standard check with exception 5 the checkdigit is g from the original account number.
 /// � After dividing the result by 11;
 /// - if the remainder=0 and g=0 the account number is valid
 /// - if the remainder=1 the account number is invalid
 /// - for all other remainders, take the remainder away from 11. If the number you get is the same as g 
 /// then the account number is valid.
 private new bool ProcessWeightingRule(BankAccountDetails bankAccountDetails, ModulusWeightMapping modulusWeightMapping)
 {
     var weightingSum = new StandardModulusCheck().GetModulusSum(bankAccountDetails, modulusWeightMapping);
     var remainder = weightingSum % Modulus;
     switch (remainder)
     {
         case 0 :
             return bankAccountDetails.AccountNumber.IntegerAt(6) == 0;
         case 1 :
             return false;
         default :
             return Modulus - remainder == bankAccountDetails.AccountNumber.IntegerAt(6);
     }
 }
コード例 #14
0
 public int GetModulusSum(BankAccountDetails bankAccountDetails, ModulusWeightMapping weightMapping)
 {
     var combinedValue = bankAccountDetails.ToCombinedString();
     if (combinedValue.Length != 14)
     {
         throw new Exception(
             string.Format("Combined SortCode and Account Number should be 14 characters long not {0}: {1}",
                           combinedValue.Length, combinedValue));
     }
     var sum = 0;
     for (var i = 0; i < 14; i++)
     {
         sum += (int.Parse(combinedValue[i].ToString(CultureInfo.InvariantCulture)) * weightMapping.WeightValues[i]);
     }
     return sum;
 }
コード例 #15
0
 private static ModulusWeightMapping ZeroiseUtoB(ModulusWeightMapping weightMapping)
 {
     return new ModulusWeightMapping(weightMapping)
     {
         WeightValues = weightMapping.WeightValues.Select((wv, index) => index < 8 ? 0 : wv).ToArray()
     };
 }
コード例 #16
0
 public void CanAddAlgorithm(string row, ModulusAlgorithm expected)
 {
     var actual = new ModulusWeightMapping(row);
     Assert.NotNull(actual);
     Assert.AreEqual(expected,actual.Algorithm);
 }