Merge branch 'master' of git@github.com:briantrice/slate-language
[cslatevm.git] / tests / srp.slate
blob69cab7c0e3853a36250ff80a0bf3765255fbd44c
1 lobby ensureNamespace: #UnitTests.
3 UnitTests define: #SRP &parents: {TestCase}.
5 s@(UnitTests SRP traits) equalityLiterals
7  "Literals that should compare = when replicated."
8  | a |
9  a: (ExtensibleArray newSize: 1).
10  a add: 'ABC'.
11  a add: 999999999999999.
12  a add: -999999999999999.
13 " a add: 1.5 .
14  a add: -1.5 .
15  a add:  1 / 3 .
16  a add: -1 / 3 ."
17  a add: #(name date).
18  a add: ({255. 65. 66. 67. 0.} as: ByteArray).
19  a
22 s@(UnitTests SRP traits) identityLiterals
24   "Literals that should compare == when replicated."
26  { True. False. Nil. #name. $A. 7. -7.}
27 "  #(True False Nil $A 7 -7)"
30 s@(UnitTests SRP traits) testLiteralDefaultReplications
32   s equalityLiterals do: [| :ea |
33     s assert: (SRP Configuration new replicate: ea) = ea.
34     s assert: (SRP NonMappingConfiguration new replicate: ea) = ea.
35 "    self assert: (SrpBase64Configuration new replicate: ea) = ea.
36     self assert: (SrtSequenceCheckConfiguration new replicate: ea) = ea."
37   ].
39   s identityLiterals do: [| :ea |
40     s assert: (SRP Configuration new replicate: ea) == ea.
41     s assert: ((SRP NonMappingConfiguration new replicate: ea) == ea).
42 "    self assert: (SrpBase64Configuration new replicate: ea) == ea.
43     self assert: (SrtSequenceCheckConfiguration new replicate: ea) == ea."
44   ].
47 s@(UnitTests SRP traits) testStringReplications
49   | stream |
51   stream: ((ExtensibleArray newSize: 1) writer).
52   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
54   stream ; '\n'.
56   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
58   stream nextPut: $A.
60   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
62   stream ; '\n'.
64   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
66   stream nextPutAll: 'ABCD'.
68   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
70   stream ; '\n'.
71   stream nextPutAll: 'EFGH'.
73   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
75   stream ; '\n'. stream ; '\n'.
76    stream nextPutAll: 'IJKL'.
78   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
80   stream nextPut: (10 as: Character).
81    stream ; '\n'.
82   stream nextPutAll: 'MNOP'.
84   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
86   stream nextPut: (13 as: Character).
87   stream ; '\n'.
89   stream nextPutAll: 'QRST'.
91   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
93   stream nextPut: (13 as: Character). stream nextPut: (13 as: Character). stream ; '\n'. stream nextPutAll: 'UVW'.
95   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
97   stream nextPut: (10 as: Character). stream nextPut: (10 as: Character). stream ; '\n'. stream nextPutAll: 'XYZ'.
99   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
100   
101   stream ; '\n\n\t\n\n'.
103   s assert: (SRP Configuration default replicate: stream contents) = stream contents.
107 s@(UnitTests SRP traits) testSrpDefaultsComplexObject100xWriteRead
109   | ostream method t1 t2 |
111   method: s complexObject.
113   ostream: SRP Configuration new newStream.
115   t1: (t2: 0).
117   100 timesRepeat: [
119     ostream nextPut: method.
120 "    t1 := t1 + (self portal millisecondsToRun: [ostream nextPut: method ]).
122     ostream reset.
123     ostream next.
124 "    t2 := t2 + (self portal millisecondsToRun: [ostream next ]).
126     ostream reset.
128   ].
130   self reportComment: #testSrpDefaultsComplexObject100xWriteRead, ' save ', t1 printString, 'ms, load ', t2 printString, 'ms.'.
134 s@(UnitTests SRP traits) complexObject
136  SRP Configuration default loadObjectFromBinaryFilename: '/home/jewel/complexObject'
139 s@(UnitTests SRP traits) suite
140 [s suiteForSelectors: {
141   #testLiteralDefaultReplications.
142   #testStringReplications.
145 "UnitTests SRP suite run"