nurikabe / nurikabe-solver / Games-Nurikabe-Solver / t / solve-refactor.t

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88``` ```#!/usr/bin/perl use strict; use warnings; use Test::More tests => 7; use Test::Differences; use Games::Nurikabe::Solver::Cell; use Games::Nurikabe::Solver::Constants qw(\$NK_UNKNOWN \$NK_WHITE \$NK_BLACK); use Games::Nurikabe::Solver::Board; use List::MoreUtils qw(any); sub verdict_cells { my (\$m, \$verdict) = @_; return [map { \$_->to_aref() } @{\$m->get_verdict_cells(\$verdict)} ]; } { my \$string_representation = <<"EOF"; Width=2 Height=2 [1] [] [] [] EOF my \$board = Games::Nurikabe::Solver::Board->load_from_string( \$string_representation ); { my \$moves = \$board->_solve_using( { name => "surround_island", params => {}, } ); # TEST is (scalar(@\$moves), 1, "There is 1 move"); my \$m = \$moves->[0]; # TEST is (\$m->reason(), "surround_island_when_full", "reason is OK."); # TEST eq_or_diff( verdict_cells(\$m, \$NK_BLACK), [[0,1],[1,0]], "Verdicted cells is OK.", ); # TEST is (\$m->reason_param("island"), 0, "The island is 0 in the reason parameter", ); } { my \$moves = \$board->_solve_using( { name => "surrounded_by_blacks", params => {}, } ); # TEST is (scalar(@\$moves), 1, "There is 1 move"); my \$m = \$moves->[0]; # TEST is (\$m->reason(), "surrounded_by_blacks", "reason is OK."); # TEST eq_or_diff( verdict_cells(\$m, \$NK_BLACK), [[1,1]], "Verdicted cells is OK.", ); } } ```