Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Properly use "isa_ok" and "is_deeply"
For some reason, I thought that "is" was using smartmatch to do the check,
whereas it only does an "eq"
  • Loading branch information
lizmat committed May 15, 2013
1 parent bb3e673 commit f039dde
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 86 deletions.
101 changes: 48 additions & 53 deletions S32-hash/delete-adverb.t
Expand Up @@ -66,18 +66,18 @@ sub gen_hash {

#?pugs 11 skip "no adverbials"
#?niecza 11 todo "adverbial pairs only used as boolean True"
my @fg = %h1<f g>;
is %h1<f g>:!delete, @fg, "Test non-deletion with ! multiple";
is %h1<f g>, @fg, "f g should not have been deleted";
is %h1<f g>:delete(0), @fg, "Test non-deletion with (0) multiple";
is %h1<f g>, @fg, "f g should not have been deleted";
is %h1<f g>:delete(False), @fg, "Test non-deletion with (False) multiple";
is %h1<f g>, @fg, "f g should not have been deleted";
is %h1<f g>:delete($dont), @fg, "Test non-deletion with (\$dont) multiple";
is %h1<f g>, @fg, "f g should not have been deleted";
is %h1<f g>:delete(1), @fg, "Test deletion with (1) multiple";
ok !any(%h1<f g>), "f g should be deleted now";
is +%h1, 21, "f g should be deleted now";
my $fg = %h1<f g>;
is_deeply %h1<f g>:!delete, $fg, "non-deletion with ! mult";
is_deeply %h1<f g>, $fg, "f g should not have been deleted";
is_deeply %h1<f g>:delete(0), $fg, "non-deletion with (0) mult";
is_deeply %h1<f g>, $fg, "f g should not have been deleted";
is_deeply %h1<f g>:delete(False), $fg, "non-deletion with (False) mult";
is_deeply %h1<f g>, $fg, "f g should not have been deleted";
is_deeply %h1<f g>:delete($dont), $fg, "non-deletion with (\$dont) mult";
is_deeply %h1<f g>, $fg, "f g should not have been deleted";
is_deeply %h1<f g>:delete(1), $fg, "deletion with (1) mult";
is_deeply %h1<f g>, (Any,Any), "f g should be deleted now";
is +%h1, 21, "f g should be deleted now";
} #14

