Michael Mächtel 8 anos atrás
pai
commit
16f10b780a
2 arquivos alterados com 64 adições e 0 exclusões
  1. 25
    0
      hw2/task3/README.md
  2. 39
    0
      hw2/task3/tests/task3.rs

+ 25
- 0
hw2/task3/README.md Ver arquivo

@@ -0,0 +1,25 @@
1
+# Homework hw2 task3
2
+
3
+## prepare your task
4
+
5
+Run the cargo command to prepare your task3/ directory as a library
6
+
7
+## task
8
+
9
+Compute Pascal's triangle up to a given number of rows. Create the new type *PascalsTriangle* and implement the methods *new()* and *rows()*. See the `tests/task3.rs` for more informationen about parameters and returns of the methods.
10
+
11
+In Pascal's Triangle each number is computed by adding the numbers to
12
+the right and left of the current position in the previous row.
13
+
14
+```plain
15
+    1
16
+   1 1
17
+  1 2 1
18
+ 1 3 3 1
19
+1 4 6 4 1
20
+# ... etc
21
+```
22
+
23
+
24
+
25
+

+ 39
- 0
hw2/task3/tests/task3.rs Ver arquivo

@@ -0,0 +1,39 @@
1
+extern crate task3;
2
+
3
+use task3::*;
4
+
5
+#[test]
6
+fn no_rows() {
7
+    let pt = PascalsTriangle::new(0);
8
+    let expected: Vec<Vec<u32>> = Vec::new();
9
+    assert_eq!(expected, pt.rows());
10
+}
11
+
12
+
13
+#[test]
14
+fn one_row() {
15
+    let pt = PascalsTriangle::new(1);
16
+    let expected: Vec<Vec<u32>> = vec![vec![1]];
17
+    assert_eq!(expected, pt.rows());
18
+}
19
+
20
+#[test]
21
+fn two_rows() {
22
+    let pt = PascalsTriangle::new(2);
23
+    let expected: Vec<Vec<u32>> = vec![vec![1], vec![1, 1]];
24
+    assert_eq!(expected, pt.rows());
25
+}
26
+
27
+#[test]
28
+fn three_rows() {
29
+    let pt = PascalsTriangle::new(3);
30
+    let expected: Vec<Vec<u32>> = vec![vec![1], vec![1, 1], vec![1, 2, 1]];
31
+    assert_eq!(expected, pt.rows());
32
+}
33
+
34
+#[test]
35
+fn last_of_four_rows() {
36
+    let pt = PascalsTriangle::new(4);
37
+    let expected: Vec<u32> = vec![1, 3, 3, 1];
38
+    assert_eq!(expected, pt.rows().pop().unwrap());
39
+}

Carregando…
Cancelar
Salvar