Show
Ignore:
Timestamp:
07/02/08 20:34:54 (5 months ago)
Author:
Auzon
Message:

[gsoc_spectest] added more range tests, fixed existing ones, and unfudged some passing ones. (added 27 tests, removed 2)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • t/spec/S02-builtin_data_types/range.t

    r21156 r21168  
    33use Test; 
    44 
    5 plan 39; 
     5plan 64; 
    66 
    77# basic Range 
     
    3131 
    3232{ 
    33   my $r = 1..5; 
    34   #?rakudo 4 skip '.ACCEPTS not implemented between ranges' 
    35   ok(($r).ACCEPTS($r), 'accepts self'); 
    36   ok(($r).ACCEPTS(1..5), 'accepts same'); 
    37   ok($r ~~ $r, 'accepts self'); 
    38   ok($r ~~ 1..5, 'accepts same'); 
    39   # TODO check how to avoid "eager is" 
    40   #is($r, $r, "equals to self"); 
    41   my $s = 1..5; 
    42   #is($r, $s, "equals"); 
     33    my $r = 1..5; 
     34    #?rakudo 4 skip '.ACCEPTS not implemented between ranges' 
     35    ok(($r).ACCEPTS($r), 'accepts self'); 
     36    ok(($r).ACCEPTS(1..5), 'accepts same'); 
     37    ok($r ~~ $r, 'accepts self'); 
     38    ok($r ~~ 1..5, 'accepts same'); 
     39    # TODO check how to avoid "eager is" 
     40    #is($r, $r, "equals to self"); 
     41    my $s = 1..5; 
     42    #is($r, $s, "equals"); 
    4343} 
    4444 
     
    5050 
    5151ok(('a'..'z').ACCEPTS('x'), 'str in range'); 
    52 ##?rakudo 3 skip 'infix:~~ not implemented between Range and Str' 
    5352ok('x' ~~ 'a'..'z', 'str in range'); 
    5453ok('x' !~~ 'a'..'c', 'str not in range'); 
     
    5756 
    5857 
    59 #?rakudo 6 skip 'numification of Range not implemented' 
    6058is(+(6..6), 1, 'numification'); 
    6159is(+(6^..6), 0, 'numification'); 
    6260is(+(6..^6), 0, 'numification'); 
    6361is(+(6..8), 3, 'numification'); 
    64 ok(6..6 ~~ 1, 'numification'); 
    65 ok(6..8 !~~ 3, 'numification'); 
    6662 
    6763# shift 
    6864{ 
    69   my $r = 1..5; 
    70   my $n = $r.shift; 
    71   is $n, 1, "got the right shift result"; 
    72   my @r = $r; 
    73   is @r, [2, 3, 4, 5], 'got the right state change'; 
    74   my $s = 2..5; 
    75   #is $r, $s, "range modified after shift"; 
     65    my $r = 1..5; 
     66    my $n = $r.shift; 
     67    is $n, 1, "got the right shift result"; 
     68    my @r = $r; 
     69    is @r, [2, 3, 4, 5], 'got the right state change'; 
     70    my $s = 2..5; 
     71    #is $r, $s, "range modified after shift"; 
    7672} 
    7773 
    78 # infinite range 
    79 #?rakudo skip '*..* not implemented' 
     74# simple .to, .from 
    8075{ 
    81     my @inf = *..*; 
     76    my $r = 1 .. 5; 
     77    is($r.from, 1, 'range.from'); 
     78    is($r.to,   5, 'range.to'); 
    8279 
    83     is(@inf.shift, -Inf, 'bottom end of *..* is -Inf (1)'); 
    84     is(@inf.shift, -Inf, 'bottom end of *..* is still -Inf (2)'); 
     80    #?rakudo 3 skip '.min, .max, .minmax on ranges' 
     81    is($r.min, 1, 'range.min'); 
     82    is($r.max, 5, 'range.max'); 
     83    is($r.minmax, [1,5], 'range.minmax'); 
    8584 
    86     is(@inf.pop, Inf, 'top end of *..* is Inf (1)'); 
    87     is(@inf.pop, Inf, 'top end of *..* is still Inf (2)'); 
     85    #?rakudo 5 skip '.reverse on ranges' 
     86    is($r.reverse.from, 5, 'range.reverse.from'); 
     87    is($r.reverse.to,   1, 'range.reverse.to'); 
     88    is($r.min, 1, 'range.reverse.min'); 
     89    is($r.max, 5, 'range.reverse.max'); 
     90    is($r.minmax, [1,5], 'range.reverse.minmax'); 
     91} 
    8892 
    89     ok(42  ~~ @inf, 'positive integer matches *..*'); 
    90     ok(.2  ~~ @inf, 'positive non-int matches *..*'); 
    91     ok(-2  ~~ @inf, 'negative integer matches *..*'); 
    92     ok(-.2 ~~ @inf, 'negative non-int matches *..*'); 
     93# uneven ranges 
     94{ 
     95    my $r = 1 .. 4.5; 
     96    is($r.from, 1, 'uneven range.from'); 
     97    is($r.to, 4.5, 'uneven range.to'); 
     98 
     99    #?rakudo 3 skip '.min, .max, .minmax on range' 
     100    is($r.min, 1,   'range.min'); 
     101    is($r.max, 4.5, 'range.max'); 
     102    is($r.minmax, [1, 4.5], 'range.minmax'); 
     103 
     104    #?rakudo 2 skip '.reverse on ranges' 
     105    is($r.reverse.from, 4.5, 'uneven range.reverse.from'); 
     106    is($r.reverse.to,   1,   'uneven range.reverse.to'); 
     107 
     108    #?rakudo 10 skip '.pop on ranges' 
     109    is($r.shift, 1, 'uneven range.shift (1)'); 
     110    is($r.pop, 4.5, 'uneven range.pop (1)'); 
     111 
     112    is($r.from,  2, 'uneven range.from after shift,pop'); 
     113    is($r.to,  3.5, 'uneven range.to after shift,pop'); 
     114    is($r.minmax, [2, 3.5], 'uneven range.minmax after shift,pop'); 
     115 
     116    is($r.shift, 2, 'uneven range.shift (2)'); 
     117    is($r.pop, 3.5, 'uneven range.pop (2)'); 
     118    is($r.shift, 3, 'uneven range.shift (3)'); 
     119    ok(!$r.pop,     'uneven range.pop (empty)'); 
     120    ok(!$r.shift,   'uneven range.shift (empty)'); 
     121} 
     122 
     123# infinite ranges 
     124#?rakudo skip 'infinite ranges not implemented' 
     125{ 
     126    my $inf = *..*; 
     127 
     128    is($inf.shift, -Inf, 'bottom end of *..* is -Inf (1)'); 
     129    is($inf.shift, -Inf, 'bottom end of *..* is still -Inf (2)'); 
     130 
     131    is($inf.pop, Inf, 'top end of *..* is Inf (1)'); 
     132    is($inf.pop, Inf, 'top end of *..* is still Inf (2)'); 
     133 
     134    ok(42  ~~ $inf, 'positive integer matches *..*'); 
     135    ok(.2  ~~ $inf, 'positive non-int matches *..*'); 
     136    ok(-2  ~~ $inf, 'negative integer matches *..*'); 
     137    ok(-.2 ~~ $inf, 'negative non-int matches *..*'); 
    93138} 
    94139