Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[S32] unfossile more tests
  • Loading branch information
moritz committed May 23, 2011
1 parent c5fa27b commit 19614fb
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 91 deletions.
13 changes: 1 addition & 12 deletions S32-num/log.t
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 34;
plan 28;

=begin pod
Expand All @@ -26,13 +26,6 @@ is_approx(log(42, 23), 1.192051192, 'log(42, 23)');
# with non-Num
is_approx(log("42", "23"), 1.192051192, 'log(42, 23) with strings');

{
is_approx(log(:x(5)), $log_5, 'got the log of 5');
is_approx(log(:x(0.1)), $log_one_tenth, 'got the log of 0.1');
is_approx(log(:x(5), :base(10)), $log10_5, 'got the log10 of 5');
is_approx(log(:x(0.1), :base(10)), $log10_one_tenth, 'got the log10 of 0.1');
}

# L<S32::Numeric/Numeric/"=item log10">

is_approx(log10(5), $log10_5, 'got the log10 of 5');
Expand All @@ -49,10 +42,6 @@ is( log10(Inf), Inf, 'log10(Inf) = Inf');
is( log10(-Inf), NaN, 'log10(-Inf) = NaN');
is( log10(NaN), NaN, 'log10(NaN) = NaN');

{
is_approx(log10(:x(5)), $log10_5, 'got the log10 of 5');
is_approx(log10(:x(0.1)), $log10_one_tenth, 'got the log10 of 0.1');
}

# please add tests for complex numbers
#
Expand Down
8 changes: 4 additions & 4 deletions S32-num/rand.t
Expand Up @@ -51,19 +51,19 @@ lives_ok { srand(1) }, 'srand(1) lives and parses';

{
my sub repeat_rand ($seed) {
srand(:seed($seed));
srand($seed);
for 1..99 { rand; }
return rand;
}

ok(repeat_rand(314159) == repeat_rand(314159),
'srand(:seed(...)) provides repeatability for rand');
'srand(...) provides repeatability for rand');

ok(repeat_rand(0) == repeat_rand(0),
'edge case: srand(:seed(0)) provides repeatability');
'edge case: srand(0) provides repeatability');

ok(repeat_rand(0) != repeat_rand(1),
'edge case: srand(:seed(0)) not the same as srand(:seed(1))');
'edge case: srand(0) not the same as srand(:seed(1))');
}

#?rakudo skip 'Test is too slow'
Expand Down
16 changes: 1 addition & 15 deletions S32-num/rounders.t
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 148;
plan 108;

# L<S32::Numeric/Real/"=item round">
# L<S32::Numeric/Real/"=item floor">
Expand Down Expand Up @@ -82,20 +82,6 @@ for %tests.keys.sort -> $type {
}
}

for %tests.keys.sort -> $type {
my @subtests = @(%tests{$type}); # XXX .[] doesn't work yet!
for @subtests -> $test {
my $code = "{$type}(:x({$test[0]}))";
my $res = eval($code);

if ($!) {
#?pugs todo 'feature'
flunk("failed to parse $code ($!)");
} else {
ok($res == $test[1], "$code == {$test[1]}");
}
}
}

for %tests.keys.sort -> $type {
my @subtests = @(%tests{$type}); # XXX .[] doesn't work yet!
Expand Down
11 changes: 1 addition & 10 deletions S32-num/sign.t
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 42;
plan 35;

# L<S32::Numeric/Real/"=item sign">

Expand Down Expand Up @@ -48,15 +48,6 @@ isa_ok(sign(Inf), Int, 'got correct type for +Inf');
isa_ok(sign(-Inf), Int, 'got correct type for -Inf');
is(sign(NaN),NaN, 'sign of NaN is NaN');

{
is(sign(:x(0)), 0, 'got the right sign for 0');
is(sign(:x(-100)), -1, 'got the right sign for -100');
is(sign(:x(100)), 1, 'got the right sign for 100');
is(sign(:x(1.5)), 1, 'got the right sign for 1.5');
is(sign(:x(-1.5)), -1, 'got the right sign for -1.5');
is(sign(:x(1.5e-1)), 1, 'got the right sign for 1.5e-1');
is(sign(:x(-1.5e-1)), -1, 'got the right sign for -1.5e-1');
}

nok sign(Int).defined, 'sign(Int) is undefined';
nok sign(3+4i).defined, 'sign(Complex) fails';
Expand Down
10 changes: 1 addition & 9 deletions S32-num/sqrt.t
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 24;
plan 19;

# L<S32::Numeric/Real/"=item sqrt">

Expand Down Expand Up @@ -30,14 +30,6 @@ is(sqrt(-Inf), NaN, 'sqrt(-Inf) is NaN');
is(sqrt(-0/1), -0/1, 'sqrt preserves sign of Rat zero');
is(sqrt(-0.0e0), -0.0e0, 'sqrt preserves sign of Num zero');

{
is_approx(sqrt(:x(2)), 1.41421356, 'got the square root of 2 with named args');
is_approx(sqrt(:x(5)) * sqrt(5), 5, 'got the square root of 5 with named args');
is_approx(sqrt(:x(1/42)) * sqrt(1/42), 1/42, 'got the square root of 1/42 with named args');
is_approx(sqrt(:x(1e2)) * sqrt(1e2), 100, 'got the square root of 1e2 with named args');
is(sqrt(:x(-1)), NaN, 'sqrt(:x(-1)) is NaN');
}

# The spec specifies a branch cut in the complex plane of -pi <= theta <= pi
is_approx(sqrt(-1 +0i), 1i, 'got the square root of -1+0i');

Expand Down
18 changes: 0 additions & 18 deletions S32-num/unpolar.t
Expand Up @@ -14,13 +14,6 @@ my $pi = 312689/99532;
is_approx(cis(3*$pi / 2),-1i, "cis(3pi/2) == -i");
}

