Skip to content

Commit 3c3d103

Browse files
committed
Sync pascals-triangle with problem-specifications
1 parent 3c6e571 commit 3c3d103

5 files changed

Lines changed: 49 additions & 36 deletions

File tree

exercises/practice/pascals-triangle/.docs/instructions.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
Compute Pascal's triangle up to a given number of rows.
44

5-
In Pascal's Triangle each number is computed by adding the numbers to
6-
the right and left of the current position in the previous row.
5+
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.
76

87
```text
98
1

exercises/practice/pascals-triangle/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
},
3232
"blurb": "Compute Pascal's triangle up to a given number of rows.",
3333
"source": "Pascal's Triangle at Wolfram Math World",
34-
"source_url": "http://mathworld.wolfram.com/PascalsTriangle.html"
34+
"source_url": "https://www.wolframalpha.com/input/?i=Pascal%27s+triangle"
3535
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use pascals_triangle::PascalsTriangle;
2+
{% for test in cases %}
3+
#[test]
4+
{% if loop.index != 1 -%}
5+
#[ignore]
6+
{% endif -%}
7+
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
8+
let pt = PascalsTriangle::new({{ test.input.count }});
9+
let expected: Vec<Vec<u32>> = vec![{% for row in test.expected -%}
10+
vec!{{ row | json_encode() }},
11+
{%- endfor %}];
12+
assert_eq!(pt.rows(), expected);
13+
}
14+
{% endfor -%}

exercises/practice/pascals-triangle/.meta/tests.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[9920ce55-9629-46d5-85d6-4201f4a4234d]
13+
description = "zero rows"
14+
15+
[70d643ce-a46d-4e93-af58-12d88dd01f21]
16+
description = "single row"
417

518
[a6e5a2a2-fc9a-4b47-9f4f-ed9ad9fbe4bd]
619
description = "two rows"
720

821
[97206a99-79ba-4b04-b1c5-3c0fa1e16925]
922
description = "three rows"
1023

24+
[565a0431-c797-417c-a2c8-2935e01ce306]
25+
description = "four rows"
26+
1127
[06f9ea50-9f51-4eb2-b9a9-c00975686c27]
1228
description = "five rows"
1329

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
use pascals_triangle::*;
1+
use pascals_triangle::PascalsTriangle;
22

33
#[test]
4-
fn no_rows() {
4+
fn zero_rows() {
55
let pt = PascalsTriangle::new(0);
6-
let expected: Vec<Vec<u32>> = Vec::new();
7-
assert_eq!(expected, pt.rows());
6+
let expected: Vec<Vec<u32>> = vec![];
7+
assert_eq!(pt.rows(), expected);
88
}
99

1010
#[test]
1111
#[ignore]
12-
fn one_row() {
12+
fn single_row() {
1313
let pt = PascalsTriangle::new(1);
1414
let expected: Vec<Vec<u32>> = vec![vec![1]];
15-
assert_eq!(expected, pt.rows());
15+
assert_eq!(pt.rows(), expected);
1616
}
1717

1818
#[test]
1919
#[ignore]
2020
fn two_rows() {
2121
let pt = PascalsTriangle::new(2);
2222
let expected: Vec<Vec<u32>> = vec![vec![1], vec![1, 1]];
23-
assert_eq!(expected, pt.rows());
23+
assert_eq!(pt.rows(), expected);
2424
}
2525

2626
#[test]
2727
#[ignore]
2828
fn three_rows() {
2929
let pt = PascalsTriangle::new(3);
3030
let expected: Vec<Vec<u32>> = vec![vec![1], vec![1, 1], vec![1, 2, 1]];
31-
assert_eq!(expected, pt.rows());
31+
assert_eq!(pt.rows(), expected);
3232
}
3333

3434
#[test]
3535
#[ignore]
36-
fn last_of_four_rows() {
36+
fn four_rows() {
3737
let pt = PascalsTriangle::new(4);
38-
let expected: Vec<u32> = vec![1, 3, 3, 1];
39-
assert_eq!(Some(expected), pt.rows().pop());
38+
let expected: Vec<Vec<u32>> = vec![vec![1], vec![1, 1], vec![1, 2, 1], vec![1, 3, 3, 1]];
39+
assert_eq!(pt.rows(), expected);
4040
}
4141

4242
#[test]
@@ -50,7 +50,7 @@ fn five_rows() {
5050
vec![1, 3, 3, 1],
5151
vec![1, 4, 6, 4, 1],
5252
];
53-
assert_eq!(expected, pt.rows());
53+
assert_eq!(pt.rows(), expected);
5454
}
5555

5656
#[test]
@@ -65,23 +65,7 @@ fn six_rows() {
6565
vec![1, 4, 6, 4, 1],
6666
vec![1, 5, 10, 10, 5, 1],
6767
];
68-
assert_eq!(expected, pt.rows());
69-
}
70-
71-
#[test]
72-
#[ignore]
73-
fn seven_rows() {
74-
let pt = PascalsTriangle::new(7);
75-
let expected: Vec<Vec<u32>> = vec![
76-
vec![1],
77-
vec![1, 1],
78-
vec![1, 2, 1],
79-
vec![1, 3, 3, 1],
80-
vec![1, 4, 6, 4, 1],
81-
vec![1, 5, 10, 10, 5, 1],
82-
vec![1, 6, 15, 20, 15, 6, 1],
83-
];
84-
assert_eq!(expected, pt.rows());
68+
assert_eq!(pt.rows(), expected);
8569
}
8670

8771
#[test]
@@ -100,5 +84,5 @@ fn ten_rows() {
10084
vec![1, 8, 28, 56, 70, 56, 28, 8, 1],
10185
vec![1, 9, 36, 84, 126, 126, 84, 36, 9, 1],
10286
];
103-
assert_eq!(expected, pt.rows());
87+
assert_eq!(pt.rows(), expected);
10488
}

0 commit comments

Comments
 (0)