Skip to content

Commit

Permalink
Merge branch 'dezzy30000-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul D'Ambra committed Jan 6, 2017
2 parents d92426e + 82179fe commit 1d6ec85
Show file tree
Hide file tree
Showing 8 changed files with 40,146 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .semver
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:major: 1
:minor: 4
:patch: 0
:patch: 1
:special: ""
5 changes: 3 additions & 2 deletions ModulusChecking/Loaders/ValacdosSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public class ValacdosSource : IRuleMappingSource
public ValacdosSource()
{
GetModulusWeightMappings = Resources.valacdos
.Split(new[] {"\r\n", "\n"}, StringSplitOptions.None)
.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None)
.Where(row => row.Length > 0)
.Select<string, ModulusWeightMapping>(row => ModulusWeightMapping.From(row));
.Select(row => ModulusWeightMapping.From(row))
.ToArray();
}
}
}
186 changes: 94 additions & 92 deletions ModulusChecking/Models/AccountNumber.cs
Original file line number Diff line number Diff line change
@@ -1,128 +1,130 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace ModulusChecking.Models
{
internal class AccountNumber : IEquatable<AccountNumber>
{
private readonly int[] _accountNumber;

public static AccountNumber Parse(string accountNumber)
{
if (!Regex.IsMatch(accountNumber, @"^[0-9]{6,8}$"))
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace ModulusChecking.Models
{
internal class AccountNumber : IEquatable<AccountNumber>
{
private static readonly Regex _accountNumberRegex = new Regex("^[0-9]{6,8}$", RegexOptions.Compiled);

private readonly int[] _accountNumber;

public static AccountNumber Parse(string accountNumber)
{
if (!_accountNumberRegex.IsMatch(accountNumber))
{
throw new ArgumentException(string.Format("The provided account number {0} must be a string of between six and eight digits", accountNumber));
}

}

accountNumber = accountNumber.PadLeft(8, '0');

var parsedAccountNumber = new int[8];
for (var index = 0; index < accountNumber.Count(); index++)
{
var character = accountNumber[index];
parsedAccountNumber[index] = int.Parse(character.ToString());
}

return new AccountNumber(parsedAccountNumber);
}

private AccountNumber(int[] accountNumber)
{
_accountNumber = accountNumber;
}

public int GetExceptionFourCheckValue
{
get
{
}

return new AccountNumber(parsedAccountNumber);
}

private AccountNumber(int[] accountNumber)
{
_accountNumber = accountNumber;
}

public int GetExceptionFourCheckValue
{
get
{
var checkString = string.Format("{0}{1}", _accountNumber[6], _accountNumber[7]);
return int.Parse(checkString);
}
}

/// <summary>
/// Exception Six Indicates that these sorting codes may contain foreign currency accounts which cannot be checked.
/// Perform the first and second checks, except:
/// • If a = 4, 5, 6, 7 or 8, and g and h are the same, the accounts are for a foreign currency and the checks
/// cannot be used.
/// This method returns true if this is a foreign currency account and therefore this account cannot be checked.
/// </summary>
public bool IsForeignCurrencyAccount
return int.Parse(checkString);
}
}

/// <summary>
/// Exception Six Indicates that these sorting codes may contain foreign currency accounts which cannot be checked.
/// Perform the first and second checks, except:
/// • If a = 4, 5, 6, 7 or 8, and g and h are the same, the accounts are for a foreign currency and the checks
/// cannot be used.
/// This method returns true if this is a foreign currency account and therefore this account cannot be checked.
/// </summary>
public bool IsForeignCurrencyAccount
{
get { return _accountNumber[0] >= 4 && _accountNumber[0] <= 8 && _accountNumber[6] == _accountNumber[7]; }
}

public bool ExceptionTenShouldZeroiseWeights
{
get { return _accountNumber[0] >= 4 && _accountNumber[0] <= 8 && _accountNumber[6] == _accountNumber[7]; }
}

public bool ExceptionTenShouldZeroiseWeights
{
get
{
return
(MatchFirstTwoCharacters(0, 9) || MatchFirstTwoCharacters(9, 9))
get
{
return
(MatchFirstTwoCharacters(0, 9) || MatchFirstTwoCharacters(9, 9))
&&
_accountNumber[6] == 9;
}
}

private bool MatchFirstTwoCharacters(int first, int second)
_accountNumber[6] == 9;
}
}

private bool MatchFirstTwoCharacters(int first, int second)
{
return _accountNumber[0] == first && _accountNumber[1] == second;
}

public bool IsValidCouttsNumber
return _accountNumber[0] == first && _accountNumber[1] == second;
}

