|
1 |
| -use std::fs::File; |
2 |
| -use std::path::Path; |
3 |
| -use std::io::Read; |
4 |
| - |
5 | 1 | extern crate tournament;
|
6 | 2 |
|
7 |
| -fn file_equal(output_file: &str, expected_file: &str) { |
8 |
| - let output = match File::open(&Path::new(output_file)) { |
9 |
| - Err(e) => panic!("Couldn't open {}: {}", output_file, e), |
10 |
| - Ok(mut f) => { |
11 |
| - let mut buf = String::new(); |
12 |
| - match f.read_to_string(&mut buf) { |
13 |
| - Err(e) => panic!("Couldn't read {}: {}", output_file, e), |
14 |
| - Ok(_) => buf |
15 |
| - } |
16 |
| - } |
17 |
| - }; |
18 |
| - let expected = match File::open(&Path::new(expected_file)) { |
19 |
| - Err(e) => panic!("Couldn't open {}: {}", expected_file, e), |
20 |
| - Ok(mut f) => { |
21 |
| - let mut buf = String::new(); |
22 |
| - match f.read_to_string(&mut buf) { |
23 |
| - Err(e) => panic!("Couldn't read {}: {}", expected_file, e), |
24 |
| - Ok(_) => buf |
25 |
| - } |
26 |
| - } |
27 |
| - }; |
28 |
| - assert_eq!("\n".to_string() + output.as_ref(), "\n".to_string() + expected.as_ref()); |
29 |
| - |
30 |
| -} |
31 |
| - |
32 |
| - |
33 | 3 | #[test]
|
34 | 4 | fn test_good() {
|
35 |
| - assert_eq!(tournament::tally(&Path::new("tests/input1.txt"), &Path::new("tests/output1.txt")).unwrap(), 6); |
36 |
| - file_equal("tests/output1.txt", "tests/expected1.txt"); |
| 5 | + let input = "Allegoric Alaskians;Blithering Badgers;win\n".to_string() + |
| 6 | + "Devastating Donkeys;Courageous Californians;draw\n" + |
| 7 | + "Devastating Donkeys;Allegoric Alaskians;win\n" + |
| 8 | + "Courageous Californians;Blithering Badgers;loss\n" + |
| 9 | + "Blithering Badgers;Devastating Donkeys;loss\n" + |
| 10 | + "Allegoric Alaskians;Courageous Californians;win"; |
| 11 | + let expected = "Team | MP | W | D | L | P\n".to_string() + |
| 12 | + "Devastating Donkeys | 3 | 2 | 1 | 0 | 7\n" + |
| 13 | + "Allegoric Alaskians | 3 | 2 | 0 | 1 | 6\n" + |
| 14 | + "Blithering Badgers | 3 | 1 | 0 | 2 | 3\n" + |
| 15 | + "Courageous Californians | 3 | 0 | 1 | 2 | 1"; |
| 16 | + |
| 17 | + assert_eq!(tournament::tally(&input), expected); |
37 | 18 | }
|
38 | 19 |
|
39 | 20 | #[test]
|
40 | 21 | #[ignore]
|
41 | 22 | fn test_ignore_bad_lines() {
|
42 |
| - assert_eq!(tournament::tally(&Path::new("tests/input2.txt"), &Path::new("tests/output2.txt")).unwrap(), 6); |
43 |
| - file_equal("tests/output2.txt", "tests/expected2.txt"); |
| 23 | + let input = "Allegoric Alaskians;Blithering Badgers;win\n".to_string() + |
| 24 | + "Devastating Donkeys_Courageous Californians;draw\n" + |
| 25 | + "Devastating Donkeys;Allegoric Alaskians;win\n" + |
| 26 | + "\n" + |
| 27 | + "Courageous Californians;Blithering Badgers;loss\n" + |
| 28 | + "Bla;Bla;Bla\n" + |
| 29 | + "Blithering Badgers;Devastating Donkeys;loss\n" + |
| 30 | + "# Yackity yackity yack\n" + |
| 31 | + "Allegoric Alaskians;Courageous Californians;win\n" + |
| 32 | + "Devastating Donkeys;Courageous Californians;draw\n" + |
| 33 | + "Devastating Donkeys@Courageous Californians;draw"; |
| 34 | + let expected = "Team | MP | W | D | L | P\n".to_string() + |
| 35 | + "Devastating Donkeys | 3 | 2 | 1 | 0 | 7\n" + |
| 36 | + "Allegoric Alaskians | 3 | 2 | 0 | 1 | 6\n" + |
| 37 | + "Blithering Badgers | 3 | 1 | 0 | 2 | 3\n" + |
| 38 | + "Courageous Californians | 3 | 0 | 1 | 2 | 1"; |
| 39 | + |
| 40 | + assert_eq!(tournament::tally(&input), expected); |
44 | 41 | }
|
45 | 42 |
|
46 | 43 | #[test]
|
47 | 44 | #[ignore]
|
48 | 45 | fn test_incomplete_competition() {
|
49 |
| - assert_eq!(tournament::tally(&Path::new("tests/input3.txt"), &Path::new("tests/output3.txt")).unwrap(), 4); |
50 |
| - file_equal("tests/output3.txt", "tests/expected3.txt"); |
| 46 | + let input = "Allegoric Alaskians;Blithering Badgers;win\n".to_string() + |
| 47 | + "Devastating Donkeys;Allegoric Alaskians;win\n" + |
| 48 | + "Courageous Californians;Blithering Badgers;loss\n" + |
| 49 | + "Allegoric Alaskians;Courageous Californians;win"; |
| 50 | + let expected = "Team | MP | W | D | L | P\n".to_string() + |
| 51 | + "Allegoric Alaskians | 3 | 2 | 0 | 1 | 6\n" + |
| 52 | + "Blithering Badgers | 2 | 1 | 0 | 1 | 3\n" + |
| 53 | + "Devastating Donkeys | 1 | 1 | 0 | 0 | 3\n" + |
| 54 | + "Courageous Californians | 2 | 0 | 0 | 2 | 0"; |
| 55 | + |
| 56 | + assert_eq!(tournament::tally(&input), expected); |
51 | 57 | }
|
0 commit comments