{
is_approx(cis(:angle(0)), 1 + 0i, "cis(:angle(0)) == 1");
is_approx(cis(:angle($pi)), -1 + 0i, "cis(:angle(pi)) == -1");
is_approx(cis(:angle($pi / 2)), 1i, "cis(:angle(pi/2)) == i");
is_approx(cis(:angle(3*$pi / 2)),-1i, "cis(:angle(3pi/2)) == -i");
}

# Test that 1.unpolar == cis
# L<S32::Numeric/Numeric/=item cis>
# L<S32::Numeric/Numeric/=item unpolar>
Expand Down Expand Up @@ -53,17 +46,6 @@ my $pi = 312689/99532;
}

# L<S32::Numeric/Numeric/=item unpolar>
{
# Basic tests for unpolar()
my $s = 2 * sqrt(2);

is_approx(unpolar(:mag(4), 0), 4, "unpolar(:mag(4), 0) == 4");
is_approx(unpolar(:mag(4), $pi/4), $s + ($s)i ,"unpolar(:mag(4), pi/4) == 2+2i");
is_approx(unpolar(:mag(4), $pi/2), 4i, "unpolar(:mag(4), pi/2) == 4i");
is_approx(unpolar(:mag(4), 3*$pi/4), -$s + ($s)i,"unpolar(:mag(4), pi/4) == -2+2i");
is_approx(unpolar(:mag(4), $pi), -4, "unpolar(:mag(4), pi) == -4");
}

{
# Basic tests for unpolar()
my $s = 2 * sqrt(2);
Expand Down
3 changes: 1 addition & 2 deletions S32-str/capitalize.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 16;
plan 15;

# L<S32::Str/Str/capitalize>

Expand All @@ -14,7 +14,6 @@ my $a = "";
is capitalize($a), "", "capitalize empty string";
$a = "puGS Is cOOl!";
is capitalize($a), "Pugs Is Cool!", "capitalize string works";
is capitalize(:string($a)), "Pugs Is Cool!", "capitalize string works with positional argument";
is $a, "puGS Is cOOl!", "original string not touched";
is $a.capitalize, "Pugs Is Cool!", "capitalize string works";
is $a, "puGS Is cOOl!", "original string not touched";
Expand Down
4 changes: 1 addition & 3 deletions S32-str/chomp.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 13;
plan 12;

=begin pod
Expand All @@ -25,8 +25,6 @@ Basic tests for the chomp() builtin
is($foo, 'foo', 'our variable is chomped correctly');
$foo .= chomp;
is($foo, 'foo', 'our variable is chomped again with no effect');
#?rakudo skip "chomp with named argument"
is(chomp(:string("station\n")), 'station', 'chomp works with a named argument');
}

