Skip to content

Commit

Permalink
feat(card): add support for card UkrCard (#81)
Browse files Browse the repository at this point in the history
Fix #46 

Co-authored-by: Umair Fayaz <[email protected]>
  • Loading branch information
umair-fayaz and umair-fayaz authored Oct 18, 2021
1 parent 99a9c56 commit a3631cc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/Dedge.Cardizer/Dedge.Cardizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -728,4 +728,25 @@ type Cardizer =
[ 6; 7; 6; 7; 7; 0 ]
[ 6; 7; 6; 7; 7; 4 ] ].[Cardizer.next 3]

Cardizer.GenerateCard prefix length
Cardizer.GenerateCard prefix length

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

let prefix = Cardizer.NextSeqInRange 60400100 60420099

Cardizer.GenerateCard prefix length
19 changes: 18 additions & 1 deletion src/Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,21 @@ let ``Should generate valid Maestro UK`` length expectedLength =

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

[<Theory>]
[<InlineData(From16To19.Sixteen, 16)>]
[<InlineData(From16To19.Seventeen, 17)>]
[<InlineData(From16To19.Eighteen, 18)>]
[<InlineData(From16To19.Nineteen, 19)>]
let ``Should generate valid UkrCard`` length expectedLength =
let card = Cardizer.NextUkrCard length

let start = card.Substring(0, 8) |> int

let prefixInRange =
(start >= 60400100 && start <= 60420099)

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

0 comments on commit a3631cc

Please sign in to comment.