File: ariths.tst

package info (click to toggle)
gap 4.15.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 110,212 kB
  • sloc: ansic: 97,261; xml: 48,343; cpp: 13,946; sh: 4,900; perl: 1,650; javascript: 255; makefile: 252; ruby: 9
file content (444 lines) | stat: -rw-r--r-- 10,356 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#
# Tests for functions defined in src/ariths.c
#
gap> START_TEST("kernel/ariths.tst");

# InUndefined
gap> 1 in 2;
Error, operations: IN of integer and integer is not defined

# SUM, DIFF, PROD, QUO
gap> SUM(1,1);
2
gap> DIFF(1,1);
0
gap> PROD(1,1);
1
gap> QUO(1,1);
1
gap> MOD(1,1);
0

#
# suppress paths in trace output
#
gap> old_VMETHOD_PRINT_INFO:=VMETHOD_PRINT_INFO;;
gap> old_NEXT_VMETHOD_PRINT_INFO:=NEXT_VMETHOD_PRINT_INFO;;
gap> MakeReadWriteGlobal("VMETHOD_PRINT_INFO");
gap> MakeReadWriteGlobal("NEXT_VMETHOD_PRINT_INFO");
gap> VMETHOD_PRINT_INFO:=function(methods, i, arity)
>     local offset;
>     offset := (arity+BASE_SIZE_METHODS_OPER_ENTRY)*(i-1)+arity;
>     Print("#I  ", methods[offset+4]);
>     Print("\n");
> end;;
gap> NEXT_VMETHOD_PRINT_INFO:=function(methods, i, arity)
>     local offset;
>     offset := (arity+BASE_SIZE_METHODS_OPER_ENTRY)*(i-1)+arity;
>     Print("#I Trying next: ", methods[offset+4]);
>     Print("\n");
> end;;

#
# Test the various "VerboseFOO" handlers; to this end, create a mock family,
# category and type, and two instances of that, so that we can safely test all
# involved unary and binary operations
#
gap> fam := NewFamily("MockFamily");;
gap> cat := NewCategory("IsMockObj",
>               IsMultiplicativeElementWithInverse and
>               IsAdditiveElementWithInverse and
>               IsCommutativeElement and
>               IsAssociativeElement and
>               IsAdditivelyCommutativeElement);;
gap> type := NewType(fam, cat and IsPositionalObjectRep);;
gap> a := Objectify(type,[2]);;
gap> b := Objectify(type,[3]);;

# unary
gap> unary := [
>   Zero,
>   ZeroMutable,
>   ZeroSameMutability,
>   AdditiveInverse,
>   AdditiveInverseMutable,
>   AdditiveInverseSameMutability,
>   One,
>   OneMutable,
>   OneSameMutability,
>   Inverse,
>   InverseMutable,
>   InverseSameMutability,
> ];;

# binary
gap> binary := [
>   \=,
>   \<,
>   \in,
>   \+,
>   \-,
>   \*,
>   \/,
>   LeftQuotient,
>   \^,
>   Comm,
>   \mod,
> ];;

#
# test with regular methods
#
gap> for m in unary do InstallMethod(m, [cat], ReturnTrue); od;
gap> for m in binary do InstallMethod(m, [cat, cat], ReturnTrue); od;
gap> InstallMethod(SetZeroImmutable, [cat, IsObject], ReturnNothing);
gap> InstallMethod(SetAdditiveInverseImmutable, [cat, IsObject], ReturnNothing);
gap> InstallMethod(SetOneImmutable, [cat, IsObject], ReturnNothing);
gap> InstallMethod(SetInverseImmutable, [cat, IsObject], ReturnNothing);

# ... and also involving TryNextMethod
gap> for m in unary do InstallMethod(m, [cat], 1, function(x) TryNextMethod(); end); od;
gap> for m in binary do InstallMethod(m, [cat, cat], 1, function(x,y) TryNextMethod(); end); od;

