File: records.tst

package info (click to toggle)
gap 4r10p0-7
  • links: PTS
  • area: main
  • in suites: buster
  • size: 47,392 kB
  • sloc: ansic: 118,475; xml: 54,089; sh: 4,112; perl: 1,654; makefile: 274
file content (92 lines) | stat: -rw-r--r-- 2,243 bytes parent folder | download
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
#
# Tests for functions defined in src/records.c
#
gap> START_TEST("kernel/records.tst");

#
# setup: a precord, and a custom record object
#
gap> r:=rec(1:=2);
rec( 1 := 2 )
gap> fam := NewFamily("MockFamily");;
gap> cat := NewCategory("IsMockRecord", IsRecord);;
gap> type := NewType(fam, cat and IsPositionalObjectRep);;
gap> mockRec := Objectify(type,["myName"]);;

# RNamIntg, RNamObj
gap> ForAll([1,-1,"abc"], x -> IsInt(RNamObj(x)));
true
gap> RNamObj(fail);
Error, Record: '<rec>.(<obj>)' <obj> must be a string or an integer

# NameRNam
gap> ForAll([1,-1,"abc"], x -> NameRNam(RNamObj(x)) = String(x));
true
gap> NameRNam(-1);
Error, NameRName: <rnam> must be a record name (not a integer)
gap> NameRNam(fail);
Error, NameRName: <rnam> must be a record name (not a boolean or fail)

# ElmRecHandler
gap> ELM_REC(r, RNamObj(1));
2
gap> ELM_REC(r, RNamObj(2));
Error, Record Element: '<rec>.2' must have an assigned value

# ElmRecError
gap> fail.1;
Error, Record Element: <rec> must be a record (not a boolean or fail)

# ElmRecObject
gap> InstallMethod(\., [cat, IsPosInt], function(x,i) end);
gap> mockRec.1;
Error, Record access method must return a value
gap> InstallMethod(\., [cat, IsPosInt], function(x,i) return 42; end);
gap> mockRec.1;
42

# IsbRecHandler
gap> ISB_REC(r, RNamObj(1));
true
gap> ISB_REC(r, RNamObj(2));
false

# IsbRecError
gap> IsBound(fail.1);
Error, Record IsBound: <rec> must be a record (not a boolean or fail)

# IsbRecObject
gap> InstallMethod(IsBound\., [cat, IsPosInt], {x,i} -> (i = RNamObj(1)));
gap> IsBound(mockRec.1);
true
gap> IsBound(mockRec.2);
false

# AssRecHandler
gap> ASS_REC(r, RNamObj(3), 42);
gap> r;
rec( 1 := 2, 3 := 42 )

# AssRecError
gap> fail.1 := 2;
Error, Record Assignment: <rec> must be a record (not a boolean or fail)

# AssRecObject
gap> InstallMethod(\.\:\=, [cat, IsPosInt, IsObject], function(x,i,v) end);
gap> ASS_REC(mockRec, RNamObj(1), 2);
gap> mockRec.1 := 2;
2

# UnbRecHandler
gap> UNB_REC(r, RNamObj(2));

# UnbRecError
gap> Unbind(fail.1);
Error, Record Unbind: <rec> must be a record (not a boolean or fail)

# UnbRecObject
gap> InstallMethod(Unbind\., [cat, IsPosInt], function(x,i) end);
gap> Unbind(mockRec.1);

#
gap> STOP_TEST("kernel/records.tst", 1);