diff --git a/exercises/practice/pascals-triangle/.docs/instructions.md b/exercises/practice/pascals-triangle/.docs/instructions.md index 7109334fb..f55678593 100644 --- a/exercises/practice/pascals-triangle/.docs/instructions.md +++ b/exercises/practice/pascals-triangle/.docs/instructions.md @@ -2,8 +2,7 @@ Compute Pascal's triangle up to a given number of rows. -In Pascal's Triangle each number is computed by adding the numbers to -the right and left of the current position in the previous row. +In Pascal's Triangle each number is computed by adding the numbers to the right and left of the current position in the previous row. ```text 1 diff --git a/exercises/practice/pascals-triangle/.meta/config.json b/exercises/practice/pascals-triangle/.meta/config.json index f8d75e1de..750d670aa 100644 --- a/exercises/practice/pascals-triangle/.meta/config.json +++ b/exercises/practice/pascals-triangle/.meta/config.json @@ -31,5 +31,5 @@ }, "blurb": "Compute Pascal's triangle up to a given number of rows.", "source": "Pascal's Triangle at Wolfram Math World", - "source_url": "http://mathworld.wolfram.com/PascalsTriangle.html" + "source_url": "https://www.wolframalpha.com/input/?i=Pascal%27s+triangle" } diff --git a/exercises/practice/pascals-triangle/.meta/test_template.tera b/exercises/practice/pascals-triangle/.meta/test_template.tera new file mode 100644 index 000000000..6ef434fa6 --- /dev/null +++ b/exercises/practice/pascals-triangle/.meta/test_template.tera @@ -0,0 +1,14 @@ +use pascals_triangle::PascalsTriangle; +{% for test in cases %} +#[test] +{% if loop.index != 1 -%} +#[ignore] +{% endif -%} +fn {{ test.description | slugify | replace(from="-", to="_") }}() { + let pt = PascalsTriangle::new({{ test.input.count }}); + let expected: Vec> = vec![{% for row in test.expected -%} + vec!{{ row | json_encode() }}, + {%- endfor %}]; + assert_eq!(pt.rows(), expected); +} +{% endfor -%} diff --git a/exercises/practice/pascals-triangle/.meta/tests.toml b/exercises/practice/pascals-triangle/.meta/tests.toml index b0c8be28c..2db0ee523 100644 --- a/exercises/practice/pascals-triangle/.meta/tests.toml +++ b/exercises/practice/pascals-triangle/.meta/tests.toml @@ -1,6 +1,19 @@ -# 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. + +[9920ce55-9629-46d5-85d6-4201f4a4234d] +description = "zero rows" + +[70d643ce-a46d-4e93-af58-12d88dd01f21] +description = "single row" [a6e5a2a2-fc9a-4b47-9f4f-ed9ad9fbe4bd] description = "two rows" @@ -8,6 +21,9 @@ description = "two rows" [97206a99-79ba-4b04-b1c5-3c0fa1e16925] description = "three rows" +[565a0431-c797-417c-a2c8-2935e01ce306] +description = "four rows" + [06f9ea50-9f51-4eb2-b9a9-c00975686c27] description = "five rows" diff --git a/exercises/practice/pascals-triangle/tests/pascals-triangle.rs b/exercises/practice/pascals-triangle/tests/pascals-triangle.rs index fe2042bdc..24ba514fe 100644 --- a/exercises/practice/pascals-triangle/tests/pascals-triangle.rs +++ b/exercises/practice/pascals-triangle/tests/pascals-triangle.rs @@ -1,18 +1,18 @@ -use pascals_triangle::*; +use pascals_triangle::PascalsTriangle; #[test] -fn no_rows() { +fn zero_rows() { let pt = PascalsTriangle::new(0); - let expected: Vec> = Vec::new(); - assert_eq!(expected, pt.rows()); + let expected: Vec> = vec![]; + assert_eq!(pt.rows(), expected); } #[test] #[ignore] -fn one_row() { +fn single_row() { let pt = PascalsTriangle::new(1); let expected: Vec> = vec![vec![1]]; - assert_eq!(expected, pt.rows()); + assert_eq!(pt.rows(), expected); } #[test] @@ -20,7 +20,7 @@ fn one_row() { fn two_rows() { let pt = PascalsTriangle::new(2); let expected: Vec> = vec![vec![1], vec![1, 1]]; - assert_eq!(expected, pt.rows()); + assert_eq!(pt.rows(), expected); } #[test] @@ -28,15 +28,15 @@ fn two_rows() { fn three_rows() { let pt = PascalsTriangle::new(3); let expected: Vec> = vec![vec![1], vec![1, 1], vec![1, 2, 1]]; - assert_eq!(expected, pt.rows()); + assert_eq!(pt.rows(), expected); } #[test] #[ignore] -fn last_of_four_rows() { +fn four_rows() { let pt = PascalsTriangle::new(4); - let expected: Vec = vec![1, 3, 3, 1]; - assert_eq!(Some(expected), pt.rows().pop()); + let expected: Vec> = vec![vec![1], vec![1, 1], vec![1, 2, 1], vec![1, 3, 3, 1]]; + assert_eq!(pt.rows(), expected); } #[test] @@ -50,7 +50,7 @@ fn five_rows() { vec![1, 3, 3, 1], vec![1, 4, 6, 4, 1], ]; - assert_eq!(expected, pt.rows()); + assert_eq!(pt.rows(), expected); } #[test] @@ -65,23 +65,7 @@ fn six_rows() { vec![1, 4, 6, 4, 1], vec![1, 5, 10, 10, 5, 1], ]; - assert_eq!(expected, pt.rows()); -} - -#[test] -#[ignore] -fn seven_rows() { - let pt = PascalsTriangle::new(7); - let expected: Vec> = vec![ - vec![1], - vec![1, 1], - vec![1, 2, 1], - vec![1, 3, 3, 1], - vec![1, 4, 6, 4, 1], - vec![1, 5, 10, 10, 5, 1], - vec![1, 6, 15, 20, 15, 6, 1], - ]; - assert_eq!(expected, pt.rows()); + assert_eq!(pt.rows(), expected); } #[test] @@ -100,5 +84,5 @@ fn ten_rows() { vec![1, 8, 28, 56, 70, 56, 28, 8, 1], vec![1, 9, 36, 84, 126, 126, 84, 36, 9, 1], ]; - assert_eq!(expected, pt.rows()); + assert_eq!(pt.rows(), expected); }