Browse Source

Added unimplemented methods in task5 and ran the tests

Lorenz Bung 8 years ago
parent
commit
974e66965d
2 changed files with 17 additions and 3 deletions
  1. 6
    0
      hw1/task4/Cargo.toml
  2. 11
    3
      hw1/task4/src/lib.rs

+ 6
- 0
hw1/task4/Cargo.toml View File

1
+[package]
2
+name = "task4"
3
+version = "0.1.0"
4
+authors = ["Lorenz Bung <lorenz.bung@googlemail.com>"]
5
+
6
+[dependencies]

+ 11
- 3
hw1/task4/src/lib.rs View File

1
 pub fn square_of_sum(n: i32) -> i32 {
1
 pub fn square_of_sum(n: i32) -> i32 {
2
-    unimplemented!();
2
+    let mut i: i32 = 0;
3
+    for x in 1..n+1 {
4
+        i += x;
5
+    }
6
+    i.pow(2)
3
 }
7
 }
4
 
8
 
5
 pub fn sum_of_squares(n: i32) -> i32 {
9
 pub fn sum_of_squares(n: i32) -> i32 {
6
-    unimplemented!();
10
+    let mut i: i32 = 0;
11
+    for x in 1..n+1 {
12
+       i += x.pow(2); 
13
+    }
14
+    i
7
 }
15
 }
8
 
16
 
9
 pub fn difference(n: i32) -> i32 {
17
 pub fn difference(n: i32) -> i32 {
10
-    unimplemented!();
18
+    square_of_sum(n) - sum_of_squares(n)
11
 }
19
 }

Loading…
Cancel
Save