Skip to content

Commit e666a48

Browse files
committed
fixed print tests
1 parent 18d3bf8 commit e666a48

14 files changed

Lines changed: 123 additions & 180 deletions

src/Math-FunctionFit/PMAnotherGeneticOptimizer.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ PMAnotherGeneticOptimizer >> printOn: aStream [
174174
aStream
175175
nextPutAll: self class name;
176176
nextPutAll: '( function: ';
177-
nextPutAll: originalFunction compiledBlock asString;
177+
nextPutAll: (PMFunctionPrinter new printFunction: originalFunction);
178178
nextPutAll: ' manager: ';
179179
print: chromosomeManager;
180180
nextPutAll: ' maxIterations: ';

src/Math-FunctionFit/PMErrorOfParameterFunction.class.st

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ PMErrorOfParameterFunction class >> function: aBlock data: aCollectionOfPoints [
2727
PMErrorOfParameterFunction >> compiledBlock [
2828
"This method only exists for polymorphic message send"
2929

30-
^ self asString
30+
^ function
3131
]
3232

3333
{ #category : 'accessing' }
@@ -117,9 +117,11 @@ PMErrorOfParameterFunction >> parameterSize [
117117

118118
{ #category : 'printing' }
119119
PMErrorOfParameterFunction >> printOn: aStream [
120-
super printOn: aStream.
121120
aStream
122-
nextPutAll: '( function: '; print: function compiledBlock;
121+
nextPutAll: 'a ';
122+
nextPutAll: self class name;
123+
nextPutAll: '( function: ';
124+
nextPutAll: (PMFunctionPrinter new printFunction: function);
123125
nextPutAll: ' relativeError: '; print: relative;
124126
nextPutAll: ' errorType: '; print: errorType.
125127
(#(#quartile #insensitive) includes: errorType)ifTrue:[
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Class {
2+
#name : 'PMFunctionPrinter',
3+
#superclass : 'Object',
4+
#category : 'Math-FunctionFit',
5+
#package : 'Math-FunctionFit'
6+
}
7+
8+
{ #category : 'printing' }
9+
PMFunctionPrinter >> printFunction: aFunction [
10+
11+
^ aFunction compiledBlock sourceNode sourceCode
12+
]

src/Math-FunctionFit/PMGeneralFunctionFit.class.st

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ PMGeneralFunctionFit class >> range: anArray size: anInteger type: string [
4545
ifFalse: [self error: (string, ' values is no collection or number')]]
4646
]
4747

48+
{ #category : 'accessing' }
49+
PMGeneralFunctionFit >> compiledBlock [
50+
51+
^ errorFunction function
52+
]
53+
4854
{ #category : 'accessing' }
4955
PMGeneralFunctionFit >> data: aCollectionOfPoints [
5056
"the data, a collection of x@f(x), used to estimate the parameters"
@@ -237,16 +243,19 @@ PMGeneralFunctionFit >> precision [
237243

238244
{ #category : 'printing' }
239245
PMGeneralFunctionFit >> printOn: aStream [
246+
240247
aStream
241248
nextPutAll: 'a ';
242249
nextPutAll: self class name;
243250
nextPut: $(;
244251
print: geneticOptimizer;
245252
nextPutAll: ' with data of size: ';
246-
print: data size .
247-
dataTruncated ifTrue:
248-
[aStream nextPutAll: ' truncated to: '; print: self optimizer functionBlock data size] .
249-
aStream nextPut: $)
253+
print: data size.
254+
dataTruncated ifTrue: [
255+
aStream
256+
nextPutAll: ' truncated to: ';
257+
print: self optimizer functionBlock data size ].
258+
aStream nextPut: $)
250259
]
251260

252261
{ #category : 'accessing' }

src/Math-Tests-FunctionFit/PMAnotherChromosomeManagerTest.class.st

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Class {
2-
#name : #PMAnotherChromosomeManagerTest,
3-
#superclass : #TestCase,
2+
#name : 'PMAnotherChromosomeManagerTest',
3+
#superclass : 'TestCase',
44
#instVars : [
55
'chromosomeManager'
66
],
7-
#category : #'Math-Tests-FunctionFit'
7+
#category : 'Math-Tests-FunctionFit',
8+
#package : 'Math-Tests-FunctionFit'
89
}
910

10-
{ #category : #running }
11+
{ #category : 'running' }
1112
PMAnotherChromosomeManagerTest >> setHammersleyTest: aBoolean [
1213
chromosomeManager useHammersley: aBoolean.
1314
chromosomeManager randomizePopulation.
@@ -23,22 +24,22 @@ PMAnotherChromosomeManagerTest >> setHammersleyTest: aBoolean [
2324
self assert: (i second between: 1 and: 4) ]
2425
]
2526

26-
{ #category : #running }
27+
{ #category : 'running' }
2728
PMAnotherChromosomeManagerTest >> setUp [
2829

2930
super setUp.
3031
chromosomeManager := PMAnotherChromosomeManager origin: #( 0 1 ) range: #( 2 3 ).
3132
chromosomeManager randomGenerator: (Random seed: 42)
3233
]
3334

34-
{ #category : #tests }
35+
{ #category : 'tests' }
3536
PMAnotherChromosomeManagerTest >> testAccessing [
3637
self assert: chromosomeManager range equals: #(2 3).
3738
self assert: chromosomeManager populationSize equals: 100.
3839
self deny: chromosomeManager isFullyPopulated
3940
]
4041

41-
{ #category : #tests }
42+
{ #category : 'tests' }
4243
PMAnotherChromosomeManagerTest >> testCrossOver [
4344

4445
| a |
@@ -56,7 +57,7 @@ PMAnotherChromosomeManagerTest >> testCrossOver [
5657
self assert: (a occurrencesOf: #( 1 2 3 )) < 20
5758
]
5859

59-
{ #category : #tests }
60+
{ #category : 'tests' }
6061
PMAnotherChromosomeManagerTest >> testEirCrossOver [
6162
|a|
6263
a :=(1 to: 200)collect: [:i| a:=chromosomeManager eirCrossover: #(1.0 3.0) and: #(5.0 1.0).
@@ -82,7 +83,7 @@ self shouldnt: [a:=chromosomeManager eirCrossover: #(1 -3) and: #(1 -3)] raise:
8283
].
8384
]
8485

85-
{ #category : #tests }
86+
{ #category : 'tests' }
8687
PMAnotherChromosomeManagerTest >> testIntegerDigits [
8788
self
8889
assert: (PMAnotherChromosomeManager integerDigitsFor: 0 base: 2)
@@ -101,7 +102,7 @@ PMAnotherChromosomeManagerTest >> testIntegerDigits [
101102
equals: #(1 4 4)
102103
]
103104

104-
{ #category : #tests }
105+
{ #category : 'tests' }
105106
PMAnotherChromosomeManagerTest >> testLineCrossOver [
106107
| a |
107108
1 to: 10 do: [ :i |
@@ -110,7 +111,7 @@ PMAnotherChromosomeManagerTest >> testLineCrossOver [
110111
self assert: ((a at: 2) at: 2) equals: ((a at: 2) at: 1) negated ]
111112
]
112113

113-
{ #category : #tests }
114+
{ #category : 'tests' }
114115
PMAnotherChromosomeManagerTest >> testMutateProbabilistic [
115116

116117
| a f s |
@@ -134,7 +135,7 @@ PMAnotherChromosomeManagerTest >> testMutateProbabilistic [
134135
self assert: (s size between: 3 and: 20)
135136
]
136137

137-
{ #category : #tests }
138+
{ #category : 'tests' }
138139
PMAnotherChromosomeManagerTest >> testNumberOfHamersleyPoints [
139140

140141
| rand |
@@ -197,17 +198,7 @@ PMAnotherChromosomeManagerTest >> testNumberOfHamersleyPoints [
197198
rand do: [ :i | i do: [ :j | j < (1 / 3) ] ]
198199
]
199200

200-
{ #category : #tests }
201-
PMAnotherChromosomeManagerTest >> testPrint [
202-
|aStream s|
203-
aStream :=ReadWriteStream with:''.
204-
chromosomeManager printOn: aStream .
205-
s :=aStream contents .
206-
self assert: (s includesSubstring: '#(0 1)').
207-
self assert: (s includesSubstring: '#(2 3)')
208-
]
209-
210-
{ #category : #tests }
201+
{ #category : 'tests' }
211202
PMAnotherChromosomeManagerTest >> testProcessand [
212203
chromosomeManager reset.
213204
1 to: 60 do: [ :i | chromosomeManager process: #(0 0) and: #(1 1) ].
@@ -218,7 +209,7 @@ PMAnotherChromosomeManagerTest >> testProcessand [
218209
self assert: chromosomeManager population size equals: 120
219210
]
220211

221-
{ #category : #tests }
212+
{ #category : 'tests' }
222213
PMAnotherChromosomeManagerTest >> testRandomizePopulation [
223214

224215
| g |
@@ -231,7 +222,7 @@ PMAnotherChromosomeManagerTest >> testRandomizePopulation [
231222
self deny: chromosomeManager population first equals: g
232223
]
233224

234-
{ #category : #tests }
225+
{ #category : 'tests' }
235226
PMAnotherChromosomeManagerTest >> testRateSetting [
236227
self should: [chromosomeManager rateOfLC: 1.3] raise: DomainError .
237228
self should: [chromosomeManager rateOfEir: -0.3] raise: DomainError .

src/Math-Tests-FunctionFit/PMAnotherGeneticOptimizerTest.class.st

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Class {
2-
#name : #PMAnotherGeneticOptimizerTest,
3-
#superclass : #TestCase,
2+
#name : 'PMAnotherGeneticOptimizerTest',
3+
#superclass : 'TestCase',
44
#instVars : [
55
'geneticOptimizer'
66
],
7-
#category : #'Math-Tests-FunctionFit'
7+
#category : 'Math-Tests-FunctionFit',
8+
#package : 'Math-Tests-FunctionFit'
89
}
910

10-
{ #category : #running }
11+
{ #category : 'running' }
1112
PMAnotherGeneticOptimizerTest >> setUp [
1213

1314
| origin f |
@@ -23,15 +24,15 @@ PMAnotherGeneticOptimizerTest >> setUp [
2324
geneticOptimizer chromosomeManager randomGenerator: (Random seed: 42)
2425
]
2526

26-
{ #category : #tests }
27+
{ #category : 'tests' }
2728
PMAnotherGeneticOptimizerTest >> testChromosomeManager [
2829
self
2930
assert: geneticOptimizer chromosomeManager class
3031
equals: PMAnotherChromosomeManager.
3132
self assert: geneticOptimizer chromosomeManager populationSize equals: 20
3233
]
3334

34-
{ #category : #tests }
35+
{ #category : 'tests' }
3536
PMAnotherGeneticOptimizerTest >> testComputePrecision [
3637
|r|
3738
geneticOptimizer maximumIterations: 2.
@@ -42,15 +43,15 @@ geneticOptimizer evaluate .
4243
self assert: (r>geneticOptimizer computePrecision )
4344
]
4445

45-
{ #category : #tests }
46+
{ #category : 'tests' }
4647
PMAnotherGeneticOptimizerTest >> testEvaluate [
4748

4849
geneticOptimizer maximumIterations: 170.
4950
geneticOptimizer chromosomeManager populationSize: 50.
5051
self assert: geneticOptimizer evaluate closeTo: #( 0 0 0 )
5152
]
5253

53-
{ #category : #tests }
54+
{ #category : 'tests' }
5455
PMAnotherGeneticOptimizerTest >> testInitializeIterations [
5556

5657
self assertEmpty: geneticOptimizer bestPoints.
@@ -63,19 +64,7 @@ PMAnotherGeneticOptimizerTest >> testInitializeIterations [
6364
self assertEmpty: geneticOptimizer bestValueHistory
6465
]
6566

66-
{ #category : #tests }
67-
PMAnotherGeneticOptimizerTest >> testPrint [
68-
69-
| aStream s |
70-
aStream := ReadWriteStream with: ''.
71-
geneticOptimizer printOn: aStream.
72-
s := aStream contents.
73-
self assert: (s includesSubstring: 'v * v').
74-
self assert: (s includesSubstring: '50').
75-
self assert: (s includesSubstring: '20')
76-
]
77-
78-
{ #category : #tests }
67+
{ #category : 'tests' }
7968
PMAnotherGeneticOptimizerTest >> testRangeScale [
8069

8170
geneticOptimizer initializeIterations.
@@ -86,7 +75,7 @@ PMAnotherGeneticOptimizerTest >> testRangeScale [
8675
self assert: geneticOptimizer rangeScale second closeTo: 0.19473684210526315
8776
]
8877

89-
{ #category : #tests }
78+
{ #category : 'tests' }
9079
PMAnotherGeneticOptimizerTest >> testRangeScaleProbabilistic [
9180
| r1 r2 correct |
9281
correct := 0.
@@ -106,7 +95,7 @@ PMAnotherGeneticOptimizerTest >> testRangeScaleProbabilistic [
10695
self assert: correct > 0
10796
]
10897

109-
{ #category : #tests }
98+
{ #category : 'tests' }
11099
PMAnotherGeneticOptimizerTest >> testRemoveLastProbabilistic [
111100
| r1 r2 correct |
112101
correct := 0.
@@ -126,7 +115,7 @@ PMAnotherGeneticOptimizerTest >> testRemoveLastProbabilistic [
126115
self assert: correct > 0
127116
]
128117

129-
{ #category : #tests }
118+
{ #category : 'tests' }
130119
PMAnotherGeneticOptimizerTest >> testSteadyState [
131120
|r1 r2|
132121
"probabilistic test. not always true"
@@ -140,7 +129,7 @@ r2 :=geneticOptimizer evaluate norm.
140129
self assert: (r1>r2 )
141130
]
142131

143-
{ #category : #tests }
132+
{ #category : 'tests' }
144133
PMAnotherGeneticOptimizerTest >> testaddPointAt [
145134
| b |
146135
geneticOptimizer chromosomeManager populationSize: 2.
@@ -167,7 +156,7 @@ PMAnotherGeneticOptimizerTest >> testaddPointAt [
167156
self assert: b second position equals: #(0 0.9 0)
168157
]
169158

170-
{ #category : #tests }
159+
{ #category : 'tests' }
171160
PMAnotherGeneticOptimizerTest >> testcalcStatistics [
172161

173162
| s |
@@ -183,7 +172,7 @@ PMAnotherGeneticOptimizerTest >> testcalcStatistics [
183172
self assert: geneticOptimizer whateverHistory size equals: s
184173
]
185174

186-
{ #category : #tests }
175+
{ #category : 'tests' }
187176
PMAnotherGeneticOptimizerTest >> testresetBestPoints [
188177

189178
geneticOptimizer evaluate.

src/Math-Tests-FunctionFit/PMDataHolderTest.class.st

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
Class {
2-
#name : #PMDataHolderTest,
3-
#superclass : #TestCase,
4-
#category : #'Math-Tests-FunctionFit'
2+
#name : 'PMDataHolderTest',
3+
#superclass : 'TestCase',
4+
#category : 'Math-Tests-FunctionFit',
5+
#package : 'Math-Tests-FunctionFit'
56
}
67

7-
{ #category : #tests }
8+
{ #category : 'tests' }
89
PMDataHolderTest >> testpointsAndErrorsDo [
910
|g|
1011
g:=PMDataHolder new: 2 withAll: 2@3.

0 commit comments

Comments
 (0)