Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(card): add support for Troy #62

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Dedge.Cardizer/Dedge.Cardizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,21 @@ type Cardizer =
[ 6; 3; 9 ] ].[Cardizer.next 3]

Cardizer.GenerateCard prefix 16

/// <summary>Returns a random Troy number.</summary>
/// <returns>Random Troy number</returns>
/// <example>
/// This sample shows how to call the <see cref="NextTroy"/> method.
/// <code>
/// void PrintTroy()
/// {
/// Console.WriteLine(Cardizer.NextTroy());
/// }
/// </code>
/// </example>
static member NextTroy() =
let prefix =
[ [ 6; 5 ]
[ 9; 7; 9; 2 ] ].[Cardizer.next 2]

Cardizer.GenerateCard prefix 16
15 changes: 15 additions & 0 deletions src/Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,18 @@ let ``Should generate valid InstaPayment`` () =
prefixInRange |> should be True
card |> should haveLength 16
card |> luhn |> should be LuhnCheck

[<Fact>]
let ``Should generate valid Troy`` () =
let card = Cardizer.NextTroy()

let shortPrefix = card.Substring(0, 2) |> int
let longPrefix = card.Substring(0, 4) |> int

let prefixInRange =
shortPrefix = 65
|| longPrefix = 9792

prefixInRange |> should be True
card |> should haveLength 16
card |> luhn |> should be LuhnCheck