#
gap> 0*a;
true
gap> Zero(a);
true
gap> ZeroMutable(a);
true
gap> ZeroSameMutability(a);
true
gap> -a;
true
gap> AdditiveInverse(a);
true
gap> AdditiveInverseMutable(a);
true
gap> AdditiveInverseSameMutability(a);
true
gap> a^0;
true
gap> One(a);
true
gap> OneMutable(a);
true
gap> OneSameMutability(a);
true
gap> a^-1;
true
gap> Inverse(a);
true
gap> InverseMutable(a);
true
gap> InverseSameMutability(a);
true
gap> a = b;
true
gap> a < b;
true
gap> a in b;
true
gap> a + b;
true
gap> a - b;
true
gap> a * b;
true
gap> a / b;
true
gap> LeftQuotient(a, b);
true
gap> a ^ b;
true
gap> Comm(a, b);
true
gap> a mod b;
true

#
gap> meths := Concatenation(unary, binary);;
gap> TraceMethods(meths);

#
gap> 0*a;
#I  *: zero integer * additive element with zero
#I  ZeroSameMutability
#I Trying next: ZeroSameMutability
true
gap> Zero(a);
#I  ZeroImmutable
#I Trying next: ZeroImmutable
#I  SetZeroImmutable
true
gap> ZeroMutable(a);
#I  ZeroMutable
#I Trying next: ZeroMutable
true
gap> ZeroSameMutability(a);
#I  ZeroSameMutability
#I Trying next: ZeroSameMutability
true
gap> -a;
#I  AdditiveInverseSameMutability
#I Trying next: AdditiveInverseSameMutability
true
gap> AdditiveInverse(a);
#I  AdditiveInverseImmutable
#I Trying next: AdditiveInverseImmutable
#I  SetAdditiveInverseImmutable
true
gap> AdditiveInverseMutable(a);
#I  AdditiveInverseMutable
#I Trying next: AdditiveInverseMutable
true
gap> AdditiveInverseSameMutability(a);
#I  AdditiveInverseSameMutability
#I Trying next: AdditiveInverseSameMutability
true
gap> a^0;
#I  ^: for mult. element-with-one, and zero
#I  OneSameMutability
#I Trying next: OneSameMutability
true
gap> One(a);
#I  OneImmutable
#I Trying next: OneImmutable
#I  SetOneImmutable
true
gap> OneMutable(a);
#I  OneMutable
#I Trying next: OneMutable
true
gap> OneSameMutability(a);
#I  OneSameMutability
#I Trying next: OneSameMutability
true
gap> a^-1;
#I  ^: for mult. element-with-inverse, and negative integer
#I  InverseSameMutability
#I Trying next: InverseSameMutability
true
gap> Inverse(a);
#I  InverseImmutable
#I Trying next: InverseImmutable
#I  SetInverseImmutable
true
gap> InverseMutable(a);
#I  InverseMutable
#I Trying next: InverseMutable
true
gap> InverseSameMutability(a);
#I  InverseSameMutability
#I Trying next: InverseSameMutability
true
gap> a = b;
#I  =
#I Trying next: =
true
gap> a < b;
#I  <
#I Trying next: <
true
gap> a in b;
#I  in
#I Trying next: in
true
gap> a + b;
#I  +
#I Trying next: +
true
gap> a - b;
#I  -
#I Trying next: -
true
gap> a * b;
#I  *
#I Trying next: *
true
gap> a / b;
#I  /
#I Trying next: /
true
gap> LeftQuotient(a, b);
true
gap> a ^ b;
#I  ^
#I Trying next: ^
true
gap> Comm(a, b);
#I  Comm
#I Trying next: Comm
true
gap> a mod b;
#I  mod
#I Trying next: mod
true

#
gap> UntraceMethods(meths);

#
# test "method should have returned a value" checks
#
gap> for m in unary do InstallMethod(m, [cat], 2, ReturnNothing); od;
gap> for m in binary do InstallMethod(m, [cat, cat], 2, ReturnNothing); od;

