Skip to content

Commit 90f8717

Browse files
test ipow/pow
1 parent 326f664 commit 90f8717

File tree

3 files changed

+492
-35
lines changed

3 files changed

+492
-35
lines changed

test/generate.py

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,65 @@
11
import operator
22

3+
hugenumbers = [
4+
1 ,
5+
17 ,
6+
91**7 ,
7+
2**30 ,
8+
3**50
9+
]
10+
11+
smallnumbers = [ 1 , 3 , 7 , 9 , 11 , 17 , 22 , 24 , 27 , 29 ]
12+
313
arithmetic = {
414
'add' : {
15+
'numbers' : hugenumbers ,
516
'apply' : operator.add ,
617
'str' : '+'
718
} ,
819
'sub' : {
20+
'numbers' : hugenumbers ,
921
'apply' : operator.sub ,
1022
'str' : '-'
1123
} ,
1224
'mul' : {
25+
'numbers' : hugenumbers ,
1326
'apply' : operator.mul ,
1427
'str' : '*'
1528
} ,
16-
# 'pow' : {
17-
# 'apply' : operator.pow ,
18-
# 'str' : '^'
19-
# } ,
29+
'pow' : {
30+
'numbers' : smallnumbers ,
31+
'apply' : operator.pow ,
32+
'str' : '^'
33+
} ,
2034
'div' : {
35+
'numbers' : hugenumbers ,
2136
'apply' : operator.floordiv ,
2237
'str' : '/'
2338
} ,
2439
'mod' : {
40+
'numbers' : hugenumbers ,
2541
'apply' : operator.mod ,
2642
'str' : '%'
2743
}
2844
}
2945

30-
numbers = [
31-
1 ,
32-
17 ,
33-
91**7 ,
34-
2**30 ,
35-
3**50
36-
]
37-
38-
def write ( f , name , t , opstr , a ) :
46+
def write ( f , numbers , name , t , opstr , a , ispow = True ) :
3947

4048
f.write("import test from 'ava' ;\n")
4149
f.write("import {{ parse , stringify , {} }} from '../../../../src' ;\n\n".format(name))
4250

51+
if ispow :
52+
53+
f.write("""function macro ( t , A , B , C ) {{
54+
const a = parse( A ) ;
55+
const c = {}( a , B ) ;
56+
t.is( stringify( a ) , {} ) ;
57+
t.is( stringify( c ) , C ) ;
58+
}}\n\n""".format( name , a ) )
59+
60+
else:
4361