public bool IsValidCouttsNumber
{
get { return _accountNumber[7] == 0 || _accountNumber[7] == 1 || _accountNumber[7] == 9; }
}

get { return _accountNumber[7] == 0 || _accountNumber[7] == 1 || _accountNumber[7] == 9; }
}

/// <summary>
/// For second exception 14 check a new account number is created by removing the final digit and prepending a 0
/// </summary>
public AccountNumber SlideFinalDigitOff()
{
var newNumber = new int[8];
newNumber[0] = 0;
Array.Copy(_accountNumber, 0, newNumber, 1, 7);
return new AccountNumber(newNumber);
}

public int IntegerAt(int i)
{
return _accountNumber[i];
}

public override string ToString()
{
return string.Join("", _accountNumber.Select(el => el.ToString()).ToArray());
}

/// </summary>
public AccountNumber SlideFinalDigitOff()
{
var newNumber = new int[8];
newNumber[0] = 0;
Array.Copy(_accountNumber, 0, newNumber, 1, 7);
return new AccountNumber(newNumber);
}

public int IntegerAt(int i)
{
return _accountNumber[i];
}

public override string ToString()
{
return string.Join("", _accountNumber.Select(el => el.ToString()).ToArray());
}

public bool Equals(AccountNumber other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(_accountNumber, other._accountNumber);
}

}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((AccountNumber) obj);
}

}

public override int GetHashCode()
{
return (_accountNumber != null ? _accountNumber.GetHashCode() : 0);
}

}

public static bool operator ==(AccountNumber left, AccountNumber right)
{
return Equals(left, right);
}

}

public static bool operator !=(AccountNumber left, AccountNumber right)
{
return !Equals(left, right);
}
}
}
}
}
}
4 changes: 3 additions & 1 deletion ModulusChecking/Models/SortCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace ModulusChecking.Models
{
public class SortCode
{
private static readonly Regex _sortCodeRegex = new Regex("^[0-9]{6}$", RegexOptions.Compiled);

private readonly double _doubleValue;
public double DoubleValue { get {return _doubleValue;} }
private readonly string _value;
Expand All @@ -16,7 +18,7 @@ public override string ToString()

public SortCode(string s)
{
if (!Regex.IsMatch(s, "^[0-9]{6}$"))
if (!_sortCodeRegex.IsMatch(s))
{
throw new ArgumentException("A Sort Code must be a string consisting of 6 digits. Not " + s);
}
Expand Down
36 changes: 36 additions & 0 deletions PublicInterfaceTests/PerformanceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using ModulusChecking;
using NUnit.Framework;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace PublicInterfaceTests
{
public class PerformanceTests
{
[TestCase(2)]
public void ItCanProcessALargeFileInUnder(int seconds)
{
var stopwatch = new Stopwatch();
var modulusChecker = new ModulusChecker();

using (var sr = new StreamReader("sa.txt"))
{
stopwatch.Start();

while (sr.Peek() >= 0)
{
var segments = sr
.ReadLine()
.Split('\t');

modulusChecker.CheckBankAccount(segments.First(), segments.Last());
}

stopwatch.Stop();
}

Assert.IsTrue(stopwatch.Elapsed.Seconds <= seconds, string.Format("Failed to process a large number of sortcodes and account numbers in under {0} seconds.", seconds));
}
}
}
6 changes: 6 additions & 0 deletions PublicInterfaceTests/PublicInterfaceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="IssueFive.cs" />
<Compile Include="PerformanceTests.cs" />
<Compile Include="VocalinkTestCases.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand All @@ -51,6 +52,11 @@
<Name>ModulusChecking</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="sa.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 1d6ec85

Please sign in to comment.