Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…

… (mostly) by colomon++

git-svn-id: http://svn.pugscode.org/pugs@28161 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit a4ba5fd817e61b34abef0d8b647c44a676f12b18 1 parent c3ff100
moritz authored
View
4 S02-builtin_data_types/declare.t
@@ -29,7 +29,7 @@ plan 85;
}
{
- my Rat $namcu = 7 div 4;
+ my Rat $namcu = 7 / 4;
isa_ok($namcu,Rat);
}
@@ -148,7 +148,7 @@ plan 85;
#?rakudo skip 'rat not implemented'
{
- my rat $namcu = 7 div 4;
+ my rat $namcu = 7 / 4;
isa_ok($namcu,rat);
}
View
4 S02-builtin_data_types/num.t
@@ -19,7 +19,7 @@ plan 48;
#L<S02/Built-In Data Types/Rat supports arbitrary precision rational arithmetic>
{
- my $a = 1 div 1;
+ my $a = 1 / 1;
isa_ok($a, Rat);
is($a, "1/1", '1.0 stringification works');
}
@@ -91,7 +91,7 @@ plan 48;
}
#L<S02/Built-In Data Types/Rat supports arbitrary precision rational arithmetic>
-isa_ok(1 div 1, Rat);
+isa_ok(1 / 1, Rat);
{
my $a = 80000.0000000000000000000000000;
View
4 S02-builtin_data_types/type.t
@@ -118,8 +118,8 @@ my $baz of Int;
{
# the following two are the same type of behavior
# S02: "It is possible for the of type to disagree with the as type"
- my Rat sub returntype4 ($pass) as Num {$pass ?? 11 div 10 !! 1}
- my sub returntype5 ($pass --> Rat) as Num {$pass ?? 11 div 5 !! 2}
+ my Rat sub returntype4 ($pass) as Num {$pass ?? 11 / 10 !! 1}
+ my sub returntype5 ($pass --> Rat) as Num {$pass ?? 11 / 5 !! 2}
is(returntype4(True), 1.1, 'good return value works (my Type sub as OtherType)');
eval_dies_ok('returntype4(False)', 'bad return value dies (my Type sub as OtherType)');
View
4 S02-literals/radix.t
@@ -106,7 +106,7 @@ is(:16('0d37'), 0x0D37, ":16('0d37') uses d as hex digit" );
# L<S02/Literals/"Any radix may include a fractional part">
#?rakudo todo 'fractionals base 16'
-is(:16<dead_beef.face>, 0xDEAD_BEEF + 0xFACE / ( 16 ** 4 ), 'Fractional base 16 works' );
+is(:16<dead_beef.face>, 0xDEAD_BEEF + 0xFACE div ( 16 ** 4 ), 'Fractional base 16 works' );
# L<S02/Literals/":8<177777>">
@@ -225,7 +225,7 @@ is( :2<1.1> * :2<10> ** :2<10>, 6, 'multiplication and exponentiatio
is +":1_0<14_56>", 1456, "underscore seperators works";
is +":10<123.456>", 123.456, "base 10 decimal notation works";
is +":2<1.111>", 1.875, "base 2 decimal notation works";
- is +":16<dead_beef.face>", 0xDEADBEEF + 0xFACE / (16 ** 4), "fractional base 16 works";
+ is +":16<dead_beef.face>", 0xDEADBEEF + 0xFACE / 65536.0, "fractional base 16 works";
for 2..36 {
is +":{$_}<11>", $_ + 1, "stringified form of base $_ works";
View
2  S02-magicals/dollar_bang.t
@@ -34,7 +34,7 @@ ok $!, 'Calling a subroutine with a nonmatching signature sets $!';
ok !$called, 'The subroutine also was not called';
undefine $!;
-try { 1 / 0 };
+try { 1 div 0 };
ok $!, 'Dividing one by zero sets $!';
sub incr ( $a is rw ) { $a++ };
View
56 S03-operators/arith.t
@@ -2,7 +2,7 @@ use v6;
use Test;
-plan 199;
+plan 200;
my $five = abs(-5);
@@ -263,15 +263,17 @@ tryeq -1.2, " -1.2";
# divide
-tryeq 28/14, 2;
-tryeq 28/-7, -4;
-tryeq -28/4, -7;
-tryeq -28/-2, 14;
+tryeq 28 div 14, 2;
+tryeq 28 div -7, -4;
+tryeq -28 div 4, -7;
+tryeq -28 div -2, 14;
-tryeq 0x80000000/1, 0x80000000;
-tryeq 0x80000000/-1, -0x80000000;
-tryeq -0x80000000/1, -0x80000000;
-tryeq -0x80000000/-1, 0x80000000;
+tryeq 0x80000000 div 1, 0x80000000;
+tryeq 0x80000000 div -1, -0x80000000;
+tryeq -0x80000000 div 1, -0x80000000;
+tryeq -0x80000000 div -1, 0x80000000;
+
+is(9 div 4, 2, "9 div 4 == 2");
# The example for sloppy divide, rigged to avoid the peephole optimiser.
is_approx "20." / "5.", 4;
@@ -283,12 +285,14 @@ tryeq -5.5 / -2, 2.75;
# Bluuurg if your floating point can't accurately cope with powers of 2
# [I suspect this is parsing string-to-float problems, not actual arith]
-is 18446744073709551616/1, 18446744073709551616; # Bluuurg
+#?rakudo todo 'big numbers'
+is 18446744073709551616 div 1, 18446744073709551616; # Bluuurg
{
- tryeq_sloppy 18446744073709551616/2, 9223372036854775808;
- tryeq_sloppy 18446744073709551616/4294967296, 4294967296;
- tryeq_sloppy 18446744073709551616/9223372036854775808, 2;
+ tryeq_sloppy 18446744073709551616 div 2, 9223372036854775808;
+ tryeq_sloppy 18446744073709551616 div 4294967296, 4294967296;
+ #?rakudo skip 'big numbers'
+ ok 18446744073709551616 div 9223372036854775808 == 2, '$bignum1 div $bignum2';
}
{
@@ -323,7 +327,7 @@ is 2 ** 2 ** 3, 256, 'infix:<**> is right associative';
{
is_approx(-1, (0 + 1i)**2, "i^2 == -1");
is_approx(-1, (0.7071067811865476 + -0.7071067811865475i)**4, "sqrt(-i)**4 ==-1" );
- is_approx(1i, (-1+0i)**(1/2), '(-1+0i)**(1/2) == i ');
+ is_approx(1i, (-1+0i)**0.5, '(-1+0i)**0.5 == i ');
}
{
@@ -335,16 +339,16 @@ is 2 ** 2 ** 3, 256, 'infix:<**> is right associative';
is Inf+100, Inf;
is Inf-100, Inf;
is Inf*100, Inf;
- is Inf/100, Inf;
+ is Inf / 100, Inf;
is Inf*-100, -Inf;
- is Inf/-100, -Inf;
- is 100/Inf, 0;
+ is Inf / -100, -Inf;
+ is 100 / Inf, 0;
is Inf**100, Inf;
is Inf*0, NaN;
is Inf - Inf, NaN;
is Inf*Inf, Inf;
- is Inf/Inf, NaN;
- is Inf*Inf/Inf, NaN;
+ is Inf / Inf, NaN;
+ is Inf*Inf / Inf, NaN;
is Inf**0, 1;
is 0**0, 1;
is 0**Inf, 0;
@@ -373,18 +377,18 @@ is 2 ** 2 ** 3, 256, 'infix:<**> is right associative';
is NaN+100, NaN;
is NaN-100, NaN;
is NaN*100, NaN;
- is NaN/100, NaN;
+ is NaN / 100, NaN;
is NaN**100, NaN;
is NaN+NaN, NaN;
is NaN - NaN, NaN;
is NaN*NaN, NaN;
- is NaN/NaN, NaN;
+ is NaN / NaN, NaN;
is NaN+Inf, NaN;
is NaN - Inf, NaN;
is NaN*Inf, NaN;
- is NaN/Inf, NaN;
- is Inf/NaN, NaN;
+ is NaN / Inf, NaN;
+ is Inf / NaN, NaN;
my $nan1 = NaN**NaN;
is $nan1, NaN, "NaN**NaN";
@@ -413,9 +417,9 @@ dies_ok( { say 3 % 0 }, 'Modulo zero dies and is catchable');
dies_ok( { $x = 0; say 3 % $x; }, 'Modulo zero dies and is catchable with VInt/VRat variables');
dies_ok( { $x := 0; say 3 % $x; }, 'Modulo zero dies and is catchable with VRef variables');
-dies_ok( { say 3 / 0 }, 'Division by zero dies and is catchable');
-dies_ok( { $x = 0; say 3 / $x; }, 'Division by zero dies and is catchable with VInt/VRat variables');
-dies_ok( { $x := 0; say 3 / $x; }, 'Division by zero dies and is catchable with VRef variables');
+dies_ok( { say 3 div 0 }, 'Division by zero dies and is catchable');
+dies_ok( { $x = 0; say 3 div $x; }, 'Division by zero dies and is catchable with VInt div VRat variables');
+dies_ok( { $x := 0; say 3 div $x; }, 'Division by zero dies and is catchable with VRef variables');
# This is a rakudo regression wrt bignum:
#?rakudo skip 'bigint'
View
8 S03-operators/assign.t
@@ -297,10 +297,10 @@ my @p;
{
my $x = 6;
- @p = $x /= 3, 4;
- is($x, 2, '/= operator');
- is(@p[0],2, "/= operator parses as item assignment 1");
- is(@p[1],4, "/= operator parses as item assignment 2");
+ @p = $x div= 3, 4;
+ is($x, 2, 'div= operator');
+ is(@p[0],2, "div= operator parses as item assignment 1");
+ is(@p[1],4, "div= operator parses as item assignment 2");
}
{
View
2  S03-operators/basic-types.t
@@ -64,7 +64,7 @@ ok(+$num ~~ Num, 'it is an Num type');
my $float = 0.5;
isa_ok($float, Num, 'it is an Num type');
-isa_ok(1 div 4, Rat, 'infix:<div> produces a Rat');
+isa_ok(1 / 4, Rat, 'infix:</> of integers produces a Rat');
my $string = "Hello World";
isa_ok($string, Str, 'it is a Str type');
View
4 S03-operators/hyper.t
@@ -35,7 +35,7 @@ my @e;
@e = ((1,1,1), (2,2), (3));
is(~@r, ~@e, "hyper-xx two arrays");
- @r = (20, 40, 60) »/« (2, 5, 10);
+ @r = (20, 40, 60) »div« (2, 5, 10);
@e = (10, 8, 6);
is(~@r, ~@e, "hyper-divide two arrays");
@@ -65,7 +65,7 @@ my @e;
@e = ((1,1,1), (2,2), (3));
is(~@r, ~@e, "hyper-xx two arrays ASCII notation");
- @r = (20, 40, 60) >>/<< (2, 5, 10);
+ @r = (20, 40, 60) >>div<< (2, 5, 10);
@e = (10, 8, 6);
is(~@r, ~@e, "hyper-divide two arrays ASCII notation");
View
5 S03-operators/precedence.t
@@ -13,7 +13,7 @@ proper separation of the two levels.
=end pod
-plan 54;
+plan 55;
# terms
@@ -46,7 +46,8 @@ is(?2*2, 2, "binary -> numify causes reinterpretation as, binds tighter than *")
# multiplicative
is(4 + 3 * 2, 10, "* binds tighter than binary +");
-is(2 - 2 / 2, 1, "/ binds tighter than binary -");
+is(2 - 2 div 2, 1, "div binds tighter than binary -");
+is(2 - 2 / 2, 1 / 1, "/ binds tighter than binary -");
# additive
View
2  S03-operators/ternary.t
@@ -21,7 +21,7 @@ my $str3 = "bbb";
}
is(($str2 eq $str1 ?? 8 * 8 !! 9 * 9), 64, "?? !! in parenthesis");
-is(($str2 eq $str3 ?? 8 + 8 !! 9 / 9), 1, "?? !! in parenthesis");
+is(($str2 eq $str3 ?? 8 + 8 !! 9 div 9), 1, "?? !! in parenthesis");
is(1 ?? 2 ?? 3 !! 4 !! 5 ?? 6 !! 7, 3, "nested ?? !!");
is(1 ?? 0 ?? 3 !! 4 !! 5 ?? 6 !! 7, 4, "nested ?? !!");
View
27 S32-num/rat.t
@@ -16,14 +16,29 @@ is(~(Rat.new(-32,-33)), "32/33", "Double negatives cancel out");
is(~(Rat.new(2,4)), "1/2", "Reduce to simplest form in constructor");
is(~(Rat.new(39,33)), "13/11", "Reduce to simplest form in constructor");
is(~(Rat.new(0,33)), "0/1", "Reduce to simplest form in constructor");
+is(~(Rat.new(1451234131,60)), "1451234131/60", "Reduce huge number to simplest form in constructor");
# Test basic math
-is(~(1 div 4 + 1 div 4), "1/2", "1/4 + 1/4 = 1/2");
-is(~(1 div 4 + 2 div 7), "15/28", "1/4 + 2/7 = 15/28");
-is(~(1 div 4 + 1), "5/4", "1/4 + 1 = 5/4");
-is(~(1 + 1 div 4), "5/4", "1 + 1/4 = 5/4");
-is(~(1 div 4 - 1 div 4), "0/1", "1/4 - 1/4 = 0/1");
-is(~(1 div 4 - 3 div 4), "-1/2", "1/4 - 3/4 = -1/2");
+is(~(1 / 4 + 1 / 4), "1/2", "1/4 + 1/4 = 1/2");
+is(~(1 / 4 + 2 / 7), "15/28", "1/4 + 2/7 = 15/28");
+is(~(1 / 4 + 1), "5/4", "1/4 + 1 = 5/4");
+is(~(1 + 1 / 4), "5/4", "1 + 1/4 = 5/4");
+
+is(~(1 / 4 - 1 / 4), "0/1", "1/4 - 1/4 = 0/1");
+is(~(1 / 4 - 3 / 4), "-1/2", "1/4 - 3/4 = -1/2");
+is(~(1 / 4 - 1), "-3/4", "1/4 - 1 = -3/4");
+is(~(1 - 1 / 4), "3/4", "1 - 1/4 = 3/4");
+
+is(~((2 / 3) * (5 / 4)), "5/6", "2/3 * 5/4 = 5/6");
+is(~((2 / 3) * 2), "4/3", "2/3 * 2 = 4/3");
+is(~(2 * (2 / 3)), "4/3", "2 * 2/3 = 4/3");
+
+is(~((2 / 3) / (5 / 4)), "8/15", "2/3 / 5/4 = 8/15");
+is(~((2 / 3) / 2), "1/3", "2/3 / 2 = 1/3");
+is(~(2 / (1 / 3)), "3/2", "2 / 1/3 = 3/2");
+
+
+
done_testing;
View
2  integration/99problems-31-to-40.t
@@ -147,7 +147,7 @@ plan 67;
while $n > 1 {
if $n % $cond == 0 {
$count++;
- $n /= $cond;
+ $n div= $cond;
}
else {
if $count > 0 {
View
4 integration/99problems-51-to-60.t
@@ -56,14 +56,14 @@ plan 37;
return undef if $n == 0;
gather {
if $n % 2 == 1 {
- my $k = ($n - 1) / 2;
+ my $k = ($n - 1) div 2;
for cbal-tree($k) -> $a {
for cbal-tree($k) -> $b {
take ['x', $a, $b];
}
}
} else {
- my $k = $n / 2;
+ my $k = $n div 2;
for cbal-tree($k) -> $a {
for cbal-tree($k - 1) -> $b {
take ['x', $a, $b];
Please sign in to comment.
Something went wrong with that request. Please try again.