Commits

Anonymous committed 83abd8a

Add the system test (after correcting the .abc-path.sol output.).

  • Participants
  • Parent commits 70ce436

Comments (0)

Files changed (9)

File abc-path/Games-ABC_Path-Solver/Build.PL

     add_to_cleanup      => [ 'Games-Solitaire-Verify-*' ],
     create_makefile_pl => 'traditional',
     script_files => [
-        # "script/abc-path-solve",
+        "scripts/abc-path-solve",
     ],
     meta_merge =>
     {

File abc-path/Games-ABC_Path-Solver/MANIFEST

 Makefile.PL
 MANIFEST
 README
+scripts/abc-path-solve
 t/00-load.t
+t/layouts/brain-bashers.2010-12-21.abc-path
+t/layouts/brain-bashers.2010-12-22.abc-path
 t/pod-coverage.t
 t/pod.t
+t/results/brain-bashers.2010-12-21.abc-path-sol
+t/results/brain-bashers.2010-12-22.abc-path-sol
+t/solver-output-system-test.t
+META.yml

File abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Board.pm

 {
     my ($self) = @_;
 
-    require Text::Table;
+    my $render_row = sub {
+        my $cols = shift;
 
-    my $tb =
-        Text::Table->new(
-            \" | ", (map {; "X = $_", (\' | '); } $self->_x_indexes)
-        );
+        return 
+            "| " .
+            join(
+                " | ", 
+                map { length($_) == 1 ? "  $_  " : $_ } @$cols
+            ) . " |\n";
+    };
 
-    foreach my $y ($self->_y_indexes)
-    {
-        $tb->add(
-            map 
-            { $self->_get_possible_letters_string($_, $y) } 
-            $self->_x_indexes
-        );
-    }
-
-    return $tb;
+    return join('',
+        map { $render_row->($_) }
+        (
+        [map { sprintf("X = %d", $_) } $self->_x_indexes ],
+        map { my $y = $_; 
+            [ 
+                map 
+                { $self->_get_possible_letters_string($_, $y) }
+                $self->_x_indexes
+            ]
+            }
+            $self->_y_indexes
+        )
+    );
 }
 
-sub _get_successes_text_tables
+=head2 $self->get_successes_text_tables()
+
+This returns a textual representation of the successful layouts.
+
+=cut
+
+sub get_successes_text_tables
 {
     my ($self) = @_;
 

File abc-path/Games-ABC_Path-Solver/scripts/abc-path-solve

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Games::ABC_Path::Solver::Board;
+
+my $board_fn = shift(@ARGV);
+
+if (!defined ($board_fn))
+{
+    die "Filename not specified - usage: abc-path-solver.pl [filename]!";
+}
+
+my $solver = Games::ABC_Path::Solver::Board->input_from_file($board_fn);
+# Now let's do a neighbourhood inferring of the board.
+
+$solver->solve;
+
+foreach my $move (@{$solver->get_moves})
+{
+    print +(' => ' x $move->get_depth()), $move->get_text(), "\n";
+}
+
+print @{$solver->get_successes_text_tables};
+
+1;
+

File abc-path/Games-ABC_Path-Solver/t/layouts/brain-bashers.2010-12-21.abc-path

+ABC Path Solver Layout Version 1:
+OWXIBQN
+J    AK
+E     L
+U     F
+Y     P
+R     S
+TVMGCDH

File abc-path/Games-ABC_Path-Solver/t/layouts/brain-bashers.2010-12-22.abc-path

+ABC Path Solver Layout Version 1:
+PEIRQXK
+D     S
+B     U
+O A   G
+W     H
+J     L
+TFCMYVN

File abc-path/Games-ABC_Path-Solver/t/results/brain-bashers.2010-12-21.abc-path-sol

+B cannot be at (3,2) due to lack of vicinity from A.
+B cannot be at (3,3) due to lack of vicinity from A.
+B cannot be at (3,4) due to lack of vicinity from A.
+C cannot be at (3,3) due to lack of vicinity from B.
+C cannot be at (3,4) due to lack of vicinity from B.
+D cannot be at (4,4) due to lack of vicinity from C.
+E cannot be at (0,1) due to lack of vicinity from D.
+E cannot be at (1,1) due to lack of vicinity from D.
+E cannot be at (2,1) due to lack of vicinity from D.
+D cannot be at (4,3) due to lack of vicinity from E.
+F cannot be at (0,2) due to lack of vicinity from E.
+F cannot be at (1,2) due to lack of vicinity from E.
+G cannot be at (2,0) due to lack of vicinity from F.
+G cannot be at (2,4) due to lack of vicinity from F.
+F cannot be at (4,2) due to lack of vicinity from G.
+H cannot be at (0,0) due to lack of vicinity from G.
+H cannot be at (4,4) due to lack of vicinity from G.
+J cannot be at (0,0) due to lack of vicinity from I.
+I cannot be at (2,2) due to lack of vicinity from J.
+I cannot be at (2,3) due to lack of vicinity from J.
+I cannot be at (2,4) due to lack of vicinity from J.
+M cannot be at (1,3) due to lack of vicinity from L.
+M cannot be at (1,4) due to lack of vicinity from L.
+L cannot be at (3,1) due to lack of vicinity from M.
+L cannot be at (4,1) due to lack of vicinity from M.
+N cannot be at (3,1) due to lack of vicinity from M.
+N cannot be at (0,4) due to lack of vicinity from M.
+M cannot be at (1,0) due to lack of vicinity from N.
+O cannot be at (0,0) due to lack of vicinity from N.
+O cannot be at (4,4) due to lack of vicinity from N.
+P cannot be at (0,3) due to lack of vicinity from O.
+O cannot be at (1,1) due to lack of vicinity from P.
+Q cannot be at (4,1) due to lack of vicinity from P.
+P cannot be at (1,3) due to lack of vicinity from Q.
+P cannot be at (2,3) due to lack of vicinity from Q.
+R cannot be at (0,4) due to lack of vicinity from Q.
+R cannot be at (1,4) due to lack of vicinity from Q.
+R cannot be at (2,4) due to lack of vicinity from Q.
+Q cannot be at (4,2) due to lack of vicinity from R.
+S cannot be at (0,4) due to lack of vicinity from R.
+S cannot be at (1,4) due to lack of vicinity from R.
+T cannot be at (3,1) due to lack of vicinity from S.
+T cannot be at (2,2) due to lack of vicinity from S.
+T cannot be at (0,4) due to lack of vicinity from S.
+For T only (1,3) is possible.
+S cannot be at (3,4) due to lack of vicinity from T.
+S cannot be at (4,4) due to lack of vicinity from T.
+U cannot be at (3,2) due to lack of vicinity from T.
+U cannot be at (4,2) due to lack of vicinity from T.
+V cannot be at (0,0) due to lack of vicinity from U.
+V cannot be at (0,4) due to lack of vicinity from U.
+U cannot be at (2,2) due to lack of vicinity from V.
+Y cannot be at (3,3) due to lack of vicinity from X.
+Y cannot be at (4,3) due to lack of vicinity from X.
+X cannot be at (1,0) due to lack of vicinity from Y.
+X cannot be at (1,1) due to lack of vicinity from Y.
+The only letter that can be at (4,2) is D. Invalidating it for all other cells.
+The only letter that can be at (0,4) is W. Invalidating it for all other cells.
+The only letter that can be at (1,4) is X. Invalidating it for all other cells.
+The only letter that can be at (2,4) is S. Invalidating it for all other cells.
+The only letter that can be at (3,4) is R. Invalidating it for all other cells.
+The only letter that can be at (4,4) is Q. Invalidating it for all other cells.
+C cannot be at (3,0) due to lack of vicinity from D.
+H cannot be at (3,3) due to lack of vicinity from I.
+For N only (2,2) is possible.
+For O only (3,3) is possible.
+For P only (4,3) is possible.
+V cannot be at (0,1) due to lack of vicinity from W.
+V cannot be at (0,2) due to lack of vicinity from W.
+The only letter that can be at (0,0) is K. Invalidating it for all other cells.
+The only letter that can be at (1,0) is J. Invalidating it for all other cells.
+The only letter that can be at (2,0) is I. Invalidating it for all other cells.
+The only letter that can be at (3,0) is B. Invalidating it for all other cells.
+The only letter that can be at (0,1) is L. Invalidating it for all other cells.
+The only letter that can be at (2,1) is G. Invalidating it for all other cells.
+The only letter that can be at (4,1) is E. Invalidating it for all other cells.
+The only letter that can be at (0,2) is U. Invalidating it for all other cells.
+The only letter that can be at (1,2) is M. Invalidating it for all other cells.
+The only letter that can be at (2,3) is Y. Invalidating it for all other cells.
+C cannot be at (3,2) due to lack of vicinity from B.
+For C only (3,1) is possible.
+For F only (3,2) is possible.
+For H only (1,1) is possible.
+For V only (0,3) is possible.
+| X = 0 | X = 1 | X = 2 | X = 3 | X = 4 |
+|   K   |   J   |   I   |   B   |   A   |
+|   L   |   H   |   G   |   C   |   E   |
+|   U   |   M   |   N   |   F   |   D   |
+|   V   |   T   |   Y   |   O   |   P   |
+|   W   |   X   |   S   |   R   |   Q   |

File abc-path/Games-ABC_Path-Solver/t/results/brain-bashers.2010-12-22.abc-path-sol

+B cannot be at (3,1) due to lack of vicinity from A.
+B cannot be at (4,1) due to lack of vicinity from A.
+C cannot be at (1,3) due to lack of vicinity from B.
+C cannot be at (1,4) due to lack of vicinity from B.
+D cannot be at (3,0) due to lack of vicinity from C.
+D cannot be at (4,0) due to lack of vicinity from C.
+E cannot be at (0,2) due to lack of vicinity from D.
+E cannot be at (0,3) due to lack of vicinity from D.
+E cannot be at (0,4) due to lack of vicinity from D.
+D cannot be at (2,0) due to lack of vicinity from E.
+F cannot be at (0,3) due to lack of vicinity from E.
+F cannot be at (0,4) due to lack of vicinity from E.
+G cannot be at (2,2) due to lack of vicinity from F.
+G cannot be at (3,2) due to lack of vicinity from F.
+G cannot be at (4,2) due to lack of vicinity from F.
+For G only (0,2) is possible.
+F cannot be at (0,0) due to lack of vicinity from G.
+H cannot be at (2,3) due to lack of vicinity from G.
+H cannot be at (3,3) due to lack of vicinity from G.
+H cannot be at (4,3) due to lack of vicinity from G.
+I cannot be at (1,0) due to lack of vicinity from H.
+I cannot be at (1,1) due to lack of vicinity from H.
+J cannot be at (3,4) due to lack of vicinity from I.
+J cannot be at (4,4) due to lack of vicinity from I.
+K cannot be at (4,0) due to lack of vicinity from J.
+K cannot be at (3,1) due to lack of vicinity from J.
+K cannot be at (2,2) due to lack of vicinity from J.
+L cannot be at (3,4) due to lack of vicinity from K.
+L cannot be at (4,4) due to lack of vicinity from K.
+M cannot be at (2,0) due to lack of vicinity from L.
+M cannot be at (2,1) due to lack of vicinity from L.
+M cannot be at (2,2) due to lack of vicinity from L.
+L cannot be at (0,4) due to lack of vicinity from M.
+N cannot be at (0,0) due to lack of vicinity from M.
+N cannot be at (1,1) due to lack of vicinity from M.
+N cannot be at (4,4) due to lack of vicinity from M.
+P cannot be at (0,0) due to lack of vicinity from O.
+P cannot be at (4,4) due to lack of vicinity from O.
+Q cannot be at (3,0) due to lack of vicinity from P.
+P cannot be at (1,1) due to lack of vicinity from Q.
+S cannot be at (0,0) due to lack of vicinity from R.
+S cannot be at (4,0) due to lack of vicinity from R.
+R cannot be at (2,2) due to lack of vicinity from S.
+R cannot be at (2,3) due to lack of vicinity from S.
+R cannot be at (2,4) due to lack of vicinity from S.
+T cannot be at (2,2) due to lack of vicinity from S.
+T cannot be at (1,3) due to lack of vicinity from S.
+T cannot be at (0,4) due to lack of vicinity from S.
+S cannot be at (1,0) due to lack of vicinity from T.
+U cannot be at (0,1) due to lack of vicinity from T.
+U cannot be at (1,1) due to lack of vicinity from T.
+V cannot be at (4,3) due to lack of vicinity from U.
+V cannot be at (4,4) due to lack of vicinity from U.
+U cannot be at (2,1) due to lack of vicinity from V.
+W cannot be at (0,3) due to lack of vicinity from V.
+W cannot be at (1,3) due to lack of vicinity from V.
+W cannot be at (2,3) due to lack of vicinity from V.
+V cannot be at (4,0) due to lack of vicinity from W.
+V cannot be at (4,1) due to lack of vicinity from W.
+X cannot be at (4,0) due to lack of vicinity from W.
+X cannot be at (4,1) due to lack of vicinity from W.
+Y cannot be at (3,0) due to lack of vicinity from X.
+The only letter that can be at (3,0) is S. Invalidating it for all other cells.
+The only letter that can be at (4,0) is T. Invalidating it for all other cells.
+The only letter that can be at (4,1) is U. Invalidating it for all other cells.
+The only letter that can be at (0,3) is H. Invalidating it for all other cells.
+The only letter that can be at (2,3) is M. Invalidating it for all other cells.
+The only letter that can be at (4,4) is X. Invalidating it for all other cells.
+For F only (0,1) is possible.
+Q cannot be at (3,3) due to lack of vicinity from R.
+Q cannot be at (3,4) due to lack of vicinity from R.
+For V only (4,2) is possible.
+Y cannot be at (3,1) due to lack of vicinity from X.
+Y cannot be at (3,2) due to lack of vicinity from X.
+The only letter that can be at (2,0) is R. Invalidating it for all other cells.
+The only letter that can be at (2,1) is B. Invalidating it for all other cells.
+The only letter that can be at (3,1) is Q. Invalidating it for all other cells.
+The only letter that can be at (3,2) is O. Invalidating it for all other cells.
+The only letter that can be at (4,3) is W. Invalidating it for all other cells.
+The only letter that can be at (3,4) is Y. Invalidating it for all other cells.
+For E only (0,0) is possible.
+P cannot be at (3,3) due to lack of vicinity from Q.
+The only letter that can be at (1,1) is C. Invalidating it for all other cells.
+The only letter that can be at (3,3) is N. Invalidating it for all other cells.
+For D only (1,0) is possible.
+For P only (2,2) is possible.
+We have non-conclusive cells. Trying I for (1,3)
+ => For K only (0,4) is possible.
+ => J cannot be at (2,4) due to lack of vicinity from K.
+ => L cannot be at (2,4) due to lack of vicinity from K.
+ => For L only (1,4) is possible.
+Trying I for (1,3) results in an error.
+We have non-conclusive cells. Trying K for (1,3)
+ => For I only (1,4) is possible.
+ => For L only (2,4) is possible.
+ => The only letter that can be at (0,4) is J. Invalidating it for all other cells.
+Trying K for (1,3) returns a success.
+| X = 0 | X = 1 | X = 2 | X = 3 | X = 4 |
+|   E   |   D   |   R   |   S   |   T   |
+|   F   |   C   |   B   |   Q   |   U   |
+|   G   |   A   |   P   |   O   |   V   |
+|   H   |   K   |   M   |   N   |   W   |
+|   J   |   I   |   L   |   Y   |   X   |

File abc-path/Games-ABC_Path-Solver/t/solver-output-system-test.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+use Test::Differences;
+
+sub _slurp
+{
+    my $filename = shift;
+
+    open my $in, "<", $filename
+        or die "Cannot open '$filename' for slurping - $!";
+
+    local $/;
+    my $contents = <$in>;
+
+    close($in);
+
+    return $contents;
+}
+
+{
+    my $got_results =
+        `$^X -Mblib scripts/abc-path-solve t/layouts/brain-bashers.2010-12-21.abc-path`
+        ;
+
+    # TEST
+    ok ((!$?), "Process ended successfully.");
+
+    my $exp_results =
+        _slurp('./t/results/brain-bashers.2010-12-21.abc-path-sol');
+
+    # TEST
+    eq_or_diff(
+        $got_results,
+        $exp_results,
+        "Output is OK.",
+    );
+}
+
+{
+    my $got_results =
+        `$^X -Mblib scripts/abc-path-solve t/layouts/brain-bashers.2010-12-22.abc-path`
+        ;
+
+    # TEST
+    ok ((!$?), "Process ended successfully.");
+
+    my $exp_results =
+        _slurp('./t/results/brain-bashers.2010-12-22.abc-path-sol');
+
+    # TEST
+    eq_or_diff(
+        $got_results,
+        $exp_results,
+        "Output is OK.",
+    );
+}
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (c) 2010 Shlomi Fish
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+=cut
+