summary refs log tree commit diff stats
path: root/raku/luhn/luhn.rakutest
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-08-11 15:26:15 +0530
committerAndinus <andinus@nand.sh>2021-08-11 15:26:15 +0530
commit321825828ac918bad28d0597a8616c6dc9802c3c (patch)
tree0b8e9cb1012197750eb58e972736319b2a6abac2 /raku/luhn/luhn.rakutest
parent2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff)
downloadexercism-321825828ac918bad28d0597a8616c6dc9802c3c.tar.gz
Add solved exercises
Diffstat (limited to 'raku/luhn/luhn.rakutest')
-rw-r--r--raku/luhn/luhn.rakutest165
1 files changed, 165 insertions, 0 deletions
diff --git a/raku/luhn/luhn.rakutest b/raku/luhn/luhn.rakutest
new file mode 100644
index 0000000..4bd0e63
--- /dev/null
+++ b/raku/luhn/luhn.rakutest
@@ -0,0 +1,165 @@
+#!/usr/bin/env raku
+use Test;
+use JSON::Fast;
+use lib $?FILE.IO.dirname;
+use Luhn;
+plan 18;
+
+my @test-cases = from-json($=pod.pop.contents).List;
+for @test-cases -> %case {
+  subtest %case<description>, {
+    plan 2;
+    isa-ok ( my $result := is-luhn-valid %case<input><value> ), Bool;
+    is-deeply $result, %case<expected>, 'Result matches expected';
+  }
+}
+
+=head2 Test Cases
+=begin code
+[
+  {
+    "description": "single digit strings can not be valid",
+    "expected": false,
+    "input": {
+      "value": "1"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "a single zero is invalid",
+    "expected": false,
+    "input": {
+      "value": "0"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "a simple valid SIN that remains valid if reversed",
+    "expected": true,
+    "input": {
+      "value": "059"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "a simple valid SIN that becomes invalid if reversed",
+    "expected": true,
+    "input": {
+      "value": "59"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "a valid Canadian SIN",
+    "expected": true,
+    "input": {
+      "value": "055 444 285"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "invalid Canadian SIN",
+    "expected": false,
+    "input": {
+      "value": "055 444 286"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "invalid credit card",
+    "expected": false,
+    "input": {
+      "value": "8273 1232 7352 0569"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "invalid long number with an even remainder",
+    "expected": false,
+    "input": {
+      "value": "1 2345 6789 1234 5678 9012"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "valid number with an even number of digits",
+    "expected": true,
+    "input": {
+      "value": "095 245 88"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "valid number with an odd number of spaces",
+    "expected": true,
+    "input": {
+      "value": "234 567 891 234"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "valid strings with a non-digit added at the end become invalid",
+    "expected": false,
+    "input": {
+      "value": "059a"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "valid strings with punctuation included become invalid",
+    "expected": false,
+    "input": {
+      "value": "055-444-285"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "valid strings with symbols included become invalid",
+    "expected": false,
+    "input": {
+      "value": "055# 444$ 285"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "single zero with space is invalid",
+    "expected": false,
+    "input": {
+      "value": " 0"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "more than a single zero is valid",
+    "expected": true,
+    "input": {
+      "value": "0000 0"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "input digit 9 is correctly converted to output digit 9",
+    "expected": true,
+    "input": {
+      "value": "091"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "using ascii value for non-doubled non-digit isn't allowed",
+    "expected": false,
+    "input": {
+      "value": "055b 444 285"
+    },
+    "property": "valid"
+  },
+  {
+    "description": "using ascii value for doubled non-digit isn't allowed",
+    "expected": false,
+    "input": {
+      "value": ":9"
+    },
+    "property": "valid"
+  }
+]
+=end code