From 4cd071999845584ae5513db52610a3b87d6dfeb3 Mon Sep 17 00:00:00 2001 From: n4bla Date: Sat, 1 Feb 2020 23:10:44 +0100 Subject: [PATCH 1/2] Adding exercise Levenshtein distance --- .../levenshtein-distance/canonical-data.json | 65 +++++++++++++++++++ exercises/levenshtein-distance/description.md | 8 +++ exercises/levenshtein-distance/metadata.yml | 4 ++ 3 files changed, 77 insertions(+) create mode 100644 exercises/levenshtein-distance/canonical-data.json create mode 100644 exercises/levenshtein-distance/description.md create mode 100644 exercises/levenshtein-distance/metadata.yml diff --git a/exercises/levenshtein-distance/canonical-data.json b/exercises/levenshtein-distance/canonical-data.json new file mode 100644 index 0000000000..df60caf5c9 --- /dev/null +++ b/exercises/levenshtein-distance/canonical-data.json @@ -0,0 +1,65 @@ +{ + "exercise": "levenshtein-distance", + "version": "1.0.0", + "cases": [ + { + "description": "Calculate Levenshtein distance", + "cases": [ + { + "description": "mine_to_times", + "property": "distance", + "input": { + "phrase": "mine", + "phrase": "times" + }, + "expected": "3" + }, + { + "description": "_to_abcd", + "property": "distance", + "input": { + "phrase": "", + "phrase": "abcd" + }, + "expected": "4" + }, + { + "description": "12345_to_", + "property": "distance", + "input": { + "phrase": "12345", + "phrase": "" + }, + "expected": "5" + }, + { + "description": "lifo_to_fifo", + "property": "distance", + "input": { + "phrase": "lifo", + "phrase": "fifo" + }, + "expected": "1" + }, + { + "description": "Hello-World!_to_hello-world", + "property": "distance", + "input": { + "phrase": "Hello World!", + "phrase": "hello world" + }, + "expected": "3" + }, + { + "description": "oxygenO2_to_carbondioxideCO2", + "property": "distance", + "input": { + "phrase": "oxygenO2", + "phrase": "carbondioxideCO2" + }, + "expected": "11" + } + ] + } + ] +} diff --git a/exercises/levenshtein-distance/description.md b/exercises/levenshtein-distance/description.md new file mode 100644 index 0000000000..0882c3cf29 --- /dev/null +++ b/exercises/levenshtein-distance/description.md @@ -0,0 +1,8 @@ +Calculate the Levenshtein distance between two strings. + +Lets assume you have three single-character edits (insertion, deletion and +substitution). The Levenshtein distance is then described by the minimum number +of operations needed to convert one input string into another input string. + +For example the distance to get from "mine" to "times" would be 3 +(2 substitutions plus 1 insertion). diff --git a/exercises/levenshtein-distance/metadata.yml b/exercises/levenshtein-distance/metadata.yml new file mode 100644 index 0000000000..742b978edd --- /dev/null +++ b/exercises/levenshtein-distance/metadata.yml @@ -0,0 +1,4 @@ +--- +blurb: "Calculate the Levenshtein distance between two strings." +source: "Wikipedia" +source_url: "https://en.wikipedia.org/wiki/Levenshtein_distance" From f18d301984114d5c06630fae439bdf0247e8d83e Mon Sep 17 00:00:00 2001 From: n4bla Date: Sun, 2 Feb 2020 10:27:23 +0100 Subject: [PATCH 2/2] Refactoring of test cases with improved descriptions --- .../levenshtein-distance/canonical-data.json | 145 +++++++++++------- 1 file changed, 88 insertions(+), 57 deletions(-) diff --git a/exercises/levenshtein-distance/canonical-data.json b/exercises/levenshtein-distance/canonical-data.json index df60caf5c9..482419a4c9 100644 --- a/exercises/levenshtein-distance/canonical-data.json +++ b/exercises/levenshtein-distance/canonical-data.json @@ -3,63 +3,94 @@ "version": "1.0.0", "cases": [ { - "description": "Calculate Levenshtein distance", - "cases": [ - { - "description": "mine_to_times", - "property": "distance", - "input": { - "phrase": "mine", - "phrase": "times" - }, - "expected": "3" - }, - { - "description": "_to_abcd", - "property": "distance", - "input": { - "phrase": "", - "phrase": "abcd" - }, - "expected": "4" - }, - { - "description": "12345_to_", - "property": "distance", - "input": { - "phrase": "12345", - "phrase": "" - }, - "expected": "5" - }, - { - "description": "lifo_to_fifo", - "property": "distance", - "input": { - "phrase": "lifo", - "phrase": "fifo" - }, - "expected": "1" - }, - { - "description": "Hello-World!_to_hello-world", - "property": "distance", - "input": { - "phrase": "Hello World!", - "phrase": "hello world" - }, - "expected": "3" - }, - { - "description": "oxygenO2_to_carbondioxideCO2", - "property": "distance", - "input": { - "phrase": "oxygenO2", - "phrase": "carbondioxideCO2" - }, - "expected": "11" - } - ] + "description": "empty strings", + "property": "distance", + "input": { + "from": "", + "to": "" + }, + "expected": 0 + }, + { + "description": "identical strings", + "property": "distance", + "input": { + "from": "abcdefghij", + "to": "abcdefghij" + }, + "expected": 0 + }, + { + "description": "only insertions", + "property": "distance", + "input": { + "from": "", + "to": "abcd" + }, + "expected": 4 + }, + { + "description": "only deletions", + "property": "distance", + "input": { + "from": "abcd", + "to": "" + }, + "expected": 4 + }, + { + "description": "only substitution", + "property": "distance", + "input": { + "from": "lifo", + "to": "fifo" + }, + "expected": 1 + }, + { + "description": "substitution and insertion", + "property": "distance", + "input": { + "from": "mine", + "to": "times" + }, + "expected": 3 + }, + { + "description": "substitution and deletion", + "property": "distance", + "input": { + "from": "times", + "to": "mine" + }, + "expected": 3 + }, + { + "description": "with numbers", + "property": "distance", + "input": { + "from": "abc123", + "to": "abd2234" + }, + "expected": 3 + }, + { + "description": "with special characters", + "property": "distance", + "input": { + "from": "hello world!", + "to": "helloworld" + }, + "expected": 2 + }, + { + "description": "with capital letters", + "property": "distance", + "input": { + "from": "Oxygen O2", + "to": "Carbondioxide CO2" + }, + "expected": 13 } ] }