Permalink
Browse files

[t] and [t/spec]

 * moved NaN.t, ref.t, trusts.t and fail.t to spec/
 * merged tests from complex_powers.t into arith.t
 * replaced die_and_end.t with something more useful inside spec/
 * merge builtins/my.t into spec/S04-declarations/my.t
 * small simplifications to spec/S03-operators/p5arrow.t
 * removed quotes from isa_ok(..., 'QuotedType') 
 * various unfudges for rakudo
 * added tests for binding to signatures
 * added tests for KeyHash
 * added TASKS
 * [examples/99problems]: simplified some of the tests
Merry Christmas!


git-svn-id: http://svn.pugscode.org/pugs@24607 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 5caad32 commit 207f13f6abb6124ca6a9340cf8f5b1c540570766 moritz committed Dec 25, 2008
@@ -37,15 +37,15 @@ is($anon_block(), 1, '{} <anon block> works');
{
# pointy subs
my $pointy_block = -> { 1 };
- isa_ok($pointy_block, 'Block');
+ isa_ok($pointy_block, Block);
is($pointy_block(), 1, '-> {} <"pointy" block> works');
my $pointy_block_w_arg = -> $arg { 1 + $arg };
- isa_ok($pointy_block_w_arg, 'Block');
+ isa_ok($pointy_block_w_arg, Block);
is($pointy_block_w_arg(3), 4, '-> $arg {} <"pointy" block w/args> works');
my $pointy_block_w_multiple_args = -> $arg1, $arg2 { $arg1 + $arg2 };
- isa_ok($pointy_block_w_multiple_args, 'Block');
+ isa_ok($pointy_block_w_multiple_args, Block);
is($pointy_block_w_multiple_args(3, 4), 7, '-> $arg1, $arg2 {} <"pointy" block w/multiple args> works');
my $pointy_block_nested = -> $a { -> $b { $a + $b }};
@@ -150,7 +150,6 @@ my @array2 = ("test", 1, undef);
is ~@array12,'a b c d', "assignment to end index correctly alters the array";
}
-#?rakudo skip "no whatever star yet"
#?pugs skip "no whatever star yet"
{
my @array13 = ('a', 'b', 'c', 'd');
@@ -8,7 +8,7 @@ plan 58;
# L<S09/Hashes>
my %hash1;
-isa_ok(%hash1, 'Hash');
+isa_ok(%hash1, Hash);
%hash1{"one"} = 5;
is(%hash1{"one"}, 5, 'lvalue hash assignment works (w/ double quoted keys)');
@@ -22,26 +22,26 @@ is(%hash1<three>, 3, 'lvalue hash assignment works (w/ unquoted style <key>)');
# basic hash creation w/ comma seperated key/values
my %hash2 = ("one", 1);
-isa_ok(%hash2, 'Hash');
+isa_ok(%hash2, Hash);
is(%hash2{"one"}, 1, 'comma seperated key/value hash creation works');
is(%hash2<one>, 1, 'unquoted <key> fetching works');
my %hash3 = ("one", 1, "two", 2);
-isa_ok(%hash3, 'Hash');
+isa_ok(%hash3, Hash);
is(%hash3{"one"}, 1, 'comma seperated key/value hash creation works with more than one pair');
is(%hash3{"two"}, 2, 'comma seperated key/value hash creation works with more than one pair');
# basic hash creation w/ => seperated key/values (pairs?)
my %hash4;
-isa_ok(%hash4, 'Hash');
+isa_ok(%hash4, Hash);
%hash4 = ("key" => "value");
is(%hash4{"key"}, 'value', '(key => value) seperated key/value has creation works');
# hash slicing
my %hash5 = ("one", 1, "two", 2, "three", 3);
-isa_ok(%hash5, 'Hash');
+isa_ok(%hash5, Hash);
my @slice1 = %hash5{"one", "three"};
is(+@slice1, 2, 'got the right amount of values from the %hash{} slice');
@@ -70,7 +70,7 @@ is(%hash5<foo>[1], 1, 'value assigned successfully with arrayref in list context
# keys
my %hash6 = ("one", 1, "two", 2, "three", 3);
-isa_ok(%hash6, 'Hash');
+isa_ok(%hash6, Hash);
my @keys1 = sort keys %hash6;
is(+@keys1, 3, 'got the right number of keys');
@@ -87,7 +87,7 @@ is(@keys2[2], 'two', 'got the right key');
# values
my %hash7 = ("one", 1, "two", 2, "three", 3);
-isa_ok(%hash7, 'Hash');
+isa_ok(%hash7, Hash);
my @values1 = sort values %hash7;
is(+@values1, 3, 'got the right number of values');
@@ -104,7 +104,7 @@ is(@values1[2], 3, 'got the right values');
# misc stuff ...
my %hash8;
-isa_ok(%hash8, 'Hash');
+isa_ok(%hash8, Hash);
%hash8 = (:one, :key<value>, :three(3));
is(%hash8{'one'}, 1, 'colonpair :one');
is(%hash8{'key'}, 'value', 'colonpair :key<value>');
@@ -116,7 +116,7 @@ my $key;
my $val;
my %hash9;
-isa_ok(%hash9, 'Hash');
+isa_ok(%hash9, Hash);
%hash9{1} = 2;
for (%hash9.kv) -> $k,$v {
@@ -138,11 +138,11 @@ is(%hash10<1>, 2, "assignment of pointy qw to hash");
sub test1{
my %sane = hash ('a'=>'b');
- is(~%sane.WHAT,'Hash','%sane is a Hash');
+ is(~%sane.WHAT,Hash,'%sane is a Hash');
}
sub test2 (Hash %hash) returns Void {
- is(~%hash.WHAT,'Hash','%hash is a Hash');
+ is(~%hash.WHAT,Hash,'%hash is a Hash');
}
my %h = hash (a => 'b');
@@ -25,14 +25,14 @@ plan 32;
# basic hash creation w/ comma seperated key/values
{
my $hash = hash("1st", 1);
- isa_ok $hash, 'Hash';
+ isa_ok $hash, Hash;
is $hash{"1st"}, 1, 'comma seperated key/value hash creation works';
is $hash<1st>, 1, 'unquoted <key> fetching works';
}
{
my $hash = hash("1st", 1, "2nd", 2);
- isa_ok $hash, 'Hash';
+ isa_ok $hash, Hash;
is $hash{"1st"}, 1,
'comma seperated key/value hash creation works with more than 1st pair';
is $hash{"2nd"}, 2,
@@ -0,0 +1,49 @@
+use v6;
+use Test;
+plan 18;
+
+# L<S02/Mutable types/"A KeyHash differs from a normal Hash">
+
+# untyped KeyHash
+{
+ my %h is KeyHash;
+
+ %h = (a => 1, b => 3, c => -1, d => 7);
+ is +%h.elems, 4, 'Inititalization worked';
+ lives_ok { %h<d> = 0 }, 'can set an item to 0';
+ is %h.elems, 3, '... and an item is gone';
+ is %h.keys.sort.join(''), 'abc', '... and the right one is gone';
+ %h<c>++;
+ is %h.keys.sort.join(''), 'ab', '++ on an item with -1 deletes it';
+ %h<a>--;
+ is ~%h.keys, 'b', '-- also removes items when they go to zero';
+ %h<b>--;
+ is ~%h.keys, 'b', '... but only if they go to zero';
+ %h<c> = 'abc';
+ is ~%h<b c>, '2 abc', 'can store a string as well';
+ %h<c> = '';
+ is +%h, 1, 'setting a value to the null string also removes it';
+ %h<b> = undef;
+ is %h, 0, 'setting a value to undef also removes it';
+ ok !%h, '... and the empty hash is false in boolean context';
+}
+
+# typed KeyHash
+{
+ my Int %h is KeyHash;
+
+ %h = (a => 1, b => 3, c => -1, d => 7);
+ is +%h.elems, 4, 'Inititalization worked';
+ lives_ok { %h<d> = 0 }, 'can set an item to 0';
+ is %h.elems, 3, '... and an item is gone';
+ is %h.keys.sort.join(''), 'abc', '... and the right one is gone';
+ %h<c>++;
+ is %h.keys.sort.join(''), 'ab', '++ on an item with -1 deletes it';
+ %h<a>--;
+ is ~%h.keys, 'b', '-- also removes items when they go to zero';
+ %h<b>--;
+ is ~%h.keys, 'b', '... but only if they go to zero';
+}
+
+
+# vim: ft=perl6
@@ -66,7 +66,7 @@ Some deeper tests were already added.
is(+@array, 4, 'got 4 elements in the Array of Arrays');
is(@array[0], 1, 'got the right first element');
#?rakudo todo 'too eager list flattening'
- isa_ok(@array[1], 'Array');
+ isa_ok(@array[1], Array);
is(@array[1][0], 2, 'got the right second/first element');
is(@array[1][1], 3, 'got the right second/second element');
isa_ok(@array[2], Array);
@@ -102,7 +102,7 @@ Some deeper tests were already added.
# UNSPECCED
{ # Hash of Arrays
my %hash;
- isa_ok(%hash, 'Hash');
+ isa_ok(%hash, Hash);
%hash<key> = [ 1, 2, 3 ];
isa_ok(%hash<key>, Array);
@@ -51,7 +51,7 @@ is($multi1[0], 1, 'got the right value at multi1 index 0');
is(+$multi1[1], 3, '+$multi1[1] works')
}
-isa_ok($multi1[1], 'List');
+isa_ok($multi1[1], List);
# multi-dimensional array slices
# L<S09/"Subscript and slice notation"/index value to each slice>
@@ -83,7 +83,7 @@ is(+$multi2, 2, 'the multi2 has 2 elements');
is(+$array, 3, 'multi2[0] has 3 elements');
is(+$multi2[0], 3, '+$multi2[0] works');
}
-isa_ok($multi2[0], 'List');
+isa_ok($multi2[0], List);
# slice
@@ -105,7 +105,7 @@ is($multi2[0][2], 3, 'got the right value at multi2 index 0,2');
is(+$array, 3, 'multi2[1] has 3 elements');
is(+$multi2[1], 3, '+$multi2[1] works');
}
-isa_ok($multi2[1], 'List');
+isa_ok($multi2[1], List);
# slice
@@ -0,0 +1,21 @@
+use v6;
+
+use Test;
+
+plan 6;
+
+# Undeterminate Math results
+# see L<"http://mathworld.wolfram.com/Indeterminate.html">
+# L<S02/"Built-In Data Types" /Perl 6 should by default make standard IEEE floating point concepts visible>
+
+is 0 * Inf , NaN, "0 * Inf";
+is Inf / Inf, NaN, "Inf / Inf";
+is Inf - Inf, NaN, "Inf - Inf";
+# if we say that 0**0 and Inf**0 both give 1 (sse below), then for which
+# number or limit whould $number ** 0 be different from 1? so maybe just say
+# that NaN ** 0 == 1?
+#?rakudo skip 'unspecced and inconsistent'
+is NaN ** 0, NaN, "NaN ** 0";
+
+is 0**0 , 1, "0**0 is 1, _not_ NaN";
+is Inf**0 , 1, "Inf**0 is 1, _not_ NaN";
@@ -4,86 +4,80 @@ use Test;
#L<S02/Built-In Data Types/Perl intrinsically supports big integers>
-plan 47;
+plan 48;
{
my $a = 1; "$a";
- isa_ok($a, 'Int');
+ isa_ok($a, Int);
is($a, "1", '1 stringification works');
}
{
my $a = -1; "$a";
- isa_ok($a, 'Int');
+ isa_ok($a, Int);
is($a, "-1", '-1 stringification works');
}
#L<S02/Built-In Data Types/Rat supports arbitrary precision rational arithmetic>
+#?rakudo skip "no Rat yet"
{
- my $a = 1.0; "$a";
- #?rakudo todo "no Rat yet"
- isa_ok($a, 'Rat');
+ my $a = 1 div 1;
+ isa_ok($a, Rat);
is($a, "1", '1.0 stringification works');
}
{
- my $a = -1.0; "$a";
- #?rakudo todo "no Rat yet"
- isa_ok($a, 'Rat');
+ my $a = -1.0;
+ isa_ok($a, Num);
is($a, "-1", '-1 stringification works');
}
{
- my $a = 0.1; "$a";
- #?rakudo todo "no Rat yet"
- isa_ok($a, 'Rat');
+ my $a = 0.1;
+ isa_ok($a, Num);
is($a, "0.1", '0.1 stringification works');
}
{
my $a = -0.1; "$a";
- #?rakudo todo "no Rat yet"
- isa_ok($a, 'Rat');
+ isa_ok($a, Num);
is($a, "-0.1", '-0.1 stringification works');
}
{
my $a = 10.01; "$a";
- #?rakudo todo "no Rat yet"
- isa_ok($a, 'Rat');
+ isa_ok($a, Num);
is($a, "10.01", '10.01 stringification works');
}
{
my $a = 1e3; "$a";
- #?rakudo todo "no Rat yet"
- isa_ok($a, 'Rat');
+ ok $a ~~ Num, '1e3 conforms to Num';
is($a, "1000", '1e3 stringification works');
}
{
my $a = 10.01e3; "$a";
- #?rakudo todo "no Rat yet"
- isa_ok($a, 'Rat');
+ isa_ok($a, Num);
is($a, "10010", '10.01e3 stringification works');
}
#L<S02/Built-In Data Types/Perl intrinsically supports big integers>
{
my $a = 0b100; "$a";
- isa_ok($a, 'Int');
+ isa_ok($a, Int);
is($a, "4", '0b100 (binary) stringification works');
}
{
my $a = 0x100; "$a";
- isa_ok($a, 'Int');
+ isa_ok($a, Int);
is($a, "256", '0x100 (hex) stringification works');
}
{
my $a = 0o100; "$a";
- isa_ok($a, 'Int');
+ isa_ok($a, Int);
is($a, "64", '0o100 (octal) stringification works');
}
@@ -98,17 +92,19 @@ plan 47;
}
#L<S02/Built-In Data Types/Rat supports arbitrary precision rational arithmetic>
+#?rakudo skip 'Rat, infix:<div>'
+isa_ok(1 div 1, Rat);
+
{
my $a = 80000.0000000000000000000000000;
- #?rakudo todo "no Rat yet"
- isa_ok($a, 'Rat');
+ isa_ok($a, Num);
ok($a == 80000.0, 'trailing zeros compare correctly');
}
{
my $a = 1.0000000000000000000000000000000000000000000000000000000000000000000e1;
#?rakudo todo "no Rat yet"
- isa_ok($a, 'Rat');
+ isa_ok($a, Rat);
ok($a == 10.0, 'trailing zeros compare correctly');
}
@@ -24,7 +24,7 @@ is @r, [1, 2, 3, 4, 5], 'got the right array';
# Range of Str
my $r = 'a'..'c';
-isa_ok $r, 'Range';
+isa_ok $r, Range;
# XXX unspecced: exact value of Range.perl
is $r.perl, '"a".."c"', 'canonical representation';
my @r = $r;
@@ -11,7 +11,7 @@ plan 10;
is "<%hash<a>>", '<1>', '"<%hash<a>>" works';
}
-#?rakudo skip '"MMD function __concatenate not found for types (100, 80)"'
+#?rakudo todo 'interpolation with subscripts'
{
my $hash = { a => 1, b => 2 };
is "$hash<a>", 1, '"$hash<a>" works';
Oops, something went wrong.

0 comments on commit 207f13f

Please sign in to comment.