From cecbe3a9d0f6720fc39da67959b27384fa6d9de4 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Fri, 16 Aug 2024 07:46:36 +0200 Subject: [PATCH] hamming: sync part of https://github.com/exercism/rust/issues/1824 --- .../practice/hamming/.meta/test_template.tera | 16 +++++ exercises/practice/hamming/.meta/tests.toml | 70 ++++++++++++++++++- exercises/practice/hamming/tests/hamming.rs | 65 ++++------------- 3 files changed, 98 insertions(+), 53 deletions(-) create mode 100644 exercises/practice/hamming/.meta/test_template.tera diff --git a/exercises/practice/hamming/.meta/test_template.tera b/exercises/practice/hamming/.meta/test_template.tera new file mode 100644 index 000000000..3bb6cc252 --- /dev/null +++ b/exercises/practice/hamming/.meta/test_template.tera @@ -0,0 +1,16 @@ +use hamming::*; + +{% for test in cases %} +#[test] +#[ignore] +fn {{ test.description | make_ident }}() { + assert_eq!( + hamming_distance({{ test.input.strand1 | json_encode() }}, {{ test.input.strand2 | json_encode() }}), + {% if test.expected is object -%} + None + {% else -%} + Some({{ test.expected }}) + {% endif -%} + ); +} +{% endfor -%} diff --git a/exercises/practice/hamming/.meta/tests.toml b/exercises/practice/hamming/.meta/tests.toml index be690e975..5dc17ed4e 100644 --- a/exercises/practice/hamming/.meta/tests.toml +++ b/exercises/practice/hamming/.meta/tests.toml @@ -1,3 +1,67 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[f6dcb64f-03b0-4b60-81b1-3c9dbf47e887] +description = "empty strands" + +[54681314-eee2-439a-9db0-b0636c656156] +description = "single letter identical strands" + +[294479a3-a4c8-478f-8d63-6209815a827b] +description = "single letter different strands" + +[9aed5f34-5693-4344-9b31-40c692fb5592] +description = "long identical strands" + +[cd2273a5-c576-46c8-a52b-dee251c3e6e5] +description = "long different strands" + +[919f8ef0-b767-4d1b-8516-6379d07fcb28] +description = "disallow first strand longer" +include = false + +[b9228bb1-465f-4141-b40f-1f99812de5a8] +description = "disallow first strand longer" +reimplements = "919f8ef0-b767-4d1b-8516-6379d07fcb28" + +[8a2d4ed0-ead5-4fdd-924d-27c4cf56e60e] +description = "disallow second strand longer" +include = false + +[dab38838-26bb-4fff-acbe-3b0a9bfeba2d] +description = "disallow second strand longer" +reimplements = "8a2d4ed0-ead5-4fdd-924d-27c4cf56e60e" + +[5dce058b-28d4-4ca7-aa64-adfe4e17784c] +description = "disallow left empty strand" +include = false + +[db92e77e-7c72-499d-8fe6-9354d2bfd504] +description = "disallow left empty strand" +include = false +reimplements = "5dce058b-28d4-4ca7-aa64-adfe4e17784c" + +[b764d47c-83ff-4de2-ab10-6cfe4b15c0f3] +description = "disallow empty first strand" +reimplements = "db92e77e-7c72-499d-8fe6-9354d2bfd504" + +[38826d4b-16fb-4639-ac3e-ba027dec8b5f] +description = "disallow right empty strand" +include = false + +[920cd6e3-18f4-4143-b6b8-74270bb8f8a3] +description = "disallow right empty strand" +include = false +reimplements = "38826d4b-16fb-4639-ac3e-ba027dec8b5f" + +[9ab9262f-3521-4191-81f5-0ed184a5aa89] +description = "disallow empty second strand" +reimplements = "920cd6e3-18f4-4143-b6b8-74270bb8f8a3" diff --git a/exercises/practice/hamming/tests/hamming.rs b/exercises/practice/hamming/tests/hamming.rs index bcccb8311..b5fb7b437 100644 --- a/exercises/practice/hamming/tests/hamming.rs +++ b/exercises/practice/hamming/tests/hamming.rs @@ -1,89 +1,54 @@ -fn process_distance_case(strand_pair: [&str; 2], expected_distance: Option) { - assert_eq!( - hamming::hamming_distance(strand_pair[0], strand_pair[1]), - expected_distance - ); -} +use hamming::*; #[test] fn empty_strands() { - process_distance_case(["", ""], Some(0)); -} - -#[test] -#[ignore] -/// disallow first strand longer -fn disallow_first_strand_longer() { - process_distance_case(["AATG", "AAA"], None); + assert_eq!(hamming_distance("", ""), Some(0)); } #[test] #[ignore] -/// disallow second strand longer -fn disallow_second_strand_longer() { - process_distance_case(["ATA", "AGTG"], None); -} - -#[test] -#[ignore] -fn first_string_is_longer() { - process_distance_case(["AAA", "AA"], None); -} - -#[test] -#[ignore] -fn second_string_is_longer() { - process_distance_case(["A", "AA"], None); -} - -#[test] -#[ignore] -/// single letter identical strands fn single_letter_identical_strands() { - process_distance_case(["A", "A"], Some(0)); + assert_eq!(hamming_distance("A", "A"), Some(0)); } #[test] #[ignore] -/// small distance fn single_letter_different_strands() { - process_distance_case(["G", "T"], Some(1)); + assert_eq!(hamming_distance("G", "T"), Some(1)); } #[test] #[ignore] -/// long identical strands fn long_identical_strands() { - process_distance_case(["GGACTGAAATCTG", "GGACTGAAATCTG"], Some(0)); + assert_eq!(hamming_distance("GGACTGAAATCTG", "GGACTGAAATCTG"), Some(0)); } #[test] #[ignore] -fn no_difference_between_identical_strands() { - process_distance_case(["GGACTGA", "GGACTGA"], Some(0)); +fn long_different_strands() { + assert_eq!(hamming_distance("GGACGGATTCTG", "AGGACGGATTCT"), Some(9)); } #[test] #[ignore] -fn complete_hamming_distance_in_small_strand() { - process_distance_case(["ACT", "GGA"], Some(3)); +fn disallow_first_strand_longer() { + assert_eq!(hamming_distance("AATG", "AAA"), None); } #[test] #[ignore] -fn small_hamming_distance_in_the_middle_somewhere() { - process_distance_case(["GGACG", "GGTCG"], Some(1)); +fn disallow_second_strand_longer() { + assert_eq!(hamming_distance("ATA", "AGTG"), None); } #[test] #[ignore] -fn larger_distance() { - process_distance_case(["ACCAGGG", "ACTATGG"], Some(2)); +fn disallow_empty_first_strand() { + assert_eq!(hamming_distance("", "G"), None); } #[test] #[ignore] -/// large distance in off-by-one strand -fn long_different_strands() { - process_distance_case(["GGACGGATTCTG", "AGGACGGATTCT"], Some(9)); +fn disallow_empty_second_strand() { + assert_eq!(hamming_distance("G", ""), None); }