diff --git a/src/Dedge.Cardizer/Dedge.Cardizer.fs b/src/Dedge.Cardizer/Dedge.Cardizer.fs index 6ab06e9..ce86be3 100644 --- a/src/Dedge.Cardizer/Dedge.Cardizer.fs +++ b/src/Dedge.Cardizer/Dedge.Cardizer.fs @@ -31,6 +31,12 @@ type From16To19 = | Seventeen = 17 | Eightteen = 18 | Nineteen = 19 + +type From16To19Skip17 = + | Random = 0 + | Sixteen = 16 + | Eighteen = 18 + | Nineteen = 19 type DinersClubInternationalLengthOptions = | Random = 0 @@ -597,3 +603,28 @@ type Cardizer = [ 9; 7; 9; 2 ] ].[Cardizer.next 2] Cardizer.GenerateCard prefix 16 + + /// Returns a random Solo number. + /// Random Solo number + /// + /// This sample shows how to call the method. + /// + /// void PrintSolo() + /// { + /// Console.WriteLine(Cardizer.NextSolo()); // randomized between 16, 18 or 19 + /// Console.WriteLine(Cardizer.NextSolo(From16To19Skip17.Random)); // randomized between 16, 18 or 19 + /// Console.WriteLine(Cardizer.NextSolo(From16To19Skip17.Sixteen)); + /// } + /// + /// + static member NextSolo([] soloLengthOption) = + let length = + match soloLengthOption with + | From16To19Skip17.Random -> [ 16; 18; 19 ].[Cardizer.next 3] + | _ -> int soloLengthOption + + let prefix = + [ [ 6; 3; 3; 4 ] + [ 6; 7; 6; 7 ] ].[Cardizer.next 2] + + Cardizer.GenerateCard prefix length diff --git a/src/Tests/Tests.fs b/src/Tests/Tests.fs index fd937f2..2a5ebf1 100644 --- a/src/Tests/Tests.fs +++ b/src/Tests/Tests.fs @@ -341,3 +341,20 @@ let ``Should generate valid Troy`` () = prefixInRange |> should be True card |> should haveLength 16 card |> luhn |> should be LuhnCheck + +[] +[] +[] +[] +let ``Should generate valid Solo`` length expectedLength = + let card = Cardizer.NextSolo length + + let start = card.Substring(0, 4) |> int + + let prefixInRange = + start = 6334 + || start = 6767 + + prefixInRange |> should be True + card |> should haveLength expectedLength + card |> luhn |> should be LuhnCheck