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 Solo #64

Merged
merged 4 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions src/Dedge.Cardizer/Dedge.Cardizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,26 @@ type Cardizer =
[ 9; 7; 9; 2 ] ].[Cardizer.next 2]

Cardizer.GenerateCard prefix 16

/// <summary>Returns a random Laser number.</summary>
/// <returns>Random Laser number</returns>
/// <example>
/// This sample shows how to call the <see cref="NextLaser"/> method.
/// <code>
/// void PrintLaser()
/// {
/// Console.WriteLine(Cardizer.NextLaser());
/// }
/// </code>
/// </example>
static member NextSolo([<Optional; DefaultParameterValue(From16To19.Random)>] soloLengthOption) =
let length =
match soloLengthOption with
| From16To19.Random -> Cardizer.NextInRange 16 19
| _ -> int soloLengthOption

let prefix =
[ [ 6; 3; 3; 4 ]
[ 6; 7; 6; 7 ] ].[Cardizer.next 2]

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

[<Theory>]
[<InlineData(From16To19.Sixteen, 16)>]
[<InlineData(From16To19.Seventeen, 17)>]
[<InlineData(From16To19.Eightteen, 18)>]
[<InlineData(From16To19.Nineteen, 19)>]
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