Skip to content

Commit 3608134

Browse files
committed
feat: remove [] ending, cleanup code and add test cases
1 parent 97392c8 commit 3608134

14 files changed

Lines changed: 16 additions & 19 deletions

src/challenge/challenge_01.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ pub fn run(input: &str, output: Option<&str>) -> Result<String> {
1616
if let Some(output) = output.map(split_whitespace_and_parse::<u16>).transpose()? {
1717
anyhow::ensure!(
1818
result == output,
19-
"Output vector does not match expected: got '{:?}' expected '{:?}'",
20-
result,
21-
output
19+
"Output vector does not match expected: got '{result:?}' expected '{output:?}'",
2220
);
2321

2422
return Ok(format!(

src/challenge/challenge_03.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ pub fn run(input: &str, output: Option<&str>) -> Result<String> {
1313
let result = fair_bandwidth_allocation(users, total);
1414

1515
if let Some(output) = output {
16-
if output == "[]" {
16+
if output.is_empty() {
1717
anyhow::ensure!(
18-
users == 0 && result.is_empty(),
18+
result.is_empty(),
1919
"Output does not match expected for 0 users"
2020
);
2121
}
@@ -27,9 +27,7 @@ pub fn run(input: &str, output: Option<&str>) -> Result<String> {
2727
.iter()
2828
.zip(expected_output.iter())
2929
.all(|(a, b)| (a - b).abs() < 1e-6),
30-
"Output vector does not match expected: got '{:?}' expected '{:?}'",
31-
result,
32-
expected_output
30+
"Output vector does not match expected: got '{result:?}' expected '{expected_output:?}'"
3331
);
3432

3533
return Ok(format!(
@@ -38,18 +36,9 @@ pub fn run(input: &str, output: Option<&str>) -> Result<String> {
3836
));
3937
}
4038

41-
let result_str = if result.is_empty() {
42-
"[]"
43-
} else {
44-
&result
45-
.iter()
46-
.map(|&b| format!("{b:.6}"))
47-
.collect::<Vec<String>>()
48-
.join(" ")
49-
};
50-
5139
Ok(format!(
52-
"Calculated allocations: {result_str}, but {} output!",
40+
"Calculated allocations: {}, but {} output!",
41+
&result.preview(15),
5342
"missing".red().bold()
5443
))
5544
}

testcases/03/01_input.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10 5.0

testcases/03/01_output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000

testcases/03/02_input.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10 0.5

testcases/03/02_output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.100000 0.100000 0.100000 0.100000 0.100000

testcases/03/03_input.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5 0.5

testcases/03/03_output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.100000 0.100000 0.100000 0.100000 0.100000

testcases/03/04_input.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 100

testcases/03/04_output.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)