44-
f.write("""function macro ( t , A , B , C ) {{
62+
f.write("""function macro ( t , A , B , C ) {{
4563
const a = parse( A ) ;
4664
const b = parse( B ) ;
4765
const c = {}( a , b ) ;
@@ -50,50 +68,65 @@ def write ( f , name , t , opstr , a ) :
5068
t.is( stringify( c ) , C ) ;
5169
}}\n\n""".format( name , a ) )
5270

71+
5372
f.write("macro.title = ( _ , A , B , C ) => `${{A}} {} ${{B}} = ${{C}}` ;\n\n".format(opstr))
5473

5574
for a in numbers :
5675

5776
for b in numbers :
5877

59-
x = a
60-
y = b
61-
c = t( x , y )
62-
f.write("test( macro , '{}' , '{}' , '{}' ) ;\n".format(x,y,c))
78+
if ispow:
79+
80+
x = a
81+
y = b
82+
c = t( x , y )
83+
f.write("test( macro , '{}' , {} , '{}' ) ;\n".format(x,y,c))
84+
85+
x = -a
86+
y = b
87+
c = t( x , y )
88+
f.write("test( macro , '{}' , {} , '{}' ) ;\n".format(x,y,c))
89+
90+
else:
6391

64-
x = -a
65-
y = b
66-
c = t( x , y )
67-
f.write("test( macro , '{}' , '{}' , '{}' ) ;\n".format(x,y,c))
92+
x = a
93+
y = b
94+
c = t( x , y )
95+
f.write("test( macro , '{}' , '{}' , '{}' ) ;\n".format(x,y,c))
6896

69-
x = a
70-
y = -b
71-
c = t( x , y )
72-
f.write("test( macro , '{}' , '{}' , '{}' ) ;\n".format(x,y,c))
97+
x = -a
98+
y = b
99+
c = t( x , y )
100+
f.write("test( macro , '{}' , '{}' , '{}' ) ;\n".format(x,y,c))
73101

74-
x = -a
75-
y = -b
76-
c = t( x , y )
77-
f.write("test( macro , '{}' , '{}' , '{}' ) ;\n".format(x,y,c))
102+
x = a
103+
y = -b
104+
c = t( x , y )
105+
f.write("test( macro , '{}' , '{}' , '{}' ) ;\n".format(x,y,c))
106+
107+
x = -a
108+
y = -b
109+
c = t( x , y )
110+
f.write("test( macro , '{}' , '{}' , '{}' ) ;\n".format(x,y,c))
78111

79112
for name , op in arithmetic.items():
80113

81-
# standard op
114+
t = op['apply']
115+
nb = op['numbers']
82116

117+
# standard op
83118
with open( 'test/src/integer/arithmetic/{}.js'.format(name) , 'w' ) as f :
84119

85120
opstr = op['str']
86-
t = op['apply']
87121
a = 'A'
88122

89-
write( f , name , t , opstr , a )
123+
write( f , nb , name , t , opstr , a , ispow = name == 'pow' )
90124

91125
# in-place op
92126
iname = 'i{}'.format(name)
93127
with open( 'test/src/integer/arithmetic/{}.js'.format(iname) , 'w' ) as f :
94128

95129
opstr = op['str'] + '='
96-
t = op['apply']
97130
a = 'C'
98131

99-
write( f , iname , t , opstr , a )
132+
write( f , nb , iname , t , opstr , a , ispow = name == 'pow' )

test/src/integer/arithmetic/ipow.js

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
import test from 'ava' ;
2+
import { parse , stringify , ipow } from '../../../../src' ;
3+
4+
function macro ( t , A , B , C ) {
5+
const a = parse( A ) ;
6+
const c = ipow( a , B ) ;
7+
t.is( stringify( a ) , C ) ;
8+
t.is( stringify( c ) , C ) ;
9+
}
10+
11+
macro.title = ( _ , A , B , C ) => `${A} ^= ${B} = ${C}` ;
12+
13+
test( macro , '1' , 1 , '1' ) ;
14+
test( macro , '-1' , 1 , '-1' ) ;
15+
test( macro , '1' , 3 , '1' ) ;
16+
test( macro , '-1' , 3 , '-1' ) ;
17+
test( macro , '1' , 7 , '1' ) ;
18+
test( macro , '-1' , 7 , '-1' ) ;
19+
test( macro , '1' , 9 , '1' ) ;
20+
test( macro , '-1' , 9 , '-1' ) ;
21+
test( macro , '1' , 11 , '1' ) ;
22+
test( macro , '-1' , 11 , '-1' ) ;
23+
test( macro , '1' , 17 , '1' ) ;
24+
test( macro , '-1' , 17 , '-1' ) ;
25+
test( macro , '1' , 22 , '1' ) ;
26+
test( macro , '-1' , 22 , '1' ) ;
27+
test( macro , '1' , 24 , '1' ) ;
28+
test( macro , '-1' , 24 , '1' ) ;
29+
test( macro , '1' , 27 , '1' ) ;
30+
test( macro , '-1' , 27 , '-1' ) ;
31+
test( macro , '1' , 29 , '1' ) ;
32+
test( macro , '-1' , 29 , '-1' ) ;
33+
test( macro , '3' , 1 , '3' ) ;
34+
test( macro , '-3' , 1 , '-3' ) ;
35+
test( macro , '3' , 3 , '27' ) ;
36+
test( macro , '-3' , 3 , '-27' ) ;
37+
test( macro , '3' , 7 , '2187' ) ;
38+
test( macro , '-3' , 7 , '-2187' ) ;
39+
test( macro , '3' , 9 , '19683' ) ;
40+
test( macro , '-3' , 9 , '-19683' ) ;
41+
test( macro , '3' , 11 , '177147' ) ;
42+
test( macro , '-3' , 11 , '-177147' ) ;
43+
test( macro , '3' , 17 , '129140163' ) ;
44+
test( macro , '-3' , 17 , '-129140163' ) ;
45+
test( macro , '3' , 22 , '31381059609' ) ;
46+
test( macro , '-3' , 22 , '31381059609' ) ;
47+
test( macro , '3' , 24 , '282429536481' ) ;
48+
test( macro , '-3' , 24 , '282429536481' ) ;
49+
test( macro , '3' , 27 , '7625597484987' ) ;
50+
test( macro , '-3' , 27 , '-7625597484987' ) ;
51+
test( macro , '3' , 29 , '68630377364883' ) ;
52+
test( macro , '-3' , 29 , '-68630377364883' ) ;
53+
test( macro , '7' , 1 , '7' ) ;
54+
test( macro , '-7' , 1 , '-7' ) ;
55+
test( macro , '7' , 3 , '343' ) ;
56+
test( macro , '-7' , 3 , '-343' ) ;
57+
test( macro , '7' , 7 , '823543' ) ;
58+
test( macro , '-7' , 7 , '-823543' ) ;
59+
test( macro , '7' , 9 , '40353607' ) ;
60+
test( macro , '-7' , 9 , '-40353607' ) ;
61+
test( macro , '7' , 11 , '1977326743' ) ;
62+
test( macro , '-7' , 11 , '-1977326743' ) ;
63+
test( macro , '7' , 17 , '232630513987207' ) ;
64+
test( macro , '-7' , 17 , '-232630513987207' ) ;
65+
test( macro , '7' , 22 , '3909821048582988049' ) ;
66+
test( macro , '-7' , 22 , '3909821048582988049' ) ;
67+
test( macro , '7' , 24 , '191581231380566414401' ) ;
68+
test( macro , '-7' , 24 , '191581231380566414401' ) ;
69+
test( macro , '7' , 27 , '65712362363534280139543' ) ;
70+
test( macro , '-7' , 27 , '-65712362363534280139543' ) ;
71+
test( macro , '7' , 29 , '3219905755813179726837607' ) ;
72+
test( macro , '-7' , 29 , '-3219905755813179726837607' ) ;
73+
test( macro , '9' , 1 , '9' ) ;
74+
test( macro , '-9' , 1 , '-9' ) ;
75+
test( macro , '9' , 3 , '729' ) ;
76+
test( macro , '-9' , 3 , '-729' ) ;
77+
test( macro , '9' , 7 , '4782969' ) ;
78+
test( macro , '-9' , 7 , '-4782969' ) ;
79+
test( macro , '9' , 9 , '387420489' ) ;
80+
test( macro , '-9' , 9 , '-387420489' ) ;
81+
test( macro , '9' , 11 , '31381059609' ) ;
82+
test( macro , '-9' , 11 , '-31381059609' ) ;
83+
test( macro , '9' , 17 , '16677181699666569' ) ;
84+
test( macro , '-9' , 17 , '-16677181699666569' ) ;
85+
test( macro , '9' , 22 , '984770902183611232881' ) ;
86+
test( macro , '-9' , 22 , '984770902183611232881' ) ;
87+
test( macro , '9' , 24 , '79766443076872509863361' ) ;
88+
test( macro , '-9' , 24 , '79766443076872509863361' ) ;
89+
test( macro , '9' , 27 , '58149737003040059690390169' ) ;
90+
test( macro , '-9' , 27 , '-58149737003040059690390169' ) ;
91+
test( macro , '9' , 29 , '4710128697246244834921603689' ) ;
92+
test( macro , '-9' , 29 , '-4710128697246244834921603689' ) ;
93+
test( macro , '11' , 1 , '11' ) ;
94+
test( macro , '-11' , 1 , '-11' ) ;
95+
test( macro , '11' , 3 , '1331' ) ;
96+
test( macro , '-11' , 3 , '-1331' ) ;
97+
test( macro , '11' , 7 , '19487171' ) ;
98+
test( macro , '-11' , 7 , '-19487171' ) ;
99+
test( macro , '11' , 9 , '2357947691' ) ;
100+
test( macro , '-11' , 9 , '-2357947691' ) ;
101+
test( macro , '11' , 11 , '285311670611' ) ;
102+
test( macro , '-11' , 11 , '-285311670611' ) ;
103+
test( macro , '11' , 17 , '505447028499293771' ) ;
104+
test( macro , '-11' , 17 , '-505447028499293771' ) ;
105+
test( macro , '11' , 22 , '81402749386839761113321' ) ;
106+
test( macro , '-11' , 22 , '81402749386839761113321' ) ;
107+
test( macro , '11' , 24 , '9849732675807611094711841' ) ;
108+
test( macro , '-11' , 24 , '9849732675807611094711841' ) ;
109+
test( macro , '11' , 27 , '13109994191499930367061460371' ) ;
110+
test( macro , '-11' , 27 , '-13109994191499930367061460371' ) ;
111+
test( macro , '11' , 29 , '1586309297171491574414436704891' ) ;
112+
test( macro , '-11' , 29 , '-1586309297171491574414436704891' ) ;
113+
test( macro , '17' , 1 , '17' ) ;
114+
test( macro , '-17' , 1 , '-17' ) ;
115+
test( macro , '17' , 3 , '4913' ) ;
116+
test( macro , '-17' , 3 , '-4913' ) ;
117+
test( macro , '17' , 7 , '410338673' ) ;
118+
test( macro , '-17' , 7 , '-410338673' ) ;
119+
test( macro , '17' , 9 , '118587876497' ) ;
120+
test( macro , '-17' , 9 , '-118587876497' ) ;
121+
test( macro , '17' , 11 , '34271896307633' ) ;
122+
test( macro , '-17' , 11 , '-34271896307633' ) ;
123+
test( macro , '17' , 17 , '827240261886336764177' ) ;
124+
test( macro , '-17' , 17 , '-827240261886336764177' ) ;
125+
test( macro , '17' , 22 , '1174562876521148458974062689' ) ;
126+
test( macro , '-17' , 22 , '1174562876521148458974062689' ) ;
127+
test( macro , '17' , 24 , '339448671314611904643504117121' ) ;
128+
test( macro , '-17' , 24 , '339448671314611904643504117121' ) ;
129+
test( macro , '17' , 27 , '1667711322168688287513535727415473' ) ;
130+
test( macro , '-17' , 27 , '-1667711322168688287513535727415473' ) ;
131+
test( macro , '17' , 29 , '481968572106750915091411825223071697' ) ;
132+
test( macro , '-17' , 29 , '-481968572106750915091411825223071697' ) ;
133+
test( macro , '22' , 1 , '22' ) ;
134+
test( macro , '-22' , 1 , '-22' ) ;
135+
test( macro , '22' , 3 , '10648' ) ;
136+
test( macro , '-22' , 3 , '-10648' ) ;
137+
test( macro , '22' , 7 , '2494357888' ) ;
138+
test( macro , '-22' , 7 , '-2494357888' ) ;
139+
test( macro , '22' , 9 , '1207269217792' ) ;
140+
test( macro , '-22' , 9 , '-1207269217792' ) ;
141+
test( macro , '22' , 11 , '584318301411328' ) ;
142+
test( macro , '-22' , 11 , '-584318301411328' ) ;
143+
test( macro , '22' , 17 , '66249952919459433152512' ) ;
144+
test( macro , '-22' , 17 , '-66249952919459433152512' ) ;
145+
test( macro , '22' , 22 , '341427877364219557396646723584' ) ;
146+
test( macro , '-22' , 22 , '341427877364219557396646723584' ) ;
147+
test( macro , '22' , 24 , '165251092644282265779977014214656' ) ;
148+
test( macro , '-22' , 24 , '165251092644282265779977014214656' ) ;
149+
test( macro , '22' , 27 , '1759593634476317566025195247357657088' ) ;
150+
test( macro , '-22' , 27 , '-1759593634476317566025195247357657088' ) ;
151+
test( macro , '22' , 29 , '851643319086537701956194499721106030592' ) ;
152+
test( macro , '-22' , 29 , '-851643319086537701956194499721106030592' ) ;
153+
test( macro , '24' , 1 , '24' ) ;
154+
test( macro , '-24' , 1 , '-24' ) ;
155+
test( macro , '24' , 3 , '13824' ) ;
156+
test( macro , '-24' , 3 , '-13824' ) ;
157+
test( macro , '24' , 7 , '4586471424' ) ;
158+
test( macro , '-24' , 7 , '-4586471424' ) ;
159+
test( macro , '24' , 9 , '2641807540224' ) ;
160+
test( macro , '-24' , 9 , '-2641807540224' ) ;
161+
test( macro , '24' , 11 , '1521681143169024' ) ;
162+
test( macro , '-24' , 11 , '-1521681143169024' ) ;
163+
test( macro , '24' , 17 , '290797794982682557415424' ) ;
164+
test( macro , '-24' , 17 , '-290797794982682557415424' ) ;
165+
test( macro , '24' , 22 , '2315513501476187716057433112576' ) ;
166+
test( macro , '-24' , 22 , '2315513501476187716057433112576' ) ;
167+
test( macro , '24' , 24 , '1333735776850284124449081472843776' ) ;
168+
test( macro , '-24' , 24 , '1333735776850284124449081472843776' ) ;
169+
test( macro , '24' , 27 , '18437563379178327736384102280592359424' ) ;
170+
test( macro , '-24' , 27 , '-18437563379178327736384102280592359424' ) ;
171+
test( macro , '24' , 29 , '10620036506406716776157242913621199028224' ) ;
172+
test( macro , '-24' , 29 , '-10620036506406716776157242913621199028224' ) ;
173+
test( macro , '27' , 1 , '27' ) ;
174+
test( macro , '-27' , 1 , '-27' ) ;
175+
test( macro , '27' , 3 , '19683' ) ;
176+
test( macro , '-27' , 3 , '-19683' ) ;
177+
test( macro , '27' , 7 , '10460353203' ) ;
178+
test( macro , '-27' , 7 , '-10460353203' ) ;
179+
test( macro , '27' , 9 , '7625597484987' ) ;
180+
test( macro , '-27' , 9 , '-7625597484987' ) ;
181+
test( macro , '27' , 11 , '5559060566555523' ) ;
182+
test( macro , '-27' , 11 , '-5559060566555523' ) ;
183+
test( macro , '27' , 17 , '2153693963075557766310747' ) ;
184+
test( macro , '-27' , 17 , '-2153693963075557766310747' ) ;
185+
test( macro , '27' , 22 , '30903154382632612361920641803529' ) ;
186+
test( macro , '-27' , 22 , '30903154382632612361920641803529' ) ;
187+
test( macro , '27' , 24 , '22528399544939174411840147874772641' ) ;
188+
test( macro , '-27' , 24 , '22528399544939174411840147874772641' ) ;
189+
test( macro , '27' , 27 , '443426488243037769948249630619149892803' ) ;
190+
test( macro , '-27' , 27 , '-443426488243037769948249630619149892803' ) ;
191+
test( macro , '27' , 29 , '323257909929174534292273980721360271853387' ) ;
192+
test( macro , '-27' , 29 , '-323257909929174534292273980721360271853387' ) ;
193+
test( macro , '29' , 1 , '29' ) ;
194+
test( macro , '-29' , 1 , '-29' ) ;
195+
test( macro , '29' , 3 , '24389' ) ;
196+
test( macro , '-29' , 3 , '-24389' ) ;
197+
test( macro , '29' , 7 , '17249876309' ) ;
198+
test( macro , '-29' , 7 , '-17249876309' ) ;
199+
test( macro , '29' , 9 , '14507145975869' ) ;
200+
test( macro , '-29' , 9 , '-14507145975869' ) ;
201+
test( macro , '29' , 11 , '12200509765705829' ) ;
202+
test( macro , '-29' , 11 , '-12200509765705829' ) ;
203+
test( macro , '29' , 17 , '7257147736730073114838109' ) ;
204+
test( macro , '-29' , 17 , '-7257147736730073114838109' ) ;
205+
test( macro , '29' , 22 , '148852438543083302439338564577241' ) ;
206+
test( macro , '-29' , 22 , '148852438543083302439338564577241' ) ;
207+
test( macro , '29' , 24 , '125184900814733057351483732809459681' ) ;
208+
test( macro , '-29' , 24 , '125184900814733057351483732809459681' ) ;
209+
test( macro , '29' , 27 , '3053134545970524535745336759489912159909' ) ;
210+
test( macro , '-29' , 27 , '-3053134545970524535745336759489912159909' ) ;
211+
test( macro , '29' , 29 , '2567686153161211134561828214731016126483469' ) ;
212+
test( macro , '-29' , 29 , '-2567686153161211134561828214731016126483469' ) ;

0 commit comments

Comments
 (0)