{ # whatever
Expand All @@ -91,20 +91,17 @@ sub gen_hash {

{
my %h1 = gen_hash;
my @all = %h1{ "a".."z" };
my $all = %h1{ "a".."z" };

#?pugs 10 skip "no adverbials"
#?niecza 10 todo "adverbial pairs only used as boolean True"
is %h1{*}:!delete, @all, "Test non-deletion with ! whatever";
is +%h1, 26, "* should not be deleted now";
is %h1{*}:delete(0), @all, "Test non-deletion with (0) whatever";
is +%h1, 26, "* should not be deleted now";
is %h1{*}:delete(False), @all, "Test non-deletion with (False) whatever";
is +%h1, 26, "* should not be deleted now";
is %h1{*}:delete($dont), @all, "Test non-deletion with (\$dont) whatever";
is +%h1, 26, "* should not be deleted now";
is %h1{*}:delete(1), @all, "Test deletion with (1) whatever";
is +%h1, 0, "* should be deleted now";
is_deeply %h1{*}:!delete, $all, "Test non-deletion with ! *";
is_deeply %h1{*}:delete(0), $all, "Test non-deletion with (0) *";
is_deeply %h1{*}:delete(False), $all, "Test non-deletion with (False) *";
is_deeply %h1{*}:delete($dont), $all, "Test non-deletion with (\$dont) *";
is_deeply +%h1, 26, "* should not be deleted now";
is_deeply %h1{*}:delete(1), $all, "Test deletion with (1) *";
is_deeply +%h1, 0, "* should be deleted now";
} #10

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -145,60 +142,58 @@ sub gen_hash {

{ # multiple elements
my @a = gen_array;
my @b = @a[1,3];
my $b = @a[1,3];

#?pugs 3 skip "no adverbials"
#?niecza 3 skip "no adverbials"
is @a[1,3]:delete, @b, "Test for delete multiple elements";
is_deeply @a[1,3]:delete, $b, "Test for delete multiple elements";
#?rakudo todo "not being destructively read yet"
is @a[1,3], $default, "1 3 should be deleted now";
is +@a, 10, "1 3 should be deleted now";
is_deeply @a[1,3], (Any xx 2), "1 3 should be deleted now";
is +@a, 10, "1 3 should be deleted now";

#?pugs 11 skip "no adverbials"
#?niecza 11 skip "no adverbials"
my @c = @a[2,4,9];
is @a[2,4,9]:!delete, @c, "Test non-deletion with ! multiple";
is @a[2,4,9], @c, "2 4 9 should not have been deleted";
is @a[2,4,9]:delete(0), @c, "Test non-deletion with (0) multiple";
is @a[2,4,9], @c, "2 4 9 should not have been deleted";
is @a[2,4,9]:delete(False), @c, "Test non-deletion with (False) multiple";
is @a[2,4,9], @c, "2 4 9 should not have been deleted";
is @a[2,4,9]:delete($dont), @c, "Test non-deletion with (\$dont) multiple";
is @a[2,4,9], @c, "2 4 9 should not have been deleted";
is @a[2,4,9]:delete(1), @c, "Test deletion with (1) multiple";
my $c = @a[2,4,9];
is_deeply @a[2,4,9]:!delete, $c, "Test non-deletion with ! N";
is_deeply @a[2,4,9], $c, "2 4 9 should not have been deleted";
is_deeply @a[2,4,9]:delete(0), $c, "Test non-deletion with (0) N";
is_deeply @a[2,4,9], $c, "2 4 9 should not have been deleted";
is_deeply @a[2,4,9]:delete(False), $c, "Test non-deletion with (False) N";
is_deeply @a[2,4,9], $c, "2 4 9 should not have been deleted";
is_deeply @a[2,4,9]:delete($dont), $c, "Test non-deletion with (\$dont) N";
is_deeply @a[2,4,9], $c, "2 4 9 should not have been deleted";
is_deeply @a[2,4,9]:delete(1), $c, "Test deletion with (1) N";
#?rakudo 2 todo "not being destructively read yet"
ok !any(@a[2,4,9]), "2 4 9 should be deleted now";
is +@a, 9, "array should be shortened now";
is_deeply @a[2,4,9], (Any xx 3), "2 4 9 should be deleted now";
is +@a, 9, "array should be shortened now";
} #14

{ # whatever
my @a = gen_array;
my @all = @a[^10];
my $all = @a[^10];

#?pugs 2 skip "no adverbials"
#?niecza 2 skip "no adverbials"
is @a[*]:delete, @all, "Test deletion with whatever";
is_deeply @a[*]:delete, $all, "Test deletion with whatever";
#?rakudo todo "not being destructively read yet"
is +@a, 0, "* should be deleted now";
is +@a, 0, "* should be deleted now";
} #2

{
my @a = gen_array;
my @all = @a[^10];
my $all = @a[^10];

#?pugs 10 skip "no adverbials"
#?niecza 10 skip "no adverbials"
is @a[*]:!delete, @all, "Test non-deletion with ! whatever";
is +@a, 10, "* should not be deleted now";
is @a[*]:delete(0), @all, "Test non-deletion with (0) whatever";
is +@a, 10, "* should not be deleted now";
is @a[*]:delete(False), @all, "Test non-deletion with (False) whatever";
is +@a, 10, "* should not be deleted now";
is @a[*]:delete($dont), @all, "Test non-deletion with (\$dont) whatever";
is +@a, 10, "* should not be deleted now";
is @a[*]:delete(1), @all, "Test deletion with (1) whatever";
is_deeply @a[*]:!delete, $all, "Test non-deletion with ! *";
is_deeply @a[*]:delete(0), $all, "Test non-deletion with (0) *";
is_deeply @a[*]:delete(False), $all, "Test non-deletion with (False) *";
is_deeply @a[*]:delete($dont), $all, "Test non-deletion with (\$dont) *";

is +@a, 10, "* should not be deleted now";
is_deeply @a[*]:delete(1), $all, "Test deletion with (1) whatever";
#?rakudo todo "not being destructively read yet"
is +@a, 0, "* should be deleted now";
is +@a, 0, "* should be deleted now";
} #10

#-------------------------------------------------------------------------------
Expand Down
71 changes: 38 additions & 33 deletions S32-hash/exists-adverb.t
Expand Up @@ -27,37 +27,39 @@ sub gen_hash {

{
my %h1 = gen_hash;
is +%h1, 26, "basic sanity";
is %h1.elems, 26, "basic sanity";

#?pugs 2 skip "no adverbials"
ok %h1<b>:exists, "Test for exists single key";
ok !(%h1<X>:exists), "Test for non-exists single key";
#?pugs 4 skip "no adverbials"
isa_ok %h1<b>:exists, Bool, "Bool test for exists single key";
isa_ok %h1<X>:exists, Bool, "Bool test for non-exists single key";
ok %h1<b>:exists, "Test for exists single key";
ok !(%h1<X>:exists), "Test for non-exists single key";

#?pugs 10 skip "no adverbials"
#?niecza 8 todo "adverbial pairs only used as True"
ok !(%h1<c>:!exists), "Test non-exists with ! single key c";
ok %h1<X>:!exists, "Test non-exists with ! single key X";
ok %h1<X>:!exists, "Test non-exists with ! single key X";
ok !(%h1<c>:exists(0)), "Test non-exists with (0) single key c";
ok %h1<X>:exists(0), "Test non-exists with (0) single key X";
ok %h1<X>:exists(0), "Test non-exists with (0) single key X";
ok !(%h1<c>:exists(False)), "Test non-exists with (False) single key c";
ok %h1<X>:exists(False), "Test non-exists with (False) single key X";
ok %h1<X>:exists(False), "Test non-exists with (False) single key X";
ok !(%h1<c>:exists($dont)), "Test non-exists with (\$dont) single key c";
ok %h1<X>:exists($dont), "Test non-exists with (\$dont) single key X";
ok %h1<c>:exists(1), "Test exists with (1) single key c";
ok %h1<X>:exists($dont), "Test non-exists with (\$dont) single key X";
ok %h1<c>:exists(1), "Test exists with (1) single key c";
ok !(%h1<X>:exists(1)), "Test exists with (1) single key X";

#?pugs 6 skip "no adverbials"
#?rakudo 6 skip "oh noes, it dies"
is %h1<c >d e>:exists, (True, True, True), "Test for exists TTT";
is %h1<c d X>:exists, (True, True, False), "Test for exists TTF";
is %h1{*}:exists, (True xx 26), "Test for non-exists T*";
is_deeply %h1<c d e>:exists, (True, True, True), "Test exists TTT";
is_deeply %h1<c d X>:exists, (True, True, False), "Test exists TTF";
is_deeply %h1{*}:exists, (True xx 26).Parcel, "Test non-exists T*";
#?niezca 3 todo "adverbial pairs only used as True"
is %h1<c d e>:!exists, (False,False,False), "Test for non-exists FFF";
is %h1<c d X>:!exists, (False,False,True), "Test for non-exists FFT";
is %h1{*}:!exists, (False xx 26), "Test for non-exists F*";
is_deeply %h1<c d e>:!exists, (False,False,False), "Test non-exists FFF";
is_deeply %h1<c d X>:!exists, (False,False,True), "Test non-exists FFT";
is_deeply %h1{*}:!exists, (False xx 26).Parcel, "Test non-exists F*";

is +%h1, 26, "should not have changed hash";
} #20
is %h1.elems, 26, "should not have changed hash";
} #22

#-------------------------------------------------------------------------------
# Array
Expand All @@ -66,35 +68,38 @@ sub gen_hash {
my @a = gen_array;
is @a.elems, 10, "basic sanity";

#?pugs 2 skip "no adverbials"
#?niecza 2 skip "no adverbials"
ok @a[3]:exists, "Test for exists single element";
ok !(@a[10]:exists), "Test for non-exists single element";
#?pugs 4 skip "no adverbials"
#?niecza 4 skip "no adverbials"
#?rakudo 2 todo ":exists is ignored"
isa_ok @a[ 3]:exists, Bool, "Bool test for exists single element";
isa_ok @a[10]:exists, Bool, "Bool test for non-exists single element";
ok @a[ 3]:exists, "Test for exists single element";
ok !(@a[10]:exists), "Test for non-exists single element";

#?pugs 10 skip "no adverbials"
#?niecza 10 skip "no adverbials"
ok @a[9]:!exists, "Test non-exists with ! single elem 9";
ok @a[ 9]:!exists, "Test non-exists with ! single elem 9";
ok !(@a[10]:!exists), "Test non-exists with ! single elem 10";
ok @a[9]:exists(0), "Test non-exists with (0) single elem 9";
ok @a[ 9]:exists(0), "Test non-exists with (0) single elem 9";
ok !(@a[10]:exists(0)), "Test non-exists with (0) single elem 10";
ok @a[9]:exists(False), "Test non-exists with (False) single elem 9";
ok @a[ 9]:exists(False), "Test non-exists with (False) single elem 9";
ok !(@a[10]:exists(False)), "Test non-exists with (False) single elem 10";
ok @a[9]:exists($dont), "Test non-exists with (\$dont) single elem 9";
ok @a[ 9]:exists($dont), "Test non-exists with (\$dont) single elem 9";
ok !(@a[10]:exists($dont)), "Test non-exists with (\$dont) single elem 10";
ok @a[9]:exists(1), "Test exists with (1) single elem 9";
ok @a[ 9]:exists(1), "Test exists with (1) single elem 9";
ok !(@a[10]:exists(1)), "Test exists with (1) single elem 10";

#?pugs 6 skip "no adverbials"
#?rakudo 6 skip "oh noes, it dies"
is @a[1,2,4]:exists, (True, True, True), "Test for exists TTT";
is @a[1,2,10]:exists, (True, True, False), "Test for exists TTF";
is @a[*]:exists, (True xx 26), "Test for non-exists T*";
is_deeply @a[1,2, 4]:exists, (True, True, True), "Test exists TTT";
is_deeply @a[1,2,10]:exists, (True, True, False), "Test exists TTF";
is_deeply @a[*]:exists, (True xx 26).Parcel, "Test non-exists T*";
#?niezca 3 todo "adverbial pairs only used as True"
is @a[1,2,4]:!exists, (False,False,False), "Test for non-exists FFF";
is @a[1,2,10]:!exists, (False,False,True), "Test for non-exists FFT";
is @a[*]:!exists, (False xx 26), "Test for non-exists F*";
is_deeply @a[1,2, 4]:!exists, (False,False,False), "Test non-exists FFF";
is_deeply @a[1,2,10]:!exists, (False,False,True), "Test non-exists FFT";
is_deeply @a[*]:!exists, (False xx 26).Parcel, "Test non-exists F*";

is +@a, 10, "* should be deleted now";
is @a.elems, 10, "should be untouched";
} #20

#-------------------------------------------------------------------------------
Expand Down

0 comments on commit f039dde

Please sign in to comment.