1
- import operator
2
-
3
1
MAX_NUMBER = 2 ** 53 - 1
4
2
MIN_NUMBER = - 2 ** 53
5
3
14
12
arithmetic = {
15
13
'add' : {
16
14
'numbers' : smallnumbers + hugenumbers ,
17
- 'apply' : operator . add ,
15
+ 'apply' : lambda a , b : ( a + b ,) ,
18
16
'str' : '+'
19
17
} ,
20
18
'sub' : {
21
19
'numbers' : smallnumbers + hugenumbers ,
22
- 'apply' : operator . sub ,
20
+ 'apply' : lambda a , b : ( a - b ,) ,
23
21
'str' : '-'
24
22
} ,
25
23
'mul' : {
26
24
'numbers' : smallnumbers + hugenumbers ,
27
- 'apply' : operator . mul ,
25
+ 'apply' : lambda a , b : ( a * b ,) ,
28
26
'str' : '*'
29
27
} ,
30
28
'pow' : {
31
29
'numbers' : smallnumbers ,
32
- 'apply' : operator . pow ,
30
+ 'apply' : lambda a , b : ( a ** b ,) ,
33
31
'str' : '^'
34
32
} ,
35
33
'div' : {
36
34
'numbers' : smallnumbers + hugenumbers ,
37
- 'apply' : operator . floordiv ,
35
+ 'apply' : lambda a , b : ( a // b ,) ,
38
36
'str' : '/'
39
37
} ,
40
38
'mod' : {
41
39
'numbers' : smallnumbers + hugenumbers ,
42
- 'apply' : operator . mod ,
40
+ 'apply' : lambda a , b : ( a % b ,) ,
43
41
'str' : '%'
44
- }
42
+ } ,
43
+ 'divmod' : {
44
+ 'numbers' : smallnumbers + hugenumbers ,
45
+ 'apply' : lambda a , b : (a // b , a % b ) ,
46
+ 'str' : '/%'
47
+ } ,
45
48
}
46
49
47
50
def write ( f , numbers , name , t , ispow = False , isn = False , isi = False ) :
48
51
52
+ outputsize = 2 if 'divmod' in name else 1
53
+
49
54
f .write ("import test from 'ava' ;\n " )
50
55
f .write ("import {{ parse , stringify , {} }} from '../../../../src' ;\n \n " .format (name ))
51
56
52
- if isn :
57
+ if outputsize == 2 :
58
+
59
+ if isn :
60
+
61
+ f .write ("""function macro ( t , A , B , C , D ) {{
62
+ const a = parse( A ) ;
63
+ const [c, d] = {}( a , B ) ;
64
+ t.is( stringify( a ) , {} ) ;
65
+ t.is( stringify( c ) , C ) ;
66
+ t.is( stringify( d ) , D ) ;
67
+ }}\n \n """ .format ( name , 'D' if isi else 'A' ) )
68
+
69
+ else :
70
+
71
+ f .write ("""function macro ( t , A , B , C , D ) {{
72
+ const a = parse( A ) ;
73
+ const b = parse( B ) ;
74
+ const [c, d] = {}( a , b ) ;
75
+ t.is( stringify( a ) , {} ) ;
76
+ t.is( stringify( b ) , B ) ;
77
+ t.is( stringify( c ) , C ) ;
78
+ t.is( stringify( d ) , D ) ;
79
+ }}\n \n """ .format ( name , 'D' if isi else 'A' ) )
80
+
81
+ else :
53
82
54
- f .write ("""function macro ( t , A , B , C ) {{
83
+ if isn :
84
+
85
+ f .write ("""function macro ( t , A , B , C ) {{
55
86
const a = parse( A ) ;
56
87
const c = {}( a , B ) ;
57
88
t.is( stringify( a ) , {} ) ;
58
89
t.is( stringify( c ) , C ) ;
59
90
}}\n \n """ .format ( name , 'C' if isi else 'A' ) )
60
91
61
- else :
92
+ else :
62
93
63
- f .write ("""function macro ( t , A , B , C ) {{
94
+ f .write ("""function macro ( t , A , B , C ) {{
64
95
const a = parse( A ) ;
65
96
const b = parse( B ) ;
66
97
const c = {}( a , b ) ;
@@ -70,12 +101,23 @@ def write ( f , numbers , name , t , ispow = False , isn = False , isi = False)
70
101
}}\n \n """ .format ( name , 'C' if isi else 'A' ) )
71
102
72
103
73
- f .write ("macro.title = ( _ , A , B , C ) => `{}(${{A}},${{B}}) = ${{C}}` ;\n \n " .format (name ))
104
+ if outputsize == 2 :
105
+
106
+ f .write ("macro.title = ( _ , A , B , C , D ) => `{}(${{A}},${{B}}) = [${{C}},${{D}}]` ;\n \n " .format (name ))
107
+
108
+ if isn :
109
+ LINE = "test( macro , '{}' , {} , '{}' , '{}' ) ;\n "
110
+ else :
111
+ LINE = "test( macro , '{}' , '{}' , '{}' , '{}' ) ;\n "
74
112
75
- if isn :
76
- LINE = "test( macro , '{}' , {} , '{}' ) ;\n "
77
113
else :
78
- LINE = "test( macro , '{}' , '{}' , '{}' ) ;\n "
114
+
115
+ f .write ("macro.title = ( _ , A , B , C ) => `{}(${{A}},${{B}}) = ${{C}}` ;\n \n " .format (name ))
116
+
117
+ if isn :
118
+ LINE = "test( macro , '{}' , {} , '{}' ) ;\n "
119
+ else :
120
+ LINE = "test( macro , '{}' , '{}' , '{}' ) ;\n "
79
121
80
122
for a in numbers :
81
123
@@ -85,27 +127,27 @@ def write ( f , numbers , name , t , ispow = False , isn = False , isi = False)
85
127
y = b
86
128
c = t ( x , y )
87
129
if not isn or MIN_NUMBER <= y <= MAX_NUMBER :
88
- f .write (LINE .format (x ,y ,c ))
130
+ f .write (LINE .format (x ,y ,* c ))
89
131
90
132
x = - a
91
133
y = b
92
134
c = t ( x , y )
93
135
if not isn or MIN_NUMBER <= y <= MAX_NUMBER :
94
- f .write (LINE .format (x ,y ,c ))
136
+ f .write (LINE .format (x ,y ,* c ))
95
137
96
138
if not ispow :
97
139
98
140
x = a
99
141
y = - b
100
142
c = t ( x , y )
101
143
if not isn or MIN_NUMBER <= y <= MAX_NUMBER :
102
- f .write (LINE .format (x ,y ,c ))
144
+ f .write (LINE .format (x ,y ,* c ))
103
145
104
146
x = - a
105
147
y = - b
106
148
c = t ( x , y )
107
149
if not isn or MIN_NUMBER <= y <= MAX_NUMBER :
108
- f .write (LINE .format (x ,y ,c ))
150
+ f .write (LINE .format (x ,y ,* c ))
109
151
110
152
def open_and_write ( opname , t , nb , ** kwargs ) :
111
153
with open ( 'test/src/integer/arithmetic/{}.js' .format (opname ) , 'w' ) as f :
0 commit comments