/
srp.slate
146 lines (103 loc) · 3.84 KB
/
srp.slate
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
lobby ensureNamespace: #UnitTests.
UnitTests define: #SRP &parents: {TestCase}.
s@(UnitTests SRP traits) equalityLiterals
[
"Literals that should compare = when replicated."
| a |
a: (ExtensibleArray newSize: 1).
a add: 'ABC'.
a add: 999999999999999.
a add: -999999999999999.
" a add: 1.5 .
a add: -1.5 .
a add: 1 / 3 .
a add: -1 / 3 ."
a add: #(name date).
a add: ({255. 65. 66. 67. 0.} as: ByteArray).
a
].
s@(UnitTests SRP traits) identityLiterals
[
"Literals that should compare == when replicated."
{ True. False. Nil. #name. $A. 7. -7.}
" #(True False Nil $A 7 -7)"
].
s@(UnitTests SRP traits) testLiteralDefaultReplications
[
s equalityLiterals do: [| :ea |
s assert: (SRP Configuration new replicate: ea) = ea.
s assert: (SRP NonMappingConfiguration new replicate: ea) = ea.
" self assert: (SrpBase64Configuration new replicate: ea) = ea.
self assert: (SrtSequenceCheckConfiguration new replicate: ea) = ea."
].
s identityLiterals do: [| :ea |
s assert: (SRP Configuration new replicate: ea) == ea.
s assert: ((SRP NonMappingConfiguration new replicate: ea) == ea).
" self assert: (SrpBase64Configuration new replicate: ea) == ea.
self assert: (SrtSequenceCheckConfiguration new replicate: ea) == ea."
].
].
s@(UnitTests SRP traits) testStringReplications
[
| stream |
stream: ((ExtensibleArray newSize: 1) writer).
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream ; '\n'.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream nextPut: $A.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream ; '\n'.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream nextPutAll: 'ABCD'.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream ; '\n'.
stream nextPutAll: 'EFGH'.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream ; '\n'. stream ; '\n'.
stream nextPutAll: 'IJKL'.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream nextPut: (10 as: Character).
stream ; '\n'.
stream nextPutAll: 'MNOP'.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream nextPut: (13 as: Character).
stream ; '\n'.
stream nextPutAll: 'QRST'.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream nextPut: (13 as: Character). stream nextPut: (13 as: Character). stream ; '\n'. stream nextPutAll: 'UVW'.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream nextPut: (10 as: Character). stream nextPut: (10 as: Character). stream ; '\n'. stream nextPutAll: 'XYZ'.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
stream ; '\n\n\t\n\n'.
s assert: (SRP Configuration default replicate: stream contents) = stream contents.
].
s@(UnitTests SRP traits) testSrpDefaultsComplexObject100xWriteRead
[
| ostream method t1 t2 |
method: s complexObject.
ostream: SRP Configuration new newStream.
t1: (t2: 0).
100 timesRepeat: [
ostream nextPut: method.
" t1 := t1 + (self portal millisecondsToRun: [ostream nextPut: method ]).
"
ostream reset.
ostream next.
" t2 := t2 + (self portal millisecondsToRun: [ostream next ]).
"
ostream reset.
].
"
self reportComment: #testSrpDefaultsComplexObject100xWriteRead, ' save ', t1 printString, 'ms, load ', t2 printString, 'ms.'.
"
].
s@(UnitTests SRP traits) complexObject
[
SRP Configuration default loadObjectFromBinaryFilename: '/home/jewel/complexObject'
].
s@(UnitTests SRP traits) suite
[s suiteForSelectors: {
#testLiteralDefaultReplications.
#testStringReplications.
}].
"UnitTests SRP suite run"