Skip to content

Commit 731a322

Browse files
🔍 test: Add more generated tests.
1 parent 8ae527e commit 731a322

29 files changed

+1923
-32
lines changed

test/generate.py

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,51 @@
2424

2525
smallnumbers = sorted([ 1 , 3 , 7 , 9 , 11 , 17 , 22 , 24 , 27 , 29 , 1234 , 5678 ])
2626

27+
zero = [0]
28+
2729
arithmetic = {
2830
'add' : {
29-
'numbers' : smallnumbers + hugenumbers ,
31+
'numbers' : zero + smallnumbers + hugenumbers ,
3032
'apply' : lambda a,b: (a+b,) ,
3133
'str' : '+'
3234
} ,
3335
'sub' : {
34-
'numbers' : smallnumbers + hugenumbers ,
36+
'numbers' : zero + smallnumbers + hugenumbers ,
3537
'apply' : lambda a,b: (a-b,) ,
3638
'str' : '-'
3739
} ,
3840
'mul' : {
39-
'numbers' : smallnumbers + hugenumbers ,
41+
'numbers' : zero + smallnumbers + hugenumbers ,
4042
'apply' : lambda a,b: (a*b,) ,
4143
'str' : '*'
4244
} ,
4345
'pow' : {
44-
'numbers' : smallnumbers ,
46+
'left' : zero + smallnumbers + hugenumbers ,
47+
'right' : zero + smallnumbers ,
4548
'apply' : lambda a,b: (a**b,) ,
4649
'str' : '^'
4750
} ,
4851
'div' : {
49-
'numbers' : smallnumbers + hugenumbers ,
52+
'left' : zero + smallnumbers + hugenumbers ,
53+
'right' : smallnumbers + hugenumbers ,
5054
'apply' : lambda a,b: (a//b,) ,
5155
'str' : '/'
5256
} ,
5357
'mod' : {
54-
'numbers' : smallnumbers + hugenumbers ,
58+
'left' : zero + smallnumbers + hugenumbers ,
59+
'right' : smallnumbers + hugenumbers ,
5560
'apply' : lambda a,b: (a%b,) ,
5661
'str' : '%'
5762
} ,
5863
'divmod' : {
59-
'numbers' : smallnumbers + hugenumbers ,
64+
'left' : zero + smallnumbers + hugenumbers ,
65+
'right' : smallnumbers + hugenumbers ,
6066
'apply' : lambda a, b: (a // b, a % b) ,
6167
'str' : '/%'
6268
} ,
6369
}
6470

65-
def write ( f , numbers , name , t , ispow = False , isn = False , isi = False) :
71+
def write ( f , left, right , name , t , ispow = False , isn = False , isi = False) :
6672

6773
outputsize = 2 if 'divmod' in name else 1
6874

@@ -134,52 +140,57 @@ def write ( f , numbers , name , t , ispow = False , isn = False , isi = False)
134140
else:
135141
LINE = "test( macro , '{}' , '{}' , '{}' ) ;\n"
136142

137-
for a in numbers :
143+
for a in left :
138144

139-
for b in numbers :
145+
for b in right :
140146

141147
x = a
142148
y = b
143149
c = t( x , y )
144150
if not isn or MIN_NUMBER <= y <= MAX_NUMBER:
145151
f.write(LINE.format(x,y,*c))
146152

147-
x = -a
148-
y = b
149-
c = t( x , y )
150-
if not isn or MIN_NUMBER <= y <= MAX_NUMBER:
151-
f.write(LINE.format(x,y,*c))
152-
153-
if not ispow:
154-
155-
x = a
156-
y = -b
157-
c = t( x , y )
158-
if not isn or MIN_NUMBER <= y <= MAX_NUMBER:
159-
f.write(LINE.format(x,y,*c))
160-
153+
if a != 0:
161154
x = -a
162-
y = -b
155+
y = b
163156
c = t( x , y )
164157
if not isn or MIN_NUMBER <= y <= MAX_NUMBER:
165158
f.write(LINE.format(x,y,*c))
166159

167-
def open_and_write ( opname , t , nb , **kwargs ) :
160+
if not ispow:
161+
162+
if b != 0:
163+
x = a
164+
y = -b
165+
c = t( x , y )
166+
if not isn or MIN_NUMBER <= y <= MAX_NUMBER:
167+
f.write(LINE.format(x,y,*c))
168+
169+
if a != 0:
170+
x = -a
171+
y = -b
172+
c = t( x , y )
173+
if not isn or MIN_NUMBER <= y <= MAX_NUMBER:
174+
f.write(LINE.format(x,y,*c))
175+
176+
def open_and_write ( opname , t , left , right , **kwargs ) :
168177
with open( 'test/src/integer/arithmetic/{}.js'.format(opname) , 'w' ) as f :
169-
write( f , nb , opname , t , **kwargs )
178+
write( f , left , right , opname , t , **kwargs )
170179

171180
for name , op in arithmetic.items():
172181

173182
t = op['apply']
174-
nb = op['numbers']
183+
184+
left = op.get('left', op.get('numbers'))
185+
right = op.get('right', op.get('numbers'))
175186

176187
ispow = name == 'pow'
177188

178189
# standard op
179-
open_and_write( name , t , nb , ispow = ispow )
190+
open_and_write( name , t , left , right , ispow = ispow )
180191
# in-place op
181-
open_and_write( 'i' + name , t , nb , isi = True , ispow = ispow )
192+
open_and_write( 'i' + name , t , left , right , isi = True , ispow = ispow )
182193
# standard op with number arg
183-
open_and_write( name + 'n' , t , nb , isn = True , ispow = ispow )
194+
open_and_write( name + 'n' , t , left , right , isn = True , ispow = ispow )
184195
# in-place op with number arg
185-
open_and_write( 'i' + name + 'n' , t , nb , isi = True , isn = True , ispow = ispow )
196+
open_and_write( 'i' + name + 'n' , t , left , right , isi = True , isn = True , ispow = ispow )

test/src/integer/arithmetic/add.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,43 @@ function macro ( t , A , B , C ) {
1212

1313
macro.title = ( _ , A , B , C ) => `add(${A},${B}) = ${C}` ;
1414

15+
test( macro , '0' , '0' , '0' ) ;
16+
test( macro , '0' , '1' , '1' ) ;
17+
test( macro , '0' , '-1' , '-1' ) ;
18+
test( macro , '0' , '3' , '3' ) ;
19+
test( macro , '0' , '-3' , '-3' ) ;
20+
test( macro , '0' , '7' , '7' ) ;
21+
test( macro , '0' , '-7' , '-7' ) ;
22+
test( macro , '0' , '9' , '9' ) ;
23+
test( macro , '0' , '-9' , '-9' ) ;
24+
test( macro , '0' , '11' , '11' ) ;
25+
test( macro , '0' , '-11' , '-11' ) ;
26+
test( macro , '0' , '17' , '17' ) ;
27+
test( macro , '0' , '-17' , '-17' ) ;
28+
test( macro , '0' , '22' , '22' ) ;
29+
test( macro , '0' , '-22' , '-22' ) ;
30+
test( macro , '0' , '24' , '24' ) ;
31+
test( macro , '0' , '-24' , '-24' ) ;
32+
test( macro , '0' , '27' , '27' ) ;
33+
test( macro , '0' , '-27' , '-27' ) ;
34+
test( macro , '0' , '29' , '29' ) ;
35+
test( macro , '0' , '-29' , '-29' ) ;
36+
test( macro , '0' , '1234' , '1234' ) ;
37+
test( macro , '0' , '-1234' , '-1234' ) ;
38+
test( macro , '0' , '5678' , '5678' ) ;
39+
test( macro , '0' , '-5678' , '-5678' ) ;
40+
test( macro , '0' , '94906265' , '94906265' ) ;
41+
test( macro , '0' , '-94906265' , '-94906265' ) ;
42+
test( macro , '0' , '94906266' , '94906266' ) ;
43+
test( macro , '0' , '-94906266' , '-94906266' ) ;
44+
test( macro , '0' , '1073741824' , '1073741824' ) ;
45+
test( macro , '0' , '-1073741824' , '-1073741824' ) ;
46+
test( macro , '0' , '51676101935731' , '51676101935731' ) ;
47+
test( macro , '0' , '-51676101935731' , '-51676101935731' ) ;
48+
test( macro , '0' , '717897987691852588770249' , '717897987691852588770249' ) ;
49+
test( macro , '0' , '-717897987691852588770249' , '-717897987691852588770249' ) ;
50+
test( macro , '1' , '0' , '1' ) ;
51+
test( macro , '-1' , '0' , '-1' ) ;
1552
test( macro , '1' , '1' , '2' ) ;
1653
test( macro , '-1' , '1' , '0' ) ;
1754
test( macro , '1' , '-1' , '0' ) ;
@@ -80,6 +117,8 @@ test( macro , '1' , '717897987691852588770249' , '717897987691852588770250' ) ;
80117
test( macro , '-1' , '717897987691852588770249' , '717897987691852588770248' ) ;
81118
test( macro , '1' , '-717897987691852588770249' , '-717897987691852588770248' ) ;
82119
test( macro , '-1' , '-717897987691852588770249' , '-717897987691852588770250' ) ;
120+
test( macro , '3' , '0' , '3' ) ;
121+
test( macro , '-3' , '0' , '-3' ) ;
83122
test( macro , '3' , '1' , '4' ) ;
84123
test( macro , '-3' , '1' , '-2' ) ;
85124
test( macro , '3' , '-1' , '2' ) ;
@@ -148,6 +187,8 @@ test( macro , '3' , '717897987691852588770249' , '717897987691852588770252' ) ;
148187
test( macro , '-3' , '717897987691852588770249' , '717897987691852588770246' ) ;
149188
test( macro , '3' , '-717897987691852588770249' , '-717897987691852588770246' ) ;
150189
test( macro , '-3' , '-717897987691852588770249' , '-717897987691852588770252' ) ;
190+
test( macro , '7' , '0' , '7' ) ;
191+
test( macro , '-7' , '0' , '-7' ) ;
151192
test( macro , '7' , '1' , '8' ) ;
152193
test( macro , '-7' , '1' , '-6' ) ;
153194
test( macro , '7' , '-1' , '6' ) ;
@@ -216,6 +257,8 @@ test( macro , '7' , '717897987691852588770249' , '717897987691852588770256' ) ;
216257
test( macro , '-7' , '717897987691852588770249' , '717897987691852588770242' ) ;
217258
test( macro , '7' , '-717897987691852588770249' , '-717897987691852588770242' ) ;
218259
test( macro , '-7' , '-717897987691852588770249' , '-717897987691852588770256' ) ;
260+
test( macro , '9' , '0' , '9' ) ;
261+
test( macro , '-9' , '0' , '-9' ) ;
219262
test( macro , '9' , '1' , '10' ) ;
220263
test( macro , '-9' , '1' , '-8' ) ;
221264
test( macro , '9' , '-1' , '8' ) ;
@@ -284,6 +327,8 @@ test( macro , '9' , '717897987691852588770249' , '717897987691852588770258' ) ;
284327
test( macro , '-9' , '717897987691852588770249' , '717897987691852588770240' ) ;
285328
test( macro , '9' , '-717897987691852588770249' , '-717897987691852588770240' ) ;
286329
test( macro , '-9' , '-717897987691852588770249' , '-717897987691852588770258' ) ;
330+
test( macro , '11' , '0' , '11' ) ;
331+
test( macro , '-11' , '0' , '-11' ) ;
287332
test( macro , '11' , '1' , '12' ) ;
288333
test( macro , '-11' , '1' , '-10' ) ;
289334
test( macro , '11' , '-1' , '10' ) ;
@@ -352,6 +397,8 @@ test( macro , '11' , '717897987691852588770249' , '717897987691852588770260' ) ;
352397
test( macro , '-11' , '717897987691852588770249' , '717897987691852588770238' ) ;
353398
test( macro , '11' , '-717897987691852588770249' , '-717897987691852588770238' ) ;
354399
test( macro , '-11' , '-717897987691852588770249' , '-717897987691852588770260' ) ;
400+
test( macro , '17' , '0' , '17' ) ;
401+
test( macro , '-17' , '0' , '-17' ) ;
355402
test( macro , '17' , '1' , '18' ) ;
356403
test( macro , '-17' , '1' , '-16' ) ;
357404
test( macro , '17' , '-1' , '16' ) ;
@@ -420,6 +467,8 @@ test( macro , '17' , '717897987691852588770249' , '717897987691852588770266' ) ;
420467
test( macro , '-17' , '717897987691852588770249' , '717897987691852588770232' ) ;
421468
test( macro , '17' , '-717897987691852588770249' , '-717897987691852588770232' ) ;
422469
test( macro , '-17' , '-717897987691852588770249' , '-717897987691852588770266' ) ;
470+
test( macro , '22' , '0' , '22' ) ;
471+
test( macro , '-22' , '0' , '-22' ) ;
423472
test( macro , '22' , '1' , '23' ) ;
424473
test( macro , '-22' , '1' , '-21' ) ;
425474
test( macro , '22' , '-1' , '21' ) ;
@@ -488,6 +537,8 @@ test( macro , '22' , '717897987691852588770249' , '717897987691852588770271' ) ;
488537
test( macro , '-22' , '717897987691852588770249' , '717897987691852588770227' ) ;
489538
test( macro , '22' , '-717897987691852588770249' , '-717897987691852588770227' ) ;
490539
test( macro , '-22' , '-717897987691852588770249' , '-717897987691852588770271' ) ;
540+
test( macro , '24' , '0' , '24' ) ;
541+
test( macro , '-24' , '0' , '-24' ) ;
491542
test( macro , '24' , '1' , '25' ) ;
492543
test( macro , '-24' , '1' , '-23' ) ;
493544
test( macro , '24' , '-1' , '23' ) ;
@@ -556,6 +607,8 @@ test( macro , '24' , '717897987691852588770249' , '717897987691852588770273' ) ;
556607
test( macro , '-24' , '717897987691852588770249' , '717897987691852588770225' ) ;
557608
test( macro , '24' , '-717897987691852588770249' , '-717897987691852588770225' ) ;
558609
test( macro , '-24' , '-717897987691852588770249' , '-717897987691852588770273' ) ;
610+
test( macro , '27' , '0' , '27' ) ;
611+
test( macro , '-27' , '0' , '-27' ) ;
559612
test( macro , '27' , '1' , '28' ) ;
560613
test( macro , '-27' , '1' , '-26' ) ;
561614
test( macro , '27' , '-1' , '26' ) ;
@@ -624,6 +677,8 @@ test( macro , '27' , '717897987691852588770249' , '717897987691852588770276' ) ;
624677
test( macro , '-27' , '717897987691852588770249' , '717897987691852588770222' ) ;
625678
test( macro , '27' , '-717897987691852588770249' , '-717897987691852588770222' ) ;
626679
test( macro , '-27' , '-717897987691852588770249' , '-717897987691852588770276' ) ;
680+
test( macro , '29' , '0' , '29' ) ;
681+
test( macro , '-29' , '0' , '-29' ) ;
627682
test( macro , '29' , '1' , '30' ) ;
628683
test( macro , '-29' , '1' , '-28' ) ;
629684
test( macro , '29' , '-1' , '28' ) ;
@@ -692,6 +747,8 @@ test( macro , '29' , '717897987691852588770249' , '717897987691852588770278' ) ;
692747
test( macro , '-29' , '717897987691852588770249' , '717897987691852588770220' ) ;
693748
test( macro , '29' , '-717897987691852588770249' , '-717897987691852588770220' ) ;
694749
test( macro , '-29' , '-717897987691852588770249' , '-717897987691852588770278' ) ;
750+
test( macro , '1234' , '0' , '1234' ) ;
751+
test( macro , '-1234' , '0' , '-1234' ) ;
695752
test( macro , '1234' , '1' , '1235' ) ;
696753
test( macro , '-1234' , '1' , '-1233' ) ;
697754
test( macro , '1234' , '-1' , '1233' ) ;
@@ -760,6 +817,8 @@ test( macro , '1234' , '717897987691852588770249' , '717897987691852588771483' )
760817
test( macro , '-1234' , '717897987691852588770249' , '717897987691852588769015' ) ;
761818
test( macro , '1234' , '-717897987691852588770249' , '-717897987691852588769015' ) ;
762819
test( macro , '-1234' , '-717897987691852588770249' , '-717897987691852588771483' ) ;
820+
test( macro , '5678' , '0' , '5678' ) ;
821+
test( macro , '-5678' , '0' , '-5678' ) ;
763822
test( macro , '5678' , '1' , '5679' ) ;
764823
test( macro , '-5678' , '1' , '-5677' ) ;
765824
test( macro , '5678' , '-1' , '5677' ) ;
@@ -828,6 +887,8 @@ test( macro , '5678' , '717897987691852588770249' , '717897987691852588775927' )
828887
test( macro , '-5678' , '717897987691852588770249' , '717897987691852588764571' ) ;
829888
test( macro , '5678' , '-717897987691852588770249' , '-717897987691852588764571' ) ;
830889
test( macro , '-5678' , '-717897987691852588770249' , '-717897987691852588775927' ) ;
890+
test( macro , '94906265' , '0' , '94906265' ) ;
891+
test( macro , '-94906265' , '0' , '-94906265' ) ;
831892
test( macro , '94906265' , '1' , '94906266' ) ;
832893
test( macro , '-94906265' , '1' , '-94906264' ) ;
833894
test( macro , '94906265' , '-1' , '94906264' ) ;
@@ -896,6 +957,8 @@ test( macro , '94906265' , '717897987691852588770249' , '71789798769185268367651
896957
test( macro , '-94906265' , '717897987691852588770249' , '717897987691852493863984' ) ;
897958
test( macro , '94906265' , '-717897987691852588770249' , '-717897987691852493863984' ) ;
898959
test( macro , '-94906265' , '-717897987691852588770249' , '-717897987691852683676514' ) ;
960+
test( macro , '94906266' , '0' , '94906266' ) ;
961+
test( macro , '-94906266' , '0' , '-94906266' ) ;
899962
test( macro , '94906266' , '1' , '94906267' ) ;
900963
test( macro , '-94906266' , '1' , '-94906265' ) ;
901964
test( macro , '94906266' , '-1' , '94906265' ) ;
@@ -964,6 +1027,8 @@ test( macro , '94906266' , '717897987691852588770249' , '71789798769185268367651
9641027
test( macro , '-94906266' , '717897987691852588770249' , '717897987691852493863983' ) ;
9651028
test( macro , '94906266' , '-717897987691852588770249' , '-717897987691852493863983' ) ;
9661029
test( macro , '-94906266' , '-717897987691852588770249' , '-717897987691852683676515' ) ;
1030+
test( macro , '1073741824' , '0' , '1073741824' ) ;
1031+
test( macro , '-1073741824' , '0' , '-1073741824' ) ;
9671032
test( macro , '1073741824' , '1' , '1073741825' ) ;
9681033
test( macro , '-1073741824' , '1' , '-1073741823' ) ;
9691034
test( macro , '1073741824' , '-1' , '1073741823' ) ;
@@ -1032,6 +1097,8 @@ test( macro , '1073741824' , '717897987691852588770249' , '717897987691853662512
10321097
test( macro , '-1073741824' , '717897987691852588770249' , '717897987691851515028425' ) ;
10331098
test( macro , '1073741824' , '-717897987691852588770249' , '-717897987691851515028425' ) ;
10341099
test( macro , '-1073741824' , '-717897987691852588770249' , '-717897987691853662512073' ) ;
1100+
test( macro , '51676101935731' , '0' , '51676101935731' ) ;
1101+
test( macro , '-51676101935731' , '0' , '-51676101935731' ) ;
10351102
test( macro , '51676101935731' , '1' , '51676101935732' ) ;
10361103
test( macro , '-51676101935731' , '1' , '-51676101935730' ) ;
10371104
test( macro , '51676101935731' , '-1' , '51676101935730' ) ;
@@ -1100,6 +1167,8 @@ test( macro , '51676101935731' , '717897987691852588770249' , '71789798774352869
11001167
test( macro , '-51676101935731' , '717897987691852588770249' , '717897987640176486834518' ) ;
11011168
test( macro , '51676101935731' , '-717897987691852588770249' , '-717897987640176486834518' ) ;
11021169
test( macro , '-51676101935731' , '-717897987691852588770249' , '-717897987743528690705980' ) ;
1170+
test( macro , '717897987691852588770249' , '0' , '717897987691852588770249' ) ;
1171+
test( macro , '-717897987691852588770249' , '0' , '-717897987691852588770249' ) ;
11031172
test( macro , '717897987691852588770249' , '1' , '717897987691852588770250' ) ;
11041173
test( macro , '-717897987691852588770249' , '1' , '-717897987691852588770248' ) ;
11051174
test( macro , '717897987691852588770249' , '-1' , '717897987691852588770248' ) ;

0 commit comments

Comments
 (0)