#
gap> 0*a;
Error, ZeroSameMutability: method should have returned a value
gap> Zero(a);
Error, Method for an attribute must return a value
gap> ZeroMutable(a);
Error, ZeroOp: method should have returned a value
gap> ZeroSameMutability(a);
Error, ZeroSameMutability: method should have returned a value
gap> -a;
Error, AdditiveInverseSameMutability: method should have returned a value
gap> AdditiveInverse(a);
Error, Method for an attribute must return a value
gap> AdditiveInverseMutable(a);
Error, AdditiveInverseOp: method should have returned a value
gap> AdditiveInverseSameMutability(a);
Error, AdditiveInverseSameMutability: method should have returned a value
gap> a^0;
Error, OneSameMutability: method should have returned a value
gap> One(a);
Error, Method for an attribute must return a value
gap> OneMutable(a);
Error, OneOp: method should have returned a value
gap> OneSameMutability(a);
Error, OneSameMutability: method should have returned a value
gap> a^-1;
Error, InverseSameMutability: method should have returned a value
gap> Inverse(a);
Error, Method for an attribute must return a value
gap> InverseMutable(a);
Error, InvOp: method should have returned a value
gap> InverseSameMutability(a);
Error, InverseSameMutability: method should have returned a value
gap> a = b;
false
gap> a < b;
false
gap> a in b;
false
gap> a + b;
Error, SUM: method should have returned a value
gap> a - b;
Error, DIFF: method should have returned a value
gap> a * b;
Error, PROD: method should have returned a value
gap> a / b;
Error, QUO: method should have returned a value
gap> LeftQuotient(a, b);
Error, LeftQuotient: method should have returned a value
gap> a ^ b;
Error, POW: method should have returned a value
gap> Comm(a, b);
Error, Comm: method should have returned a value
gap> a mod b;
Error, mod: method should have returned a value

#
gap> meths := Concatenation(unary, binary);;
gap> TraceMethods(meths);

#
gap> 0*a;
#I  *: zero integer * additive element with zero
#I  ZeroSameMutability
Error, ZeroSameMutability: method should have returned a value
gap> Zero(a);
#I  ZeroImmutable
Error, Method for an attribute must return a value
gap> ZeroMutable(a);
#I  ZeroMutable
Error, ZeroOp: method should have returned a value
gap> ZeroSameMutability(a);
#I  ZeroSameMutability
Error, ZeroSameMutability: method should have returned a value
gap> -a;
#I  AdditiveInverseSameMutability
Error, AdditiveInverseSameMutability: method should have returned a value
gap> AdditiveInverse(a);
#I  AdditiveInverseImmutable
Error, Method for an attribute must return a value
gap> AdditiveInverseMutable(a);
#I  AdditiveInverseMutable
Error, AdditiveInverseOp: method should have returned a value
gap> AdditiveInverseSameMutability(a);
#I  AdditiveInverseSameMutability
Error, AdditiveInverseSameMutability: method should have returned a value
gap> a^0;
#I  ^: for mult. element-with-one, and zero
#I  OneSameMutability
Error, OneSameMutability: method should have returned a value
gap> One(a);
#I  OneImmutable
Error, Method for an attribute must return a value
gap> OneMutable(a);
#I  OneMutable
Error, OneOp: method should have returned a value
gap> OneSameMutability(a);
#I  OneSameMutability
Error, OneSameMutability: method should have returned a value
gap> a^-1;
#I  ^: for mult. element-with-inverse, and negative integer
#I  InverseSameMutability
Error, InverseSameMutability: method should have returned a value
gap> Inverse(a);
#I  InverseImmutable
Error, Method for an attribute must return a value
gap> InverseMutable(a);
#I  InverseMutable
Error, InvOp: method should have returned a value
gap> InverseSameMutability(a);
#I  InverseSameMutability
Error, InverseSameMutability: method should have returned a value
gap> a = b;
#I  =
false
gap> a < b;
#I  <
false
gap> a in b;
#I  in
false
gap> a + b;
#I  +
Error, SUM: method should have returned a value
gap> a - b;
#I  -
Error, DIFF: method should have returned a value
gap> a * b;
#I  *
Error, PROD: method should have returned a value
gap> a / b;
#I  /
Error, QUO: method should have returned a value
gap> LeftQuotient(a, b);
Error, LeftQuotient: method should have returned a value
gap> a ^ b;
#I  ^
Error, POW: method should have returned a value
gap> Comm(a, b);
#I  Comm
Error, Comm: method should have returned a value
gap> a mod b;
#I  mod
Error, mod: method should have returned a value

#
gap> UntraceMethods(meths);

#
# restore previous state
#
gap> NEXT_VMETHOD_PRINT_INFO:=old_NEXT_VMETHOD_PRINT_INFO;;
gap> VMETHOD_PRINT_INFO:=old_VMETHOD_PRINT_INFO;;
gap> MakeReadOnlyGlobal("VMETHOD_PRINT_INFO");
gap> MakeReadOnlyGlobal("NEXT_VMETHOD_PRINT_INFO");

#
gap> STOP_TEST("kernel/ariths.tst");