Browse Source

Added tests for task1

Lorenz Bung 7 years ago
parent
commit
6793e28a3a
2 changed files with 41 additions and 1 deletions
  1. 1
    1
      hw9/task1/src/lib.rs
  2. 40
    0
      hw9/task1/tests/task1.rs

+ 1
- 1
hw9/task1/src/lib.rs View File

@@ -22,7 +22,7 @@ pub fn parse(message: &str) -> Command {
22 22
     }
23 23
 }
24 24
 
25
-#[derive(Debug)]
25
+#[derive(Debug, PartialEq)]
26 26
 pub enum Command {
27 27
     Stage(String),
28 28
     Control(String),

+ 40
- 0
hw9/task1/tests/task1.rs View File

@@ -0,0 +1,40 @@
1
+#[cfg(test)]
2
+
3
+mod tests {
4
+
5
+    extern crate task1;
6
+
7
+    use self::task1::Command;
8
+    use self::task1::parse;
9
+
10
+    #[test]
11
+    fn empty_returns_correct_command() {
12
+        assert_eq!(parse("\n"), Command::EmptyError)
13
+    }
14
+
15
+    #[test]
16
+    fn not_known_command_returns_correct_command() {
17
+        assert_eq!(parse("Hello"), Command::NotFoundError)
18
+    }
19
+
20
+    #[test]
21
+    fn stage_returns_correct_command() {
22
+        assert_eq!(parse("STAGE Hello"), Command::Stage("Hello".to_string()))
23
+    }
24
+
25
+    #[test]
26
+    fn control_returns_correct_command() {
27
+        assert_eq!(parse("CONTROL Hello"), Command::Control("Hello".to_string()))
28
+    }
29
+
30
+    #[test]
31
+    fn retrieve_returns_correct_command() {
32
+        assert_eq!(parse("RETRIEVE"), Command::Retrieve)
33
+    }
34
+
35
+    #[test]
36
+    fn retrieve_with_arguments_returns_correct_command() {
37
+        assert_eq!(parse("RETRIEVE Hello"), Command::Retrieve)
38
+    }
39
+
40
+}

Loading…
Cancel
Save