Skip to content

Commit a25df02

Browse files
committed
tests for .base with digits, .base-repeating
1 parent c66e341 commit a25df02

File tree

1 file changed

+46
-18
lines changed

1 file changed

+46
-18
lines changed

S32-num/base.t

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,52 @@
11
use v6;
22
use Test;
33

4-
plan 12;
4+
plan 27;
55

6-
is 0.base(8), '0', '0.base(something)';
7-
# RT #112872
8-
is 0.base(2), '0', '0.base(2)';
9-
is 42.base(10), '42', '42.base(10)';
10-
is 42.base(16), '2A', '42.base(16)';
11-
is 42.base(2) , '101010', '42.base(2)';
12-
is 35.base(36), 'Z', '35.base(36)';
13-
is 36.base(36), '10', '36.base(36)';
14-
is (-12).base(16), '-C', '(-12).base(16)';
6+
# Int
7+
{
8+
is 0.base(8), '0', '0.base(something)';
9+
# RT #112872
10+
is 0.base(2), '0', '0.base(2)';
11+
is 42.base(10), '42', '42.base(10)';
12+
is 42.base(16), '2A', '42.base(16)';
13+
is 42.base(2) , '101010', '42.base(2)';
14+
is 35.base(36), 'Z', '35.base(36)';
15+
is 36.base(36), '10', '36.base(36)';
16+
is (-12).base(16), '-C', '(-12).base(16)';
17+
is 121.base(11,3), '100.000', 'Integer digits are 0s';
18+
is 121.base(11,0), '100', 'Integer with 0 digits fraction leaves off radix point';
19+
}
1520

21+
# Rat
1622
# RT 112900
17-
#?niecza 4 skip "Rat.base NYI"
18-
is (1/10000000000).base(3),
19-
'0.0000000000000000000010', # is the trailing zero correct?
20-
'(1/10000000000).base(3) (RT 112900)';
21-
is (3.25).base(16), '3.4', '(3.25).base(16)';
22-
is (10.5).base(2), '1010.1', '(10.5).base(2)';
23-
is (-3.5).base(16), '-3.8', '(-3.5).base(16)';
24-
#TODO more non-integer tests?
23+
#?niecza skip "Rat.base NYI"
24+
{
25+
is (1/10000000000).base(3),
26+
'0.0000000000000000000010', # is the trailing zero correct?
27+
'(1/10000000000).base(3) (RT 112900)';
28+
is (3.25).base(16), '3.4', '(3.25).base(16)';
29+
is (10.5).base(2), '1010.1', '(10.5).base(2)';
30+
is (-3.5).base(16), '-3.8', '(-3.5).base(16)';
31+
is (1/3).base(10,40), '0.3333333333333333333333333333333333333333', 'repeating fraction can go 40 digits';
32+
is (2/3).base(10,40), '0.6666666666666666666666666666666666666667', 'repeating fraction can round at 40 digits';
33+
is (1/2).base(3,40), '0.1111111111111111111111111111111111111112', 'repeating base 3 fraction can round at 40 digits';
34+
is :8<773320.123>.base(8,0), '773320', 'Rat with 0 digits fraction leaves off radix point';
35+
}
36+
37+
# base-repeating
38+
{
39+
is (1/65535).base-repeating(10).Str, '0.0 0001525902189669642175936522468909742885481040665293354695963988708323796444647898069733730067902647440299076829175249866483558403906309605554283970397497520408941786831464103150988021667811093308918898298619058518348973830777447165636682688639658197909514', '1/65536 repeats with 256 char cycle';
40+
is (1/7).base-repeating(10).Str, '0. 142857', '1/7 repeats with 6 char cycle';
41+
is 3.1416.base-repeating(36).Str, '3.5 3IHMIRZRPEGH1SA4YBV5TFLY1HWW0X6E63SUVG6OJCQ9K7U0CFWBAFBKSKI799UL2XR4NYM8EQUAPOTPZ6YWLNO8ZHC5J2D0MT58P4384DLDB022NDVQJXGRF17JN', '3.1416 repeats in base 36';
42+
}
43+
44+
# Num
45+
{
46+
is 16.99999e0.base(16,3), '11.000', 'rounding works on fractional part';
47+
is 16.99999e0.base(16,0), '11', 'rounding works on integer part';
48+
is 16.999e0.base(16,3), '10.FFC', 'rounding works on 16.999e0.base(16,3)';
49+
is 16.999e0.base(16,9), '10.FFBE76C8B', 'rounding works on 16.999e0.base(16,9)';
50+
is pi.base(10,4), '3.1416', 'pi rounds to 4 place';
51+
is (6.02214129e23 / 10 ** 23).base(3,0), '20', 'Num with 0 digits fraction leaves off radix point';
52+
}

0 commit comments

Comments
 (0)