Skip to content

Commit e31b5ba

Browse files
authored
Make expectation in compare_board_and_check_no_solution_case more flexible (#183)
1 parent d981c59 commit e31b5ba

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

cspuz_solver_backend/src/puzzle/fillomino.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ pub fn solve(url: &str) -> Result<Board, &'static str> {
101101
mod tests {
102102
use super::solve;
103103
use crate::board::*;
104-
use crate::compare_board;
104+
use crate::compare_board_and_check_no_solution_case;
105105
use crate::uniqueness::Uniqueness;
106106

107107
#[test]
108108
#[rustfmt::skip]
109109
fn test_solve() {
110-
compare_board!(
110+
compare_board_and_check_no_solution_case!(
111111
solve("https://puzz.link/p?fillomino/5/5/g1k34g2h5h4n"),
112112
Board {
113113
kind: BoardKind::OuterGrid,

cspuz_solver_backend/src/testing.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ macro_rules! compare_board_and_check_no_solution_case {
5757
}
5858
let actual = actual.unwrap();
5959
let expected_no_solution = $crate::testing::expectation_no_solution(&$expected);
60-
assert_eq!(actual, expected_no_solution);
60+
if actual != expected_no_solution {
61+
let expected_no_solution_wall_color_changed =
62+
$crate::testing::expectation_no_solution_wall_color_changed(&$expected);
63+
assert_eq!(actual, expected_no_solution_wall_color_changed);
64+
}
6165
};
6266
}
6367

@@ -174,6 +178,30 @@ pub fn expectation_no_solution(board: &Board) -> Board {
174178
}
175179
}
176180

181+
pub fn expectation_no_solution_wall_color_changed(board: &Board) -> Board {
182+
let mut new_data = vec![];
183+
for item in &board.data {
184+
if item.color != "green" {
185+
new_data.push(item.clone());
186+
} else {
187+
if item.kind == ItemKind::BoldWall {
188+
let mut new_item = item.clone();
189+
new_item.kind = ItemKind::Wall;
190+
new_item.color = "#cccccc";
191+
new_data.push(new_item);
192+
}
193+
}
194+
}
195+
196+
Board {
197+
kind: board.kind,
198+
height: board.height,
199+
width: board.width,
200+
data: new_data,
201+
uniqueness: Uniqueness::NoAnswer,
202+
}
203+
}
204+
177205
fn add_indent(s: &str, indent: &str) -> String {
178206
s.lines()
179207
.map(|line| format!("{}{}", indent, line))

0 commit comments

Comments
 (0)