Skip to content

Commit

Permalink
accumulate: sync
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed Aug 9, 2024
1 parent 2a66d7d commit 151e64d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 6 deletions.
33 changes: 30 additions & 3 deletions exercises/practice/accumulate/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
46 changes: 43 additions & 3 deletions exercises/practice/accumulate/tests/accumulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
}

Expand Down Expand Up @@ -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::<String>();
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() {
Expand Down

0 comments on commit 151e64d

Please sign in to comment.