summary refs log tree commit diff stats
path: root/raku/hamming/hamming.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/hamming/hamming.rakutest
parent2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff)
downloadexercism-321825828ac918bad28d0597a8616c6dc9802c3c.tar.gz
Add solved exercises
Diffstat (limited to 'raku/hamming/hamming.rakutest')
-rw-r--r--raku/hamming/hamming.rakutest122
1 files changed, 122 insertions, 0 deletions
diff --git a/raku/hamming/hamming.rakutest b/raku/hamming/hamming.rakutest
new file mode 100644
index 0000000..1c5cfb3
--- /dev/null
+++ b/raku/hamming/hamming.rakutest
@@ -0,0 +1,122 @@
+#!/usr/bin/env raku
+use Test;
+use JSON::Fast;
+use lib $?FILE.IO.dirname;
+use Hamming;
+plan 9;
+
+my @test-cases = from-json($=pod.pop.contents).List;
+for @test-cases -> %case {
+  given %case<expected> {
+    when .<error>.so {
+      throws-like
+        { hamming-distance |%case<input><strand1 strand2> },
+        Exception,
+        message => /
+          'left and right strands must be of equal length'
+          || 'Constraint type check failed in binding to parameter'
+        /,
+        %case<description>;
+    }
+
+    default {
+      is hamming-distance(|%case<input><strand1 strand2>),
+        |%case<expected description>;
+    }
+  }
+}
+
+=head2 Test Cases
+=begin code
+[
+  {
+    "description": "empty strands",
+    "expected": 0,
+    "input": {
+      "strand1": "",
+      "strand2": ""
+    },
+    "property": "distance"
+  },
+  {
+    "description": "single letter identical strands",
+    "expected": 0,
+    "input": {
+      "strand1": "A",
+      "strand2": "A"
+    },
+    "property": "distance"
+  },
+  {
+    "description": "single letter different strands",
+    "expected": 1,
+    "input": {
+      "strand1": "G",
+      "strand2": "T"
+    },
+    "property": "distance"
+  },
+  {
+    "description": "long identical strands",
+    "expected": 0,
+    "input": {
+      "strand1": "GGACTGAAATCTG",
+      "strand2": "GGACTGAAATCTG"
+    },
+    "property": "distance"
+  },
+  {
+    "description": "long different strands",
+    "expected": 9,
+    "input": {
+      "strand1": "GGACGGATTCTG",
+      "strand2": "AGGACGGATTCT"
+    },
+    "property": "distance"
+  },
+  {
+    "description": "disallow first strand longer",
+    "expected": {
+      "error": "left and right strands must be of equal length"
+    },
+    "input": {
+      "strand1": "AATG",
+      "strand2": "AAA"
+    },
+    "property": "distance"
+  },
+  {
+    "description": "disallow second strand longer",
+    "expected": {
+      "error": "left and right strands must be of equal length"
+    },
+    "input": {
+      "strand1": "ATA",
+      "strand2": "AGTG"
+    },
+    "property": "distance"
+  },
+  {
+    "description": "disallow left empty strand",
+    "expected": {
+      "error": "left strand must not be empty"
+    },
+    "input": {
+      "strand1": "",
+      "strand2": "G"
+    },
+    "property": "distance"
+  },
+  {
+    "description": "disallow right empty strand",
+    "expected": {
+      "error": "right strand must not be empty"
+    },
+    "input": {
+      "strand1": "G",
+      "strand2": ""
+    },
+    "property": "distance"
+  }
+]
+=end code