[Bps-public-commit] r16002 - Parse-BooleanLogic/t
ruz at bestpractical.com
ruz at bestpractical.com
Tue Sep 16 17:50:52 EDT 2008
Author: ruz
Date: Tue Sep 16 17:50:52 2008
New Revision: 16002
Added:
Parse-BooleanLogic/t/filter.t
Parse-BooleanLogic/t/fsolve.t
Log:
* more tests
Added: Parse-BooleanLogic/t/filter.t
==============================================================================
--- (empty file)
+++ Parse-BooleanLogic/t/filter.t Tue Sep 16 17:50:52 2008
@@ -0,0 +1,43 @@
+
+use strict;
+use warnings;
+
+use Test::More tests => 27;
+use Test::Deep;
+
+use_ok 'Parse::BooleanLogic';
+
+my $p = new Parse::BooleanLogic;
+
+my $cb = sub { return $_[0]->{'v'} };
+
+cmp_deeply $p->filter( [{ v => 1 }], $cb ), [{v => 1}], "'1'";
+cmp_deeply $p->filter( [{ v => 0 }], $cb ), [], "'0'";
+
+cmp_deeply $p->filter( [{v => 0}, 'AND', {v => 0}], $cb ), [], "0 AND 0";
+cmp_deeply $p->filter( [{v => 0}, 'AND', {v => 2}], $cb ), [{v => 2}], "0 AND 1";
+cmp_deeply $p->filter( [{v => 1}, 'AND', {v => 0}], $cb ), [{v => 1}], "1 AND 0";
+cmp_deeply $p->filter( [{v => 1}, 'AND', {v => 2}], $cb ), [{v => 1}, 'AND', {v => 2}], "1 AND 1";
+
+cmp_deeply $p->filter( [{v => 0}, 'OR', {v => 0}], $cb ), [], "0 OR 0";
+cmp_deeply $p->filter( [{v => 0}, 'OR', {v => 2}], $cb ), [{v => 2}], "0 OR 1";
+cmp_deeply $p->filter( [{v => 1}, 'OR', {v => 0}], $cb ), [{v => 1}], "1 OR 0";
+cmp_deeply $p->filter( [{v => 1}, 'OR', {v => 2}], $cb ), [{v => 1}, 'OR', {v => 2}], "1 OR 1";
+
+cmp_deeply $p->filter( [{v => 0}, 'AND', {v => 0}, 'OR', {v => 0}], $cb ), [], "0 AND 0 OR 0";
+cmp_deeply $p->filter( [{v => 0}, 'AND', {v => 0}, 'OR', {v => 3}], $cb ), [{v => 3}], "0 AND 0 OR 1";
+cmp_deeply $p->filter( [{v => 0}, 'AND', {v => 2}, 'OR', {v => 0}], $cb ), [{v => 2}], "0 AND 1 OR 0";
+cmp_deeply $p->filter( [{v => 0}, 'AND', {v => 2}, 'OR', {v => 3}], $cb ), [{v => 2}, 'OR', {v => 3}], "0 AND 1 OR 1";
+cmp_deeply $p->filter( [{v => 1}, 'AND', {v => 0}, 'OR', {v => 0}], $cb ), [{v => 1}], "1 AND 0 OR 0";
+cmp_deeply $p->filter( [{v => 1}, 'AND', {v => 0}, 'OR', {v => 3}], $cb ), [{v => 1}, 'OR', {v => 3}], "1 AND 0 OR 1";
+cmp_deeply $p->filter( [{v => 1}, 'AND', {v => 2}, 'OR', {v => 0}], $cb ), [{v => 1}, 'AND', {v => 2}], "1 AND 1 OR 0";
+cmp_deeply $p->filter( [{v => 1}, 'AND', {v => 2}, 'OR', {v => 3}], $cb ), [{v => 1}, 'AND', {v => 2}, 'OR', {v => 3}], "1 AND 1 OR 1";
+
+cmp_deeply $p->filter( [{v => 0}, 'AND', [ {v => 0}, 'OR', {v => 0}]], $cb ), [], "0 AND (0 OR 0)";
+cmp_deeply $p->filter( [{v => 0}, 'AND', [ {v => 0}, 'OR', {v => 3}]], $cb ), [{v => 3}], "0 AND (0 OR 1)";
+cmp_deeply $p->filter( [{v => 0}, 'AND', [ {v => 2}, 'OR', {v => 0}]], $cb ), [{v => 2}], "0 AND (1 OR 0)";
+cmp_deeply $p->filter( [{v => 0}, 'AND', [ {v => 2}, 'OR', {v => 3}]], $cb ), [{v => 2}, 'OR', {v => 3}], "0 AND (1 OR 1)";
+cmp_deeply $p->filter( [{v => 1}, 'AND', [ {v => 0}, 'OR', {v => 0}]], $cb ), [{v => 1}], "1 AND (0 OR 0)";
+cmp_deeply $p->filter( [{v => 1}, 'AND', [ {v => 0}, 'OR', {v => 3}]], $cb ), [{v => 1}, 'AND', {v => 3}], "1 AND (0 OR 1)";
+cmp_deeply $p->filter( [{v => 1}, 'AND', [ {v => 2}, 'OR', {v => 0}]], $cb ), [{v => 1}, 'AND', {v => 2}], "1 AND (1 OR 0)";
+cmp_deeply $p->filter( [{v => 1}, 'AND', [ {v => 2}, 'OR', {v => 3}]], $cb ), [{v => 1}, 'AND', [ {v => 2}, 'OR', {v => 3}]], "1 AND (1 OR 1)";
Added: Parse-BooleanLogic/t/fsolve.t
==============================================================================
--- (empty file)
+++ Parse-BooleanLogic/t/fsolve.t Tue Sep 16 17:50:52 2008
@@ -0,0 +1,60 @@
+
+use strict;
+use warnings;
+
+use Test::More tests => 41;
+
+use_ok 'Parse::BooleanLogic';
+
+my $p = new Parse::BooleanLogic;
+
+my $cb = sub { return $_[0]->{'v'} };
+
+is $p->fsolve( [{ v => 1 }], $cb ), 1, "true";
+is $p->fsolve( [{ v => 0 }], $cb ), 0, "false";
+is $p->fsolve( [{ v => undef }], $cb ), undef, "undef";
+
+is $p->fsolve( [{v => 0}, 'AND', {v => 0}], $cb ), 0, "0 AND 0";
+is $p->fsolve( [{v => 0}, 'AND', {v => 1}], $cb ), 0, "0 AND 1";
+is $p->fsolve( [{v => 1}, 'AND', {v => 0}], $cb ), 0, "1 AND 0";
+is $p->fsolve( [{v => 1}, 'AND', {v => 1}], $cb ), 1, "1 AND 1";
+
+is $p->fsolve( [{v => 0}, 'AND', {v => undef}], $cb ), 0, "0 AND X";
+is $p->fsolve( [{v => 1}, 'AND', {v => undef}], $cb ), 1, "1 AND X";
+is $p->fsolve( [{v => undef}, 'AND', {v => 0}], $cb ), 0, "X AND 0";
+is $p->fsolve( [{v => undef}, 'AND', {v => 1}], $cb ), 1, "X AND 1";
+is $p->fsolve( [{v => undef}, 'AND', {v => undef}], $cb ), undef, "X AND X";
+
+is $p->fsolve( [{v => 0}, 'OR', {v => 0}], $cb ), 0, "0 OR 0";
+is $p->fsolve( [{v => 0}, 'OR', {v => 1}], $cb ), 1, "0 OR 1";
+is $p->fsolve( [{v => 1}, 'OR', {v => 0}], $cb ), 1, "1 OR 0";
+is $p->fsolve( [{v => 1}, 'OR', {v => 1}], $cb ), 1, "1 OR 1";
+
+is $p->fsolve( [{v => 0}, 'OR', {v => undef}], $cb ), 0, "0 OR X";
+is $p->fsolve( [{v => 1}, 'OR', {v => undef}], $cb ), 1, "1 OR X";
+is $p->fsolve( [{v => undef}, 'OR', {v => 0}], $cb ), 0, "X OR 0";
+is $p->fsolve( [{v => undef}, 'OR', {v => 1}], $cb ), 1, "X OR 1";
+
+is $p->fsolve( [{v => 0}, 'AND', {v => 0}, 'OR', {v => 0}], $cb ), 0, "0 AND 0 OR 0";
+is $p->fsolve( [{v => 0}, 'AND', {v => 0}, 'OR', {v => 1}], $cb ), 1, "0 AND 0 OR 1";
+is $p->fsolve( [{v => 0}, 'AND', {v => 1}, 'OR', {v => 0}], $cb ), 0, "0 AND 1 OR 0";
+is $p->fsolve( [{v => 0}, 'AND', {v => 1}, 'OR', {v => 1}], $cb ), 1, "0 AND 1 OR 1";
+is $p->fsolve( [{v => 1}, 'AND', {v => 0}, 'OR', {v => 0}], $cb ), 0, "1 AND 0 OR 0";
+is $p->fsolve( [{v => 1}, 'AND', {v => 0}, 'OR', {v => 1}], $cb ), 1, "1 AND 0 OR 1";
+is $p->fsolve( [{v => 1}, 'AND', {v => 1}, 'OR', {v => 0}], $cb ), 1, "1 AND 1 OR 0";
+is $p->fsolve( [{v => 1}, 'AND', {v => 1}, 'OR', {v => 1}], $cb ), 1, "1 AND 1 OR 1";
+
+is $p->fsolve( [{v => 0}, 'AND', {v => 0}, 'OR', {v => undef}], $cb ), 0, "0 AND 0 OR X";
+is $p->fsolve( [{v => 0}, 'AND', {v => 1}, 'OR', {v => undef}], $cb ), 0, "0 AND 1 OR X";
+is $p->fsolve( [{v => 1}, 'AND', {v => 0}, 'OR', {v => undef}], $cb ), 0, "1 AND 0 OR X";
+is $p->fsolve( [{v => 1}, 'AND', {v => 1}, 'OR', {v => undef}], $cb ), 1, "1 AND 1 OR X";
+
+is $p->fsolve( [{v => 0}, 'AND', {v => undef}, 'OR', {v => 0}], $cb ), 0, "0 AND X OR 0";
+is $p->fsolve( [{v => 0}, 'AND', {v => undef}, 'OR', {v => 1}], $cb ), 1, "0 AND X OR 1";
+is $p->fsolve( [{v => 1}, 'AND', {v => undef}, 'OR', {v => 0}], $cb ), 1, "1 AND X OR 0";
+is $p->fsolve( [{v => 1}, 'AND', {v => undef}, 'OR', {v => 1}], $cb ), 1, "1 AND X OR 1";
+
+is $p->fsolve( [{v => undef}, 'AND', {v => 0}, 'OR', {v => 0}], $cb ), 0, "X AND 0 OR 0";
+is $p->fsolve( [{v => undef}, 'AND', {v => 0}, 'OR', {v => 1}], $cb ), 1, "X AND 0 OR 1";
+is $p->fsolve( [{v => undef}, 'AND', {v => 1}, 'OR', {v => 0}], $cb ), 1, "X AND 1 OR 0";
+is $p->fsolve( [{v => undef}, 'AND', {v => 1}, 'OR', {v => 1}], $cb ), 1, "X AND 1 OR 1";
More information about the Bps-public-commit
mailing list