diff --git a/src/Dedge.Cardizer/Dedge.Cardizer.fs b/src/Dedge.Cardizer/Dedge.Cardizer.fs index c04649e..9db29e2 100644 --- a/src/Dedge.Cardizer/Dedge.Cardizer.fs +++ b/src/Dedge.Cardizer/Dedge.Cardizer.fs @@ -557,3 +557,21 @@ type Cardizer = [ 6; 3; 9 ] ].[Cardizer.next 3] Cardizer.GenerateCard prefix 16 + + /// Returns a random Troy number. + /// Random Troy number + /// + /// This sample shows how to call the method. + /// + /// void PrintTroy() + /// { + /// Console.WriteLine(Cardizer.NextTroy()); + /// } + /// + /// + static member NextTroy() = + let prefix = + [ [ 6; 5 ] + [ 9; 7; 9; 2 ] ].[Cardizer.next 2] + + Cardizer.GenerateCard prefix 16 diff --git a/src/Tests/Tests.fs b/src/Tests/Tests.fs index 8a716d6..82ba07e 100644 --- a/src/Tests/Tests.fs +++ b/src/Tests/Tests.fs @@ -307,3 +307,18 @@ let ``Should generate valid InstaPayment`` () = prefixInRange |> should be True card |> should haveLength 16 card |> luhn |> should be LuhnCheck + +[] +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