{
Expand Down
4 changes: 1 addition & 3 deletions S32-str/chop.t
Expand Up @@ -3,16 +3,14 @@ use Test;

# L<S32::Str/Str/"=item chop">

plan 13;
plan 12;

#
# Tests already covered by the specs
#

my $str = "foo";
is(chop($str), "fo", "o removed");
#?rakudo skip 'calling positional args by name'
is(chop(:string($str)), "fo", "chop works with named arguments");
is($str, "foo", "original string unchanged");

is($str.chop, "fo", "o removed");
Expand Down
7 changes: 1 addition & 6 deletions S32-str/comb.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 44;
plan 41;

# L<S32::Str/Str/=item comb>

Expand All @@ -22,15 +22,11 @@ is( "a\c[COMBINING DOT ABOVE, COMBINING DOT BELOW]b".comb,
("a\c[COMBINING DOT BELOW, COMBINING DOT ABOVE]", "b", ),
"comb on string with grapheme non-precomposed");

#?pugs todo 'feature'
is "abcd".comb(:limit(2)), <a b>, 'default matcher with supplied limit';

#?pugs skip "todo: Str.comb"
{
my Str $hair = "Th3r3 4r3 s0m3 numb3rs 1n th1s str1ng";
is $hair.comb(/\d+/), <3 3 4 3 0 3 3 1 1 1>, 'no limit returns all matches';
#?rakudo skip 'calling positional args by name'
is comb(:input($hair), /\d+/), <3 3 4 3 0 3 3 1 1 1>, 'comb works with named argument for input';
is $hair.comb(/\d+/, -10), (), 'negative limit returns no matches';
is $hair.comb(/\d+/, 0), (), 'limit of 0 returns no matches';
is $hair.comb(/\d+/, 1), <3>, 'limit of 1 returns 1 match';
Expand Down Expand Up @@ -104,7 +100,6 @@ is (<a ab>, <bc ad ba>).comb(m:Perl5/\S*a\S*/), <a ab ad ba>,
{
is comb( /./ , "abcd"), <a b c d>, 'Subroutine form default limit';
is comb(/./ , "abcd" , 2 ), <a b>, 'Subroutine form with supplied limit';
is comb(/./ , "abcd" , :limit(2)), <a b>, 'Subroutine form with supplied limit';
is comb(/\d+/ , "Th3r3 4r3 s0m3 numb3rs 1n th1s str1ng"), <3 3 4 3 0 3 3 1 1 1>, 'Subroutine form with no limit returns all matches';
is comb(/\d+/ , "Th3r3 4r3 s0m3 numb3rs 1n th1s str1ng" , 2), <3 3>, 'Subroutine form with limit';
}
Expand Down
4 changes: 1 addition & 3 deletions S32-str/index.t
Expand Up @@ -3,7 +3,7 @@ use Test;

# L<S32::Str/Str/"=item index">

plan 38;
plan 37;

# Type of return value
#?rakudo 2 skip 'StrPos not implemented'
Expand Down Expand Up @@ -53,8 +53,6 @@ is(index("脺mlaut", "脺"), 0, "Umlaut");
# call directly with the .notation

is("Hello".index("l"), 2, ".index on string");
#?rakudo skip 'calling positional params by name'
is(index(:string('station'), "t"), 1, "index works with named argument");

# work on variables

Expand Down
3 changes: 1 addition & 2 deletions S32-str/lc.t
Expand Up @@ -2,13 +2,12 @@ use v6;

use Test;

plan 13;
plan 12;

# L<S32::Str/Str/lc>

is(lc("hello world"), "hello world", "lowercasing string which is already lowercase");
is(lc("Hello World"), "hello world", "simple lc test");
is(lc(:string("STATION")), "station", "lc works with named argument");
is(lc(""), "", "empty string");
is(lc("脜脛脰"), "氓盲枚", "some finnish non-ascii chars");
is(lc("脛脰脺"), "盲枚眉", "lc of German Umlauts");
Expand Down
3 changes: 1 addition & 2 deletions S32-str/lcfirst.t
Expand Up @@ -2,12 +2,11 @@ use v6;

use Test;

plan 9;
plan 8;

# L<S32::Str/Str/lcfirst>

is lcfirst("HELLO WORLD"), "hELLO WORLD", "simple";
is lcfirst(:string('FREW')), 'fREW', 'lcfirst works with named argument';
is lcfirst(""), "", "empty string";
is lcfirst("脺脺脺脺"), "眉脺脺脺", "umlaut";
is lcfirst("脫脫脫脫艃"), "贸脫脫脫艃", "accented chars";
Expand Down
3 changes: 1 addition & 2 deletions S32-str/length.t
Expand Up @@ -14,7 +14,7 @@ L<"http://www.unicode.org/unicode/reports/tr11/">
=end pod

plan 60;
plan 59;

eval_dies_ok('"moose".length', 'Str.length properly not implemented');

Expand All @@ -25,7 +25,6 @@ eval_dies_ok('"moose".length', 'Str.length properly not implemented');
#?rakudo 3 skip '.bytes not implemented'
is("".bytes, 0, "empty string");
is("moose".bytes, 5, "moose");
is(bytes(:string('station')), 7, "bytes works with named argument");
my $x = Nil;
dies_ok { $x.bytes }, "undefined.bytes fail()s";
# See thread "undef.chars" on p6l started by Ingo Blechschmidt:
Expand Down

0 comments on commit 19614fb

Please sign in to comment.