From 151e64d2964dbc5b88c4789b39f9b02737d7e1b7 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Fri, 9 Aug 2024 21:25:31 +0200 Subject: [PATCH] accumulate: sync --- .../practice/accumulate/.meta/tests.toml | 33 +++++++++++-- .../practice/accumulate/tests/accumulate.rs | 46 +++++++++++++++++-- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/exercises/practice/accumulate/.meta/tests.toml b/exercises/practice/accumulate/.meta/tests.toml index be690e975..d7858e07b 100644 --- a/exercises/practice/accumulate/.meta/tests.toml +++ b/exercises/practice/accumulate/.meta/tests.toml @@ -1,3 +1,30 @@ -# 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. + +[64d97c14-36dd-44a8-9621-2cecebd6ed23] +description = "accumulate empty" + +[00008ed2-4651-4929-8c08-8b4dbd70872e] +description = "accumulate squares" + +[551016da-4396-4cae-b0ec-4c3a1a264125] +description = "accumulate upcases" + +[cdf95597-b6ec-4eac-a838-3480d13d0d05] +description = "accumulate reversed strings" + +[bee8e9b6-b16f-4cd2-be3b-ccf7457e50bb] +description = "accumulate recursively" +include = false + +[0b357334-4cad-49e1-a741-425202edfc7c] +description = "accumulate recursively" +reimplements = "bee8e9b6-b16f-4cd2-be3b-ccf7457e50bb" diff --git a/exercises/practice/accumulate/tests/accumulate.rs b/exercises/practice/accumulate/tests/accumulate.rs index 0cfb6a184..501e6bace 100644 --- a/exercises/practice/accumulate/tests/accumulate.rs +++ b/exercises/practice/accumulate/tests/accumulate.rs @@ -5,6 +5,14 @@ fn square(x: i32) -> i32 { } #[test] +fn accumulate_empty() { + let input = vec![]; + let expected = vec![]; + assert_eq!(map(input, square), expected); +} + +#[test] +#[ignore] fn func_single() { let input = vec![2]; let expected = vec![4]; @@ -13,9 +21,9 @@ fn func_single() { #[test] #[ignore] -fn func_multi() { - let input = vec![2, 3, 4, 5]; - let expected = vec![4, 9, 16, 25]; +fn accumulate_squares() { + let input = vec![1, 2, 3]; + let expected = vec![1, 4, 9]; assert_eq!(map(input, square), expected); } @@ -43,6 +51,38 @@ fn strings() { assert_eq!(map(input, |s| s.repeat(2)), expected); } +#[test] +#[ignore] +fn accumulate_upcases() { + let input = vec!["Hello", "world"]; + let expected = vec!["HELLO", "WORLD"]; + assert_eq!(map(input, str::to_uppercase), expected); +} + +#[test] +#[ignore] +fn accumulate_reversed_strings() { + let input = vec!["the", "quick", "brown", "fox", "etc"]; + let expected = vec!["eht", "kciuq", "nworb", "xof", "cte"]; + let reverse = |s: &str| s.chars().rev().collect::(); + assert_eq!(map(input, reverse), expected); +} + +#[test] +#[ignore] +fn accumulate_recursively() { + let input = vec!["a", "b", "c"]; + let expected = vec![ + vec!["a1", "a2", "a3"], + vec!["b1", "b2", "b3"], + vec!["c1", "c2", "c3"], + ]; + assert_eq!( + map(input, |x| map(vec!["1", "2", "3"], |y| [x, y].join(""))), + expected + ); +} + #[test] #[ignore] fn change_in_type() {