Skip to content

Commit 8f7faf6

Browse files
committed
Factorize code
1 parent a2e4237 commit 8f7faf6

File tree

1 file changed

+13
-52
lines changed

1 file changed

+13
-52
lines changed

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

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@ PMGeneralFunctionFitTest >> setUp [
1919
"Reset the FloatingPointMachine to make coverage consistent"
2020
PMFloatingPointMachine reset.
2121
f := [ :x :a :b | (a * x) sin / (b + x squared) ].
22-
col := (-4 to: 4 by: 0.1) collect: [ :i | i @ (f cull: i cull: 0.1 cull: 0.4) ]
22+
col := (-4 to: 4 by: 0.1) collect: [ :i | i @ (f cull: i cull: 0.1 cull: 0.4) ].
23+
fit := PMGeneralFunctionFit
24+
function: f
25+
data: col
26+
minimumValues: 0
27+
maximumValues: 5.
28+
29+
fit manager randomGenerator: (Random seed: 42)
2330
]
2431

2532
{ #category : #tests }
2633
PMGeneralFunctionFitTest >> testBasic [
2734

2835
| d |
29-
fit := PMGeneralFunctionFit
30-
function: f
31-
data: col
32-
minimumValues: 0
33-
maximumValues: 5.
34-
fit manager randomGenerator: (Random seed: 42).
3536
self assert: (fit evaluate closeTo: #( 0.1 0.4 )).
3637
(fit result - #( 0.1 0.4 )) abs with: (fit secondaryResult - #( 0.1 0.4 )) abs do: [ :e :s | self assert: s - e > 0 ].
3738
d := fit error: fit secondaryResult.
@@ -43,40 +44,24 @@ PMGeneralFunctionFitTest >> testBasic [
4344
PMGeneralFunctionFitTest >> testFunction [
4445

4546
| y |
46-
fit := PMGeneralFunctionFit
47-
function: f
48-
data: col
49-
minimumValues: 0
50-
maximumValues: 5.
51-
fit manager randomGenerator: (Random seed: 42).
5247
y := fit function value: 3 value: 0.1 value: 0.4.
5348
fit evaluate.
5449
self assert: ((fit function value: 3) closeTo: y)
5550
]
5651

5752
{ #category : #tests }
5853
PMGeneralFunctionFitTest >> testManager [
59-
fit := PMGeneralFunctionFit
60-
function: f
61-
data: col
62-
minimumValues: 0
63-
maximumValues: 5.
54+
6455
self assert: fit manager class equals: PMAnotherChromosomeManager.
65-
self assert: fit manager range equals: #(5 5)
56+
self assert: fit manager range equals: #( 5 5 )
6657
]
6758

6859
{ #category : #tests }
6960
PMGeneralFunctionFitTest >> testMaximumIterationsProbabilistic [
7061

7162
| r correct |
72-
fit := PMGeneralFunctionFit
73-
function: f
74-
data: col
75-
minimumValues: 0
76-
maximumValues: 5.
7763
correct := 0.
7864
fit populationSize: 20.
79-
fit manager randomGenerator: (Random seed: 42).
8065
7 timesRepeat: [
8166
fit resetBestPoints.
8267
fit maximumIterations: 200.
@@ -92,11 +77,7 @@ PMGeneralFunctionFitTest >> testMaximumIterationsProbabilistic [
9277

9378
{ #category : #tests }
9479
PMGeneralFunctionFitTest >> testPopulationSize [
95-
fit := PMGeneralFunctionFit
96-
function: f
97-
data: col
98-
minimumValues: 0
99-
maximumValues: 5.
80+
10081
self assert: fit manager populationSize equals: 50.
10182
fit populationSize: 100.
10283
self assert: fit manager populationSize equals: 100
@@ -105,12 +86,6 @@ PMGeneralFunctionFitTest >> testPopulationSize [
10586
{ #category : #tests }
10687
PMGeneralFunctionFitTest >> testPrecision [
10788

108-
fit := PMGeneralFunctionFit
109-
function: f
110-
data: col
111-
minimumValues: 0
112-
maximumValues: 5.
113-
fit manager randomGenerator: (Random seed: 42).
11489
self assert: fit precision isNil.
11590
fit evaluate.
11691
self assert: fit precision < 1e-6
@@ -120,13 +95,6 @@ PMGeneralFunctionFitTest >> testPrecision [
12095
PMGeneralFunctionFitTest >> testPrint [
12196

12297
| aStream s |
123-
fit := PMGeneralFunctionFit
124-
function: f
125-
data: col
126-
minimumValues: 0
127-
maximumValues: 5.
128-
129-
fit manager randomGenerator: (Random seed: 42).
13098
aStream := ReadWriteStream with: ''.
13199
fit printOn: aStream.
132100
s := aStream contents.
@@ -150,8 +118,8 @@ PMGeneralFunctionFitTest >> testRelativeError [
150118
fit := PMGeneralFunctionFit
151119
function: f
152120
data: col
153-
minimumValues: -6
154-
maximumValues: 6.
121+
minimumValues: 0
122+
maximumValues: 5.
155123

156124
fit manager randomGenerator: (Random seed: 42).
157125
fit populationSize: 10.
@@ -170,13 +138,6 @@ PMGeneralFunctionFitTest >> testRelativeError [
170138
{ #category : #tests }
171139
PMGeneralFunctionFitTest >> testResetBestPoints [
172140

173-
fit := PMGeneralFunctionFit
174-
function: f
175-
data: col
176-
minimumValues: 0
177-
maximumValues: 5.
178-
179-
fit manager randomGenerator: (Random seed: 42).
180141
fit evaluate.
181142
fit resetBestPoints.
182143
self assertEmpty: fit optimizer bestPoints

0 commit comments

Comments
 (0)