minesweeper.t (3252B) - raw
1 #!/usr/bin/env perl 2 use Test2::V0; 3 use JSON::PP; 4 use constant JSON => JSON::PP->new; 5 6 use FindBin qw<$Bin>; 7 use lib $Bin, "$Bin/local/lib/perl5"; 8 9 use Minesweeper qw<annotate>; 10 11 my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; }; 12 13 imported_ok qw<annotate> or bail_out; 14 15 for my $case (@test_cases) { 16 is( annotate( $case->{input}{minefield} ), 17 $case->{expected}, $case->{description}, ); 18 } 19 20 done_testing; 21 22 __DATA__ 23 [ 24 { 25 "description": "no rows", 26 "expected": [], 27 "input": { 28 "minefield": [] 29 }, 30 "property": "annotate" 31 }, 32 { 33 "description": "no columns", 34 "expected": [ 35 "" 36 ], 37 "input": { 38 "minefield": [ 39 "" 40 ] 41 }, 42 "property": "annotate" 43 }, 44 { 45 "description": "no mines", 46 "expected": [ 47 " ", 48 " ", 49 " " 50 ], 51 "input": { 52 "minefield": [ 53 " ", 54 " ", 55 " " 56 ] 57 }, 58 "property": "annotate" 59 }, 60 { 61 "description": "minefield with only mines", 62 "expected": [ 63 "***", 64 "***", 65 "***" 66 ], 67 "input": { 68 "minefield": [ 69 "***", 70 "***", 71 "***" 72 ] 73 }, 74 "property": "annotate" 75 }, 76 { 77 "description": "mine surrounded by spaces", 78 "expected": [ 79 "111", 80 "1*1", 81 "111" 82 ], 83 "input": { 84 "minefield": [ 85 " ", 86 " * ", 87 " " 88 ] 89 }, 90 "property": "annotate" 91 }, 92 { 93 "description": "space surrounded by mines", 94 "expected": [ 95 "***", 96 "*8*", 97 "***" 98 ], 99 "input": { 100 "minefield": [ 101 "***", 102 "* *", 103 "***" 104 ] 105 }, 106 "property": "annotate" 107 }, 108 { 109 "description": "horizontal line", 110 "expected": [ 111 "1*2*1" 112 ], 113 "input": { 114 "minefield": [ 115 " * * " 116 ] 117 }, 118 "property": "annotate" 119 }, 120 { 121 "description": "horizontal line, mines at edges", 122 "expected": [ 123 "*1 1*" 124 ], 125 "input": { 126 "minefield": [ 127 "* *" 128 ] 129 }, 130 "property": "annotate" 131 }, 132 { 133 "description": "vertical line", 134 "expected": [ 135 "1", 136 "*", 137 "2", 138 "*", 139 "1" 140 ], 141 "input": { 142 "minefield": [ 143 " ", 144 "*", 145 " ", 146 "*", 147 " " 148 ] 149 }, 150 "property": "annotate" 151 }, 152 { 153 "description": "vertical line, mines at edges", 154 "expected": [ 155 "*", 156 "1", 157 " ", 158 "1", 159 "*" 160 ], 161 "input": { 162 "minefield": [ 163 "*", 164 " ", 165 " ", 166 " ", 167 "*" 168 ] 169 }, 170 "property": "annotate" 171 }, 172 { 173 "description": "cross", 174 "expected": [ 175 " 2*2 ", 176 "25*52", 177 "*****", 178 "25*52", 179 " 2*2 " 180 ], 181 "input": { 182 "minefield": [ 183 " * ", 184 " * ", 185 "*****", 186 " * ", 187 " * " 188 ] 189 }, 190 "property": "annotate" 191 }, 192 { 193 "description": "large minefield", 194 "expected": [ 195 "1*22*1", 196 "12*322", 197 " 123*2", 198 "112*4*", 199 "1*22*2", 200 "111111" 201 ], 202 "input": { 203 "minefield": [ 204 " * * ", 205 " * ", 206 " * ", 207 " * *", 208 " * * ", 209 " " 210 ] 211 }, 212 "property": "annotate" 213 } 214 ]