diff --git a/src/Math-AutomaticDifferenciation/PMDualNumber.class.st b/src/Math-AutomaticDifferenciation/PMDualNumber.class.st index 7f8f60d0..3ebf7abb 100644 --- a/src/Math-AutomaticDifferenciation/PMDualNumber.class.st +++ b/src/Math-AutomaticDifferenciation/PMDualNumber.class.st @@ -135,8 +135,13 @@ PMDualNumber >> asInteger [ { #category : #comparing } PMDualNumber >> closeTo: aDualNumber [ - ^ (value closeTo: aDualNumber value) and: [ - eps closeTo: aDualNumber eps ] + ^ self closeTo: aDualNumber precision: Float defaultComparisonPrecision +] + +{ #category : #comparing } +PMDualNumber >> closeTo: aDualNumber precision: aPrecision [ + + ^ (value closeTo: aDualNumber value precision: aPrecision) and: [ eps closeTo: aDualNumber eps precision: aPrecision ] ] { #category : #'mathematical functions' } diff --git a/src/Math-AutomaticDifferenciation/PMHyperDualNumber.class.st b/src/Math-AutomaticDifferenciation/PMHyperDualNumber.class.st index 2453881c..9e73ef89 100644 --- a/src/Math-AutomaticDifferenciation/PMHyperDualNumber.class.st +++ b/src/Math-AutomaticDifferenciation/PMHyperDualNumber.class.st @@ -97,11 +97,10 @@ PMHyperDualNumber >> arcTan [ ] { #category : #comparing } -PMHyperDualNumber >> closeTo: aHyperDualNumber [ +PMHyperDualNumber >> closeTo: aHyperDualNumber precision: aPrecision [ - ^ (super closeTo: aHyperDualNumber) and: [ - (eps2 closeTo: aHyperDualNumber eps2) and: [ - eps1eps2 closeTo: aHyperDualNumber eps1eps2 ] ] + ^ (super closeTo: aHyperDualNumber precision: aPrecision) and: [ + (eps2 closeTo: aHyperDualNumber eps2 precision: aPrecision) and: [ eps1eps2 closeTo: aHyperDualNumber eps1eps2 precision: aPrecision ] ] ] { #category : #'mathematical functions' } diff --git a/src/Math-CompatibilityUpToPharo11/SequenceableCollection.extension.st b/src/Math-CompatibilityUpToPharo11/SequenceableCollection.extension.st new file mode 100644 index 00000000..3bcd0cbd --- /dev/null +++ b/src/Math-CompatibilityUpToPharo11/SequenceableCollection.extension.st @@ -0,0 +1,11 @@ +Extension { #name : #SequenceableCollection } + +{ #category : #'*Math-CompatibilityUpToPharo11' } +SequenceableCollection >> closeTo: aSequenceableCollection precision: aPrecision [ + "Return true if all my elements are close to the elements of same index of the parameter with a certain precision" + + "(#(1.9283 2.3029) closeTo: #(1.9284 2.3028) precision: 0.001) >>> true" + + self with: aSequenceableCollection do: [ :a :b | (a closeTo: b precision: aPrecision) ifFalse: [ ^ false ] ]. + ^ true +] diff --git a/src/Math-Tests-Accuracy/PMAccuracyTest.class.st b/src/Math-Tests-Accuracy/PMAccuracyTest.class.st index d87445e7..15a9e7bd 100644 --- a/src/Math-Tests-Accuracy/PMAccuracyTest.class.st +++ b/src/Math-Tests-Accuracy/PMAccuracyTest.class.st @@ -185,21 +185,21 @@ PMAccuracyTest >> testIfSeveralterations [ { #category : #tests } PMAccuracyTest >> testIterations [ + | s d | a iterations: 2; run. d := a dataTree at: 'names'. - s := (d atPath: #('Aaa' #(1 2) #(5 3) '+dev')) first negated. - self - assert: ((d atPath: #('Aaa' #(1 2) #(5 3) '-dev')) first closeTo: s). - s := d atPath: #('Aaa' #(3 2.8888) #(5 3) 'standard deviation'). + s := (d atPath: #( 'Aaa' #( 1 2 ) #( 5 3 ) '+dev' )) first negated. + self assert: (d atPath: #( 'Aaa' #( 1 2 ) #( 5 3 ) '-dev' )) first closeTo: s. + s := d atPath: #( 'Aaa' #( 3 2.8888 ) #( 5 3 ) 'standard deviation' ). self assert: s first > 0. self assert: s second equals: 0. - self assert: (d atPath: #('Ddd' 'data')) equals: #(#(2 3) #(2 3)). - s := d atPath: #('Ddd' 'error'). - self assert: (s first closeTo: -45). - self assert: (s second closeTo: -26.6666667) + self assert: (d atPath: #( 'Ddd' 'data' )) equals: #( #( 2 3 ) #( 2 3 ) ). + s := d atPath: #( 'Ddd' 'error' ). + self assert: s first closeTo: -45. + self assert: s second closeTo: -26.6666667 ] { #category : #tests } diff --git a/src/Math-Tests-AutomaticDifferenciation/PMDualNumberTest.class.st b/src/Math-Tests-AutomaticDifferenciation/PMDualNumberTest.class.st index fb8617f1..92129228 100644 --- a/src/Math-Tests-AutomaticDifferenciation/PMDualNumberTest.class.st +++ b/src/Math-Tests-AutomaticDifferenciation/PMDualNumberTest.class.st @@ -56,10 +56,9 @@ PMDualNumberTest >> testAdd [ PMDualNumberTest >> testArcCos [ | a | - self assert: - (zero arcCos closeTo: (PMDualNumber value: Float halfPi eps: -1)). + self assert: zero arcCos closeTo: (PMDualNumber value: Float halfPi eps: -1). a := (PMDualNumber value: -1.0 successor eps: 1) arcCos. - self assert: (a value closeTo: Float pi). + self assert: a value closeTo: Float pi. self assert: a eps < -1e6 ] @@ -69,7 +68,7 @@ PMDualNumberTest >> testArcSin [ | a | self assert: zero arcSin equals: zero. a := (PMDualNumber value: 1.0 predecessor eps: 1) arcSin. - self assert: (a value closeTo: Float halfPi). + self assert: a value closeTo: Float halfPi. self assert: a eps > 1e6. a := (PMDualNumber value: -0.5 eps: 1) arcSin. self assert: a value equals: -0.5 arcSin. @@ -80,10 +79,8 @@ PMDualNumberTest >> testArcSin [ PMDualNumberTest >> testArcTan [ self assertEquality: zero arcTan and: zero. - self - assertEquality: one negated arcTan - and: (PMDualNumber value: -1 arcTan eps: -1 / 2). - self assert: (three arcTan eps closeTo: 0.1) + self assertEquality: one negated arcTan and: (PMDualNumber value: -1 arcTan eps: -1 / 2). + self assert: three arcTan eps closeTo: 0.1 ] { #category : #test } @@ -117,13 +114,9 @@ PMDualNumberTest >> testConverting [ { #category : #'tests-mathematical functions' } PMDualNumberTest >> testCos [ - self assert: - ((PMDualNumber value: Float halfPi negated eps: 1) cos closeTo: - (PMDualNumber value: 0 eps: 1)). - self assert: ((PMDualNumber value: Float halfPi eps: 1) cos closeTo: - (PMDualNumber value: 0 eps: -1)). - self assert: - ((PMDualNumber value: Float halfPi eps: 0) cos closeTo: zeroc) + self assert: (PMDualNumber value: Float halfPi negated eps: 1) cos closeTo: (PMDualNumber value: 0 eps: 1). + self assert: (PMDualNumber value: Float halfPi eps: 1) cos closeTo: (PMDualNumber value: 0 eps: -1). + self assert: (PMDualNumber value: Float halfPi eps: 0) cos closeTo: zeroc ] { #category : #'tests-arithmetic' } @@ -167,16 +160,13 @@ PMDualNumberTest >> testEqual [ { #category : #tests } PMDualNumberTest >> testEqualsTo [ - self assert: (zeroc closeTo: zeroc). - self deny: (zeroc closeTo: zero). - self assert: (zero closeTo: zero). - self assert: - (one closeTo: (PMDualNumber value: 1.0000000001 eps: 1.0000000001)). - self deny: - (one closeTo: (PMDualNumber value: 1.0000000001 eps: 1.001)). - self deny: - (one closeTo: (PMDualNumber value: 1.001 eps: 1.0000000001)). - self deny: (one closeTo: (PMDualNumber value: 1.001 eps: 1.001)) + self assert: zeroc closeTo: zeroc. + self deny: zeroc closeTo: zero. + self assert: zero closeTo: zero. + self assert: one closeTo: (PMDualNumber value: 1.0000000001 eps: 1.0000000001). + self deny: one closeTo: (PMDualNumber value: 1.0000000001 eps: 1.001). + self deny: one closeTo: (PMDualNumber value: 1.001 eps: 1.0000000001). + self deny: one closeTo: (PMDualNumber value: 1.001 eps: 1.001) ] { #category : #'tests-mathematical functions' } @@ -185,7 +175,7 @@ PMDualNumberTest >> testExp [ | a b | b := 3 exp. a := three exp. - self assert: (a eps closeTo: b). + self assert: a eps closeTo: b. self assert: a value equals: b. self assert: one equals: zero exp ] @@ -209,7 +199,7 @@ PMDualNumberTest >> testLn [ | a | a := three ln. - self assert: (a eps closeTo: 1 / 3). + self assert: a eps closeTo: 1 / 3. self assert: a value equals: 3 ln. self assert: one ln equals: zero ] @@ -259,21 +249,17 @@ PMDualNumberTest >> testRaisedTo [ | a | self assertEquality: (three raisedTo: 2) and: three squared. self assertEquality: (three raisedTo: 0) and: onec. - self - assertEquality: (three + one raisedTo: 1 / 2) - and: (PMDualNumber value: 2 eps: 1 / 2). - self assert: - ((three + one raisedTo: 3 / 2) closeTo: - (PMDualNumber value: 8 eps: 6)). + self assertEquality: (three + one raisedTo: 1 / 2) and: (PMDualNumber value: 2 eps: 1 / 2). + self assert: (three + one raisedTo: 3 / 2) closeTo: (PMDualNumber value: 8 eps: 6). self assertEquality: (zero raisedTo: 1.4) and: zeroc. a := 2 raisedTo: three. - self assert: (a value closeTo: 8). - self assert: (a eps closeTo: 2 ln * (2 raisedTo: 3)). + self assert: a value closeTo: 8. + self assert: a eps closeTo: 2 ln * (2 raisedTo: 3). self assertEquality: (1 raisedTo: three) and: onec. self assertEquality: (one raisedTo: one) and: one. a := three raisedTo: three. - self assert: (a value closeTo: 27). - self assert: (a eps closeTo: (3 raisedTo: 3) * (3 ln + 1)) + self assert: a value closeTo: 27. + self assert: a eps closeTo: (3 raisedTo: 3) * (3 ln + 1) ] { #category : #'tests-mathematical functions' } @@ -303,11 +289,8 @@ PMDualNumberTest >> testReciprocal [ { #category : #'tests-mathematical functions' } PMDualNumberTest >> testSin [ - self assert: - ((PMDualNumber value: Float halfPi negated eps: 1) sin closeTo: - (PMDualNumber value: -1.0 eps: 0.0)). - self assert: ((PMDualNumber value: Float halfPi eps: 1) sin closeTo: - (PMDualNumber value: 1.0 eps: 0.0)). + self assert: (PMDualNumber value: Float halfPi negated eps: 1) sin closeTo: (PMDualNumber value: -1.0 eps: 0.0). + self assert: (PMDualNumber value: Float halfPi eps: 1) sin closeTo: (PMDualNumber value: 1.0 eps: 0.0). self assertEquality: zero sin and: zero ] @@ -359,11 +342,11 @@ PMDualNumberTest >> testTan [ | a b | a := three tan. self assert: a value equals: 3 tan. - self assert: (a eps closeTo: 3 tan squared + 1). + self assert: a eps closeTo: 3 tan squared + 1. b := Float halfPi - 0.000000000001. a := (PMDualNumber value: b eps: 1) tan. self assert: a value equals: b tan. - self assert: (a eps closeTo: b tan squared + 1) + self assert: a eps closeTo: b tan squared + 1 ] { #category : #'tests-testing' } diff --git a/src/Math-Tests-AutomaticDifferenciation/PMGradientAndHessianTest.class.st b/src/Math-Tests-AutomaticDifferenciation/PMGradientAndHessianTest.class.st index ca01d90f..406132f9 100644 --- a/src/Math-Tests-AutomaticDifferenciation/PMGradientAndHessianTest.class.st +++ b/src/Math-Tests-AutomaticDifferenciation/PMGradientAndHessianTest.class.st @@ -36,10 +36,9 @@ PMGradientAndHessianTest >> test2 [ g := PMGradient of: f. (h := PMHessian of: f) value: #( 0 0 ). r := #( 0.5 0.5 ). - self assert: ((g value: #( 0 0 )) closeTo: r). - self assert: (h gradient closeTo: r). + self assert: (g value: #( 0 0 )) closeTo: r. + self assert: h gradient closeTo: r. r := (-1 exp + 1 exp) reciprocal. - self assert: ((g value: #( -1 1 )) closeTo: r * #( -1 1 ) exp). - self assert: (h result closeTo: - (PMMatrix rows: #( #( 0.25 -0.25 ) #( -0.25 0.25 ) ))) + self assert: (g value: #( -1 1 )) closeTo: r * #( -1 1 ) exp. + self assert: h result closeTo: (PMMatrix rows: #( #( 0.25 -0.25 ) #( -0.25 0.25 ) )) ] diff --git a/src/Math-Tests-AutomaticDifferenciation/PMHyperDualNumberTest.class.st b/src/Math-Tests-AutomaticDifferenciation/PMHyperDualNumberTest.class.st index 22f5fb7f..daf0d3dc 100644 --- a/src/Math-Tests-AutomaticDifferenciation/PMHyperDualNumberTest.class.st +++ b/src/Math-Tests-AutomaticDifferenciation/PMHyperDualNumberTest.class.st @@ -78,17 +78,17 @@ PMHyperDualNumberTest >> testAdd [ PMHyperDualNumberTest >> testArcCos [ | a | - self assert: (zero arcCos closeTo: (PMHyperDualNumber - value: Float halfPi - eps: -1 - eps2: -1 - eps1eps2: 0)). + self assert: zero arcCos closeTo: (PMHyperDualNumber + value: Float halfPi + eps: -1 + eps2: -1 + eps1eps2: 0). a := (PMHyperDualNumber value: 1.0 predecessor eps: 1 eps2: 1 eps1eps2: 0) arcCos. - self assert: (a value closeTo: 0). + self assert: a value closeTo: 0. self assert: a eps < -1e6. self assert: a eps2 < -1e6. self assert: a eps1eps2 < -1e6 @@ -104,7 +104,7 @@ PMHyperDualNumberTest >> testArcSin [ eps: 1 eps2: 1 eps1eps2: 0) arcSin. - self assert: (a value closeTo: Float halfPi). + self assert: a value closeTo: Float halfPi. self assert: a eps > 1e6. self assert: a eps2 > 1e6. self assert: a eps1eps2 > 1e6 @@ -119,8 +119,8 @@ PMHyperDualNumberTest >> testArcTan [ eps: -1 / 2 eps2: -1 / 2 eps1eps2: 1 / 2). - self assert: (three arcTan eps2 closeTo: 0.1). - self assert: (three arcTan eps1eps2 closeTo: -3 / 50) + self assert: three arcTan eps2 closeTo: 0.1. + self assert: three arcTan eps1eps2 closeTo: -3 / 50 ] { #category : #tests } @@ -141,18 +141,21 @@ PMHyperDualNumberTest >> testConverting [ { #category : #'tests-mathematical functions' } PMHyperDualNumberTest >> testCos [ - self assert: ((PMHyperDualNumber - value: Float halfPi negated - eps: 1 - eps2: 1 - eps1eps2: 0) cos closeTo: zero). - self assert: ((PMHyperDualNumber - value: Float halfPi - eps: 1 - eps2: 1 - eps1eps2: 0) cos closeTo: zero negated). - self assert: - ((PMHyperDualNumber value: Float halfPi) cos closeTo: zeroc) + self + assert: (PMHyperDualNumber + value: Float halfPi negated + eps: 1 + eps2: 1 + eps1eps2: 0) cos + closeTo: zero. + self + assert: (PMHyperDualNumber + value: Float halfPi + eps: 1 + eps2: 1 + eps1eps2: 0) cos + closeTo: zero negated. + self assert: (PMHyperDualNumber value: Float halfPi) cos closeTo: zeroc ] { #category : #'tests-arithmetic' } @@ -203,24 +206,24 @@ PMHyperDualNumberTest >> testEqual [ { #category : #tests } PMHyperDualNumberTest >> testEqualsTo [ - self assert: (zeroc closeTo: zeroc). - self deny: (zeroc closeTo: zero). - self assert: (zero closeTo: zero). - self assert: (one closeTo: (PMHyperDualNumber - value: 1.0000000001 - eps: 1.0000000001 - eps2: 1.0000000001 - eps1eps2: 0.0000000001)). - self deny: (one closeTo: (PMHyperDualNumber - value: 1.0000000001 - eps: 1.0000000001 - eps2: 1.0000000001 - eps1eps2: 0.001)). - self deny: (one closeTo: (PMHyperDualNumber - value: 1.0000000001 - eps: 1.0000000001 - eps2: 1.001 - eps1eps2: 0.0000000001)) + self assert: zeroc closeTo: zeroc. + self deny: zeroc closeTo: zero. + self assert: zero closeTo: zero. + self assert: one closeTo: (PMHyperDualNumber + value: 1.0000000001 + eps: 1.0000000001 + eps2: 1.0000000001 + eps1eps2: 0.0000000001). + self deny: one closeTo: (PMHyperDualNumber + value: 1.0000000001 + eps: 1.0000000001 + eps2: 1.0000000001 + eps1eps2: 0.001). + self deny: one closeTo: (PMHyperDualNumber + value: 1.0000000001 + eps: 1.0000000001 + eps2: 1.001 + eps1eps2: 0.0000000001) ] { #category : #'tests-mathematical functions' } @@ -229,9 +232,9 @@ PMHyperDualNumberTest >> testExp [ | a b | b := 3 exp. a := three exp. - self assert: (a eps closeTo: b). - self assert: (a eps2 closeTo: b). - self assert: (a eps1eps2 closeTo: b). + self assert: a eps closeTo: b. + self assert: a eps2 closeTo: b. + self assert: a eps1eps2 closeTo: b. self assert: a value equals: b. self assert: one equals: zero exp ] @@ -267,9 +270,9 @@ PMHyperDualNumberTest >> testLn [ | a | a := three ln. - self assert: (a eps closeTo: 1 / 3). - self assert: (a eps2 closeTo: 1 / 3). - self assert: (a eps1eps2 closeTo: -1 / 9). + self assert: a eps closeTo: 1 / 3. + self assert: a eps2 closeTo: 1 / 3. + self assert: a eps1eps2 closeTo: -1 / 9. self assert: a value equals: 3 ln. self assert: one ln equals: zero ] @@ -333,33 +336,32 @@ PMHyperDualNumberTest >> testPrintOn [ PMHyperDualNumberTest >> testRaisedTo [ | a b | - self assert: ((three raisedTo: 2) closeTo: three squared). + self assert: (three raisedTo: 2) closeTo: three squared. self assertEquality: (three raisedTo: 0) and: onec. - self assert: - ((three + one raisedTo: 1 / 2) closeTo: (PMHyperDualNumber - value: 2 - eps: 1 / 2 - eps2: 1 / 2 - eps1eps2: -1 / 8)). + self assert: (three + one raisedTo: 1 / 2) closeTo: (PMHyperDualNumber + value: 2 + eps: 1 / 2 + eps2: 1 / 2 + eps1eps2: -1 / 8). self assertEquality: (zero raisedTo: 1.4) and: zeroc. a := 2 raisedTo: three. - self assert: (a value closeTo: 8). + self assert: a value closeTo: 8. b := 2 ln * (2 raisedTo: 3). - self assert: (a eps closeTo: b). - self assert: (a eps2 closeTo: b). - self assert: (a eps1eps2 closeTo: 2 ln * b). + self assert: a eps closeTo: b. + self assert: a eps2 closeTo: b. + self assert: a eps1eps2 closeTo: 2 ln * b. self assertEquality: (1 raisedTo: three) and: onec. - self assert: ((one raisedTo: one) closeTo: (PMHyperDualNumber - value: 1 - eps: 1 - eps2: 1 - eps1eps2: 2)). + self assert: (one raisedTo: one) closeTo: (PMHyperDualNumber + value: 1 + eps: 1 + eps2: 1 + eps1eps2: 2). a := three raisedTo: three. - self assert: (a value closeTo: 27). + self assert: a value closeTo: 27. b := 3 ln + 1 * 27. - self assert: (a eps closeTo: b). - self assert: (a eps2 closeTo: b). - self assert: (a eps1eps2 closeTo: b * (3 ln + 1) + 9) + self assert: a eps closeTo: b. + self assert: a eps2 closeTo: b. + self assert: a eps1eps2 closeTo: b * (3 ln + 1) + 9 ] { #category : #'tests-mathematical functions' } @@ -404,24 +406,28 @@ PMHyperDualNumberTest >> testReciprocal [ { #category : #'tests-mathematical functions' } PMHyperDualNumberTest >> testSin [ - self assert: ((PMHyperDualNumber - value: Float halfPi negated - eps: 1 - eps2: 1 - eps1eps2: 0) sin closeTo: (PMHyperDualNumber - value: -1 - eps: 0 - eps2: 0 - eps1eps2: 1)). - self assert: ((PMHyperDualNumber - value: Float halfPi - eps: 1 - eps2: 1 - eps1eps2: 0) sin closeTo: (PMHyperDualNumber - value: 1 - eps: 0 - eps2: 0 - eps1eps2: -1)). + self + assert: (PMHyperDualNumber + value: Float halfPi negated + eps: 1 + eps2: 1 + eps1eps2: 0) sin + closeTo: (PMHyperDualNumber + value: -1 + eps: 0 + eps2: 0 + eps1eps2: 1). + self + assert: (PMHyperDualNumber + value: Float halfPi + eps: 1 + eps2: 1 + eps1eps2: 0) sin + closeTo: (PMHyperDualNumber + value: 1 + eps: 0 + eps2: 0 + eps1eps2: -1). self assertEquality: zero sin and: zero ] @@ -467,15 +473,17 @@ PMHyperDualNumberTest >> testSqrt [ { #category : #'tests-mathematical functions' } PMHyperDualNumberTest >> testSquared [ - self assert: ((PMHyperDualNumber - value: -3 - eps: 5 - eps2: 1 - eps1eps2: 0) squared closeTo: (PMHyperDualNumber - value: 9 - eps: -30 - eps2: -6 - eps1eps2: 10)). + self + assert: (PMHyperDualNumber + value: -3 + eps: 5 + eps2: 1 + eps1eps2: 0) squared + closeTo: (PMHyperDualNumber + value: 9 + eps: -30 + eps2: -6 + eps1eps2: 10). zeroc eps1eps2: 2. self assertEquality: zero squared and: zeroc ] @@ -493,9 +501,9 @@ PMHyperDualNumberTest >> testTan [ | a | a := three tan. self assert: a value equals: 3 tan. - self assert: (a eps closeTo: 3 tan squared + 1). - self assert: (a eps closeTo: a eps2). - self assert: (a eps1eps2 closeTo: -0.2908860399427) + self assert: a eps closeTo: 3 tan squared + 1. + self assert: a eps closeTo: a eps2. + self assert: a eps1eps2 closeTo: -0.2908860399427 ] { #category : #'tests-testing' } diff --git a/src/Math-Tests-Clustering/PMClusterFinderTest.class.st b/src/Math-Tests-Clustering/PMClusterFinderTest.class.st index 05fa626d..6928f193 100644 --- a/src/Math-Tests-Clustering/PMClusterFinderTest.class.st +++ b/src/Math-Tests-Clustering/PMClusterFinderTest.class.st @@ -78,15 +78,12 @@ PMClusterFinderTest >> testClusterEuclidean [ { #category : #tests } PMClusterFinderTest >> testMahalanobisCenter [ - "Code example 12.5" | center distance | center := PMMahalanobisCenter new: 3. - #( #( 1 2 3 ) #( 2 3 4 ) #( 1 3 2 ) #( 4 3 1 ) #( 1 3 1 ) #( 1 4 2 ) - #( 3 1 2 ) #( 3 4 2 ) ) do: [ :x | - center accumulate: x asPMVector ]. + #( #( 1 2 3 ) #( 2 3 4 ) #( 1 3 2 ) #( 4 3 1 ) #( 1 3 1 ) #( 1 4 2 ) #( 3 1 2 ) #( 3 4 2 ) ) do: [ :x | center accumulate: x asPMVector ]. center computeParameters. distance := center distanceTo: #( 1 2 3 ) asPMVector. - self assert: (distance closeTo: 2.26602282704126) + self assert: distance closeTo: 2.26602282704126 ] diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index c14e34ee..efddcf78 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -23,14 +23,13 @@ PMComplexNumberTest >> testAbs [ { #category : #'testing - arithmetic' } PMComplexNumberTest >> testAbsSecure [ - "self run: #testAbsSecure" "using equalsTo since absSecure returns a slightly different Float" | c | c := 6 - 6 i. - self assert: (c absSecure closeTo: 72 sqrt) + self assert: c absSecure closeTo: 72 sqrt ] { #category : #'testing - arithmetic' } @@ -79,91 +78,98 @@ PMComplexNumberTest >> testAddingTwoComplexNumbers [ { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testArCosh [ + | c | - c := (2.5 + 0 i). - self assert: (c arCosh real closeTo: c real arCosh). - self assert: (c arCosh imaginary closeTo: 0). - #(-0.5 -2 -3 0 0.5 2 3) do: [:real | - #(-0.5 -2 -3 0 0.5 2 3) do: [:imag | - c := real + imag i. - self assert: (c arCosh cosh real closeTo: c real). - self assert: (c arCosh cosh imaginary closeTo: c imaginary). - self deny: c arCosh real negative]] + c := 2.5 + 0 i. + self assert: c arCosh real closeTo: c real arCosh. + self assert: c arCosh imaginary closeTo: 0. + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :real | + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :imag | + c := real + imag i. + self assert: c arCosh cosh real closeTo: c real. + self assert: c arCosh cosh imaginary closeTo: c imaginary. + self deny: c arCosh real negative ] ] ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testArSinh [ + | c | - c := (2.5 + 0 i). - self assert: (c arSinh real closeTo: c real arSinh). - self assert: (c arSinh imaginary closeTo: 0). - #(-0.5 -2 -3 0 0.5 2 3) do: [:real | - #(-0.5 -2 -3 0 0.5 2 3) do: [:imag | - c := real + imag i. - self assert: (c arSinh sinh real closeTo: c real). - self assert: (c arSinh sinh imaginary closeTo: c imaginary)]] + c := 2.5 + 0 i. + self assert: c arSinh real closeTo: c real arSinh. + self assert: c arSinh imaginary closeTo: 0. + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :real | + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :imag | + c := real + imag i. + self assert: c arSinh sinh real closeTo: c real. + self assert: c arSinh sinh imaginary closeTo: c imaginary ] ] ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testArTanh [ + | c | - c := (0.5 + 0 i). - self assert: (c arTanh real closeTo: c real arTanh). - self assert: (c arTanh imaginary closeTo: 0). - #(-0.5 -2 -3 0 0.5 2 3) do: [:real | - #(-0.5 -2 -3 0 0.5 2 3) do: [:imag | - c := real + imag i. - self assert: (c arTanh tanh real closeTo: c real). - self assert: (c arTanh tanh imaginary closeTo: c imaginary)]] + c := 0.5 + 0 i. + self assert: c arTanh real closeTo: c real arTanh. + self assert: c arTanh imaginary closeTo: 0. + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :real | + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :imag | + c := real + imag i. + self assert: c arTanh tanh real closeTo: c real. + self assert: c arTanh tanh imaginary closeTo: c imaginary ] ] ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testArcCos [ + | c | - c := (0.5 + 0 i). - self assert: (c arcCos real closeTo: c real arcCos). - self assert: (c arcCos imaginary closeTo: 0). - #(-0.5 -2 -3 0 0.5 2 3) do: [:real | - #(-0.5 -2 -3 0 0.5 2 3) do: [:imag | - c := real + imag i. - self assert: (c arcCos cos real closeTo: c real). - self assert: (c arcCos cos imaginary closeTo: c imaginary)]] + c := 0.5 + 0 i. + self assert: c arcCos real closeTo: c real arcCos. + self assert: c arcCos imaginary closeTo: 0. + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :real | + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :imag | + c := real + imag i. + self assert: c arcCos cos real closeTo: c real. + self assert: c arcCos cos imaginary closeTo: c imaginary ] ] ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testArcCosPlusArcSin [ + | c | - #(-0.5 -2 -3 0 0.5 2 3) do: [:real | - #(-0.5 -2 -3 0 0.5 2 3) do: [:imag | - c := real + imag i. - self assert: ((c arcCos + c arcSin) real closeTo: Float halfPi). - self assert: ((c arcCos + c arcSin) imaginary closeTo: 0.0)]] + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :real | + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :imag | + c := real + imag i. + self assert: (c arcCos + c arcSin) real closeTo: Float halfPi. + self assert: (c arcCos + c arcSin) imaginary closeTo: 0.0 ] ] ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testArcSin [ + | c | - c := (0.5 + 0 i). - self assert: (c arcSin real closeTo: c real arcSin). - self assert: (c arcSin imaginary closeTo: 0). - #(-0.5 -2 -3 0 0.5 2 3) do: [:real | - #(-0.5 -2 -3 0 0.5 2 3) do: [:imag | - c := real + imag i. - self assert: (c arcSin sin real closeTo: c real). - self assert: (c arcSin sin imaginary closeTo: c imaginary)]] + c := 0.5 + 0 i. + self assert: c arcSin real closeTo: c real arcSin. + self assert: c arcSin imaginary closeTo: 0. + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :real | + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :imag | + c := real + imag i. + self assert: c arcSin sin real closeTo: c real. + self assert: c arcSin sin imaginary closeTo: c imaginary ] ] ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testArcTan [ + | c | - c := (0.5 + 0 i). - self assert: (c arcTan real closeTo: c real arcTan). - self assert: (c arcTan imaginary closeTo: 0). - #(-0.5 -2 -3 0 0.5 2 3) do: [:real | - #(-0.5 -2 -3 0 0.5 2 3) do: [:imag | - c := real + imag i. - self assert: (c arcTan tan real closeTo: c real). - self assert: (c arcTan tan imaginary closeTo: c imaginary)]] + c := 0.5 + 0 i. + self assert: c arcTan real closeTo: c real arcTan. + self assert: c arcTan imaginary closeTo: 0. + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :real | + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :imag | + c := real + imag i. + self assert: c arcTan tan real closeTo: c real. + self assert: c arcTan tan imaginary closeTo: c imaginary ] ] ] { #category : #'testing - mathematical functions' } @@ -249,49 +255,53 @@ PMComplexNumberTest >> testComplexNumberAndIntegerAreUnequalEvenIfRealPartIsEqua { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testCos [ + | c c2 | - c := (2 + 0 i). - self assert: (c cos real closeTo: c real cos). - self assert: (c cos imaginary closeTo: 0). - c := (2 + 3 i). + c := 2 + 0 i. + self assert: c cos real closeTo: c real cos. + self assert: c cos imaginary closeTo: 0. + c := 2 + 3 i. c2 := c i exp + c i negated exp / 2. - self assert: (c cos real closeTo: c2 real). - self assert: (c cos imaginary closeTo: c2 imaginary) + self assert: c cos real closeTo: c2 real. + self assert: c cos imaginary closeTo: c2 imaginary ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testCos2PlusSin2 [ + | c | - #(-0.5 -2 -3 0 0.5 2 3) do: [:real | - #(-0.5 -2 -3 0 0.5 2 3) do: [:imag | - c := real + imag i. - self assert: ((c cos squared + c sin squared) real closeTo: 1). - self assert: ((c cos squared + c sin squared) imaginary closeTo: 0.0)]] + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :real | + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :imag | + c := real + imag i. + self assert: (c cos squared + c sin squared) real closeTo: 1. + self assert: (c cos squared + c sin squared) imaginary closeTo: 0.0 ] ] ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testCosh [ + | c c2 | - c := (2 + 0 i). - self assert: (c cosh real closeTo: c real cosh). - self assert: (c cosh imaginary closeTo: 0). - c := (2 + 3 i). + c := 2 + 0 i. + self assert: c cosh real closeTo: c real cosh. + self assert: c cosh imaginary closeTo: 0. + c := 2 + 3 i. c2 := c exp + c negated exp / 2. - self assert: (c cosh real closeTo: c2 real). - self assert: (c cosh imaginary closeTo: c2 imaginary). + self assert: c cosh real closeTo: c2 real. + self assert: c cosh imaginary closeTo: c2 imaginary. c2 := c i cos. - self assert: (c cosh real closeTo: c2 real). - self assert: (c cosh imaginary closeTo: c2 imaginary) + self assert: c cosh real closeTo: c2 real. + self assert: c cosh imaginary closeTo: c2 imaginary ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testCosh2MinusSinh2 [ + | c | - #(-0.5 -2 -3 0 0.5 2 3) do: [:real | - #(-0.5 -2 -3 0 0.5 2 3) do: [:imag | - c := real + imag i. - self assert: ((c cosh squared - c sinh squared) real closeTo: 1). - self assert: ((c cosh squared - c sinh squared) imaginary closeTo: 0.0)]] + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :real | + #( -0.5 -2 -3 0 0.5 2 3 ) do: [ :imag | + c := real + imag i. + self assert: (c cosh squared - c sinh squared) real closeTo: 1. + self assert: (c cosh squared - c sinh squared) imaginary closeTo: 0.0 ] ] ] { #category : #'testing - expressing complex numbers' } @@ -621,10 +631,10 @@ PMComplexNumberTest >> testQuotientsOfComplexNumbersCannotBeWritten [ PMComplexNumberTest >> testRaisedTo [ | c c3 | - c := (5 - 6 i). + c := 5 - 6 i. c3 := (c raisedTo: 0.2) raisedTo: 5. - self assert: (c3 real closeTo: c real). - self assert: (c3 imaginary closeTo: c imaginary) + self assert: c3 real closeTo: c real. + self assert: c3 imaginary closeTo: c imaginary ] { #category : #'testing - mathematical functions' } @@ -683,32 +693,34 @@ PMComplexNumberTest >> testSecureDivision2 [ { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testSin [ + | c c2 | - c := (2 + 0 i). - self assert: (c sin real closeTo: c real sin). - self assert: (c sin imaginary closeTo: 0). + c := 2 + 0 i. + self assert: c sin real closeTo: c real sin. + self assert: c sin imaginary closeTo: 0. c := 2 + 3 i. c2 := c i exp - c i negated exp / 2 i. - self assert: (c sin real closeTo: c2 real). - self assert: (c sin imaginary closeTo: c2 imaginary) + self assert: c sin real closeTo: c2 real. + self assert: c sin imaginary closeTo: c2 imaginary ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testSinh [ + | c c2 | - c := (2 + 0 i). - self assert: (c sinh real closeTo: c real sinh). - self assert: (c sinh imaginary closeTo: 0). + c := 2 + 0 i. + self assert: c sinh real closeTo: c real sinh. + self assert: c sinh imaginary closeTo: 0. c := 2 + 3 i. c := c cosh squared - c sinh squared. - self assert: (c real closeTo: 1). - self assert: (c imaginary closeTo: 0). + self assert: c real closeTo: 1. + self assert: c imaginary closeTo: 0. c2 := c exp - c negated exp / 2. - self assert: (c sinh real closeTo: c2 real). - self assert: (c sinh imaginary closeTo: c2 imaginary). + self assert: c sinh real closeTo: c2 real. + self assert: c sinh imaginary closeTo: c2 imaginary. c2 := c i sin i negated. - self assert: (c sinh real closeTo: c2 real). - self assert: (c sinh imaginary closeTo: c2 imaginary) + self assert: c sinh real closeTo: c2 real. + self assert: c sinh imaginary closeTo: c2 imaginary ] { #category : #'testing - mathematical functions' } @@ -843,26 +855,28 @@ PMComplexNumberTest >> testSubtractingPolynomials [ { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testTan [ + | c c2 | - c := (2 + 0 i). - self assert: (c tan real closeTo: c real tan). - self assert: (c tan imaginary closeTo: 0). + c := 2 + 0 i. + self assert: c tan real closeTo: c real tan. + self assert: c tan imaginary closeTo: 0. c := 2 + 3 i. c2 := c sin / c cos. - self assert: (c2 real closeTo: c tan real). - self assert: (c2 imaginary closeTo: c tan imaginary) + self assert: c2 real closeTo: c tan real. + self assert: c2 imaginary closeTo: c tan imaginary ] { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testTanh [ + | c c2 | - c := (2 + 0 i). - self assert: (c tanh real closeTo: c real tanh). - self assert: (c tanh imaginary closeTo: 0). + c := 2 + 0 i. + self assert: c tanh real closeTo: c real tanh. + self assert: c tanh imaginary closeTo: 0. c := 2 + 3 i. c2 := c sinh / c cosh. - self assert: (c2 real closeTo: c tanh real). - self assert: (c2 imaginary closeTo: c tanh imaginary) + self assert: c2 real closeTo: c tanh real. + self assert: c2 imaginary closeTo: c tanh imaginary ] { #category : #'testing - equality' } diff --git a/src/Math-Tests-Core-Process/PMFixpointTest.class.st b/src/Math-Tests-Core-Process/PMFixpointTest.class.st index d499a754..d69f8030 100644 --- a/src/Math-Tests-Core-Process/PMFixpointTest.class.st +++ b/src/Math-Tests-Core-Process/PMFixpointTest.class.st @@ -102,7 +102,7 @@ PMFixpointTest >> testRest [ fp := PMFixpoint block: [ :x | 1 / (1 + x) ] value: 20.0. self assert: fp cycle equals: #( ). - self assert: (fp evaluate closeTo: 0.6180339887). + self assert: fp evaluate closeTo: 0.6180339887. fp verbose: false. self assert: fp cycle size equals: 1. self assert: fp hasConverged. diff --git a/src/Math-Tests-Distributions/PMKolmogorovSmirnov1SampleTest.class.st b/src/Math-Tests-Distributions/PMKolmogorovSmirnov1SampleTest.class.st index bb8b5731..079d4880 100644 --- a/src/Math-Tests-Distributions/PMKolmogorovSmirnov1SampleTest.class.st +++ b/src/Math-Tests-Distributions/PMKolmogorovSmirnov1SampleTest.class.st @@ -64,7 +64,7 @@ PMKolmogorovSmirnov1SampleTest >> testWrongDistributionProbabilistic [ "wrong distribution with the correct mean and sd" d := PMLaplaceDistribution shape: 0 scale: (1 / 2) sqrt. self assert: d average equals: 0. - self assert: (d standardDeviation closeTo: 1). + self assert: d standardDeviation closeTo: 1. d := self numberOfRejectionsFor: d. self assert: d > 60 ] diff --git a/src/Math-Tests-Distributions/PMSmoothedDensityTest.class.st b/src/Math-Tests-Distributions/PMSmoothedDensityTest.class.st index 30119fce..4b825d09 100644 --- a/src/Math-Tests-Distributions/PMSmoothedDensityTest.class.st +++ b/src/Math-Tests-Distributions/PMSmoothedDensityTest.class.st @@ -17,7 +17,7 @@ PMSmoothedDensityTest >> setUp [ { #category : #tests } PMSmoothedDensityTest >> testAverage [ - self assert: (density data average closeTo: density average) + self assert: density data average closeTo: density average ] { #category : #tests } @@ -26,15 +26,15 @@ PMSmoothedDensityTest >> testBandWidth [ density bandWidth: 2. self assert: density bandWidth equals: 2. density ruleOfThumbBandWidth. - self assert: (density bandWidth closeTo: 0.505899674). + self assert: density bandWidth closeTo: 0.505899674. density data: #( 1 2 3 1 2.3 2.4 7 ). density ruleOfThumbBandWidth. - self assert: (density bandWidth closeTo: 0.728178892). + self assert: density bandWidth closeTo: 0.728178892. density data: #( 1 2 3 1 2.3 2.4 7 -7 ). density epanechnikov. - self assert: (density bandWidth closeTo: 0.728178892). + self assert: density bandWidth closeTo: 0.728178892. density ruleOfThumbBandWidth. - self assert: (density bandWidth closeTo: 0.753301158) + self assert: density bandWidth closeTo: 0.753301158 ] { #category : #tests } @@ -42,12 +42,12 @@ PMSmoothedDensityTest >> testDistributionValue [ self assert: (density distributionValue: 500) equals: 1. self assert: (density distributionValue: -500) equals: 0. - self assert: ((density distributionValue: 2) closeTo: 0.494519759). - self assert: ((density distributionValue: 3) closeTo: 0.8791407588). + self assert: (density distributionValue: 2) closeTo: 0.494519759. + self assert: (density distributionValue: 3) closeTo: 0.8791407588. density epanechnikov. self assert: (density distributionValue: 5) equals: 1. self assert: (density distributionValue: -1) equals: 0. - self assert: ((density distributionValue: 2) closeTo: 0.506985855) + self assert: (density distributionValue: 2) closeTo: 0.506985855 ] { #category : #tests } @@ -60,8 +60,8 @@ PMSmoothedDensityTest >> testEpanechnikov [ self assert: (density kernel value: f negated) equals: 0. self assert: (density kernel value: 0) equals: 3 / (4 * f). f := 3 / (5 * f). - self assert: ((density kernel value: 1) closeTo: f). - self assert: ((density kernel value: -1) closeTo: f). + self assert: (density kernel value: 1) closeTo: f. + self assert: (density kernel value: -1) closeTo: f. f := ReadWriteStream with: ''. density printOn: f. self assert: (f contents findString: 'epanechnikov') > 0 @@ -71,7 +71,7 @@ PMSmoothedDensityTest >> testEpanechnikov [ PMSmoothedDensityTest >> testIKernel [ density iKernel: [ :x | x ]. - self assert: ((density distributionValue: 1) closeTo: -1.87784268) + self assert: (density distributionValue: 1) closeTo: -1.87784268 ] { #category : #tests } @@ -91,13 +91,11 @@ PMSmoothedDensityTest >> testNormal [ | r | density normal. r := 0.2419707245. - self assert: - ((#( 1 0 -1 -2.9 ) collect: [ :x | density kernel value: x ]) - closeTo: (Array - with: r - with: 0.3989422804 - with: r - with: 0.0059525324197)) + self assert: (#( 1 0 -1 -2.9 ) collect: [ :x | density kernel value: x ]) closeTo: (Array + with: r + with: 0.3989422804 + with: r + with: 0.0059525324197) ] { #category : #tests } @@ -117,12 +115,11 @@ self assert: ((s findString: '0.50589967')>0) { #category : #tests } PMSmoothedDensityTest >> testValue [ - self assert: ((density value: 0.5) closeTo: 0.1632610644). - self assert: - ((density value: #( 0.5 1 )) closeTo: #( 0.1632610644 0.28923996 )). + self assert: (density value: 0.5) closeTo: 0.1632610644. + self assert: (density value: #( 0.5 1 )) closeTo: #( 0.1632610644 0.28923996 ). density epanechnikov. self assert: (density value: -0.4) equals: 0. - self assert: ((density value: 0.5) closeTo: 0.177824205). + self assert: (density value: 0.5) closeTo: 0.177824205. self assert: (density value: 5) equals: 0 ] @@ -131,7 +128,7 @@ PMSmoothedDensityTest >> testVariance [ | v | v := density variance. - self assert: (density standardDeviation closeTo: v sqrt). + self assert: density standardDeviation closeTo: v sqrt. self assert: density data stdev < v sqrt. - self assert: (v closeTo: 0.902934480) + self assert: v closeTo: 0.902934480 ] diff --git a/src/Math-Tests-Distributions/PMStatisticsBugs.class.st b/src/Math-Tests-Distributions/PMStatisticsBugs.class.st index 821a151a..5c836bde 100644 --- a/src/Math-Tests-Distributions/PMStatisticsBugs.class.st +++ b/src/Math-Tests-Distributions/PMStatisticsBugs.class.st @@ -9,7 +9,7 @@ PMStatisticsBugs >> testAsymptoticChiSquareDistribution [ | a | a := PMAsymptoticChiSquareDistribution degreeOfFreedom: 18. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.8)) closeTo: 0.8) + self assert: (a distributionValue: (a inverseDistributionValue: 0.8)) closeTo: 0.8 "Supplied derivative is not correct" ] @@ -24,31 +24,31 @@ PMStatisticsBugs >> testBetaDistribution [ self assert: (d distributionValue: -2) equals: 0. a := PMBetaDistribution shape: 2 shape: 3.1. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9). + self assert: (a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5). + self assert: (a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5. "zerodivide" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 1)) closeTo: 1). + self assert: (a distributionValue: (a inverseDistributionValue: 1)) closeTo: 1. "zerod" a := PMBetaDistribution shape: 0.9 shape: 0.9. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9). + self assert: (a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5). + self assert: (a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a inverseDistributionValue: 0) closeTo: 0). + self assert: (a inverseDistributionValue: 0) closeTo: 0. "zerod" - self assert: ((a inverseDistributionValue: 1) closeTo: 1). + self assert: (a inverseDistributionValue: 1) closeTo: 1. "zerod" a := PMBetaDistribution shape: 9 shape: 0.29. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9). + self assert: (a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5). + self assert: (a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. "ok" - self assert: ((a inverseDistributionValue: 1.0) closeTo: 1) + self assert: (a inverseDistributionValue: 1.0) closeTo: 1 "zerod" ] @@ -61,13 +61,13 @@ PMStatisticsBugs >> testCauchyDistribution [ self assert: (a inverseDistributionValue: 0) equals: Float infinity negated. self assert: (a inverseDistributionValue: 1) equals: Float infinity. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9). + self assert: (a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9. "ok" self assert: (a inverseDistributionValue: 0.5) equals: -40.2. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. "zerod, which in this case is ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1) + self assert: (a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1 "ok" ] @@ -76,23 +76,23 @@ PMStatisticsBugs >> testChiSquareDistribution [ | a | a := PMChiSquareDistribution degreeOfFreedom: 3. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.7)) closeTo: 0.7). + self assert: (a distributionValue: (a inverseDistributionValue: 0.7)) closeTo: 0.7. "zerodivide" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.004)) closeTo: 0.004). + self assert: (a distributionValue: (a inverseDistributionValue: 0.004)) closeTo: 0.004. "zerodivide" a := PMChiSquareDistribution degreeOfFreedom: 300. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.7)) closeTo: 0.7). + self assert: (a distributionValue: (a inverseDistributionValue: 0.7)) closeTo: 0.7. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.004)) closeTo: 0.004). + self assert: (a distributionValue: (a inverseDistributionValue: 0.004)) closeTo: 0.004. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1) + self assert: (a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1 "zerodivide" ] @@ -101,13 +101,13 @@ PMStatisticsBugs >> testExponentialDistribution [ | a | a := PMExponentialDistribution new. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.99)) closeTo: 0.99). + self assert: (a distributionValue: (a inverseDistributionValue: 0.99)) closeTo: 0.99. "ok " - self assert: ((a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5). + self assert: (a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1) + self assert: (a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1 "ok" ] @@ -116,27 +116,28 @@ PMStatisticsBugs >> testFisherSnedecorDistribution [ | a | a := PMFisherSnedecorDistribution degreeOfFreedom: 100 degreeOfFreedom: 200. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.8)) closeTo: 0.8). + self assert: (a distributionValue: (a inverseDistributionValue: 0.8)) closeTo: 0.8. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.6)) closeTo: 0.6). + self assert: (a distributionValue: (a inverseDistributionValue: 0.6)) closeTo: 0.6. "zerodivide" a := PMFisherSnedecorDistribution degreeOfFreedom: 5 degreeOfFreedom: 6. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.8)) closeTo: 0.8). + self assert: (a distributionValue: (a inverseDistributionValue: 0.8)) closeTo: 0.8. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.6)) closeTo: 0.6) + self assert: (a distributionValue: (a inverseDistributionValue: 0.6)) closeTo: 0.6 "zerodivide" ] { #category : #tests } PMStatisticsBugs >> testFisherTippet [ + | d | d := PMFisherTippettDistribution new. - self assert: ((d integralFrom: -10 to: -0.1) closeTo: (d distributionValue: -0.1)). - self assert: ((d integralUpTo: -0.1) closeTo: (d distributionValue: -0.1)). - self assert: ((d integralFrom: -10 to: 0.1) closeTo: (d distributionValue: 0.1)) + self assert: (d integralFrom: -10 to: -0.1) closeTo: (d distributionValue: -0.1). + self assert: (d integralUpTo: -0.1) closeTo: (d distributionValue: -0.1). + self assert: (d integralFrom: -10 to: 0.1) closeTo: (d distributionValue: 0.1) ] { #category : #tests } @@ -155,23 +156,23 @@ PMStatisticsBugs >> testFisherTippetDistribution [ | a | a := PMFisherTippettDistribution new. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9). + self assert: (a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9. "zerodivide" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.001)) closeTo: 0.001). + self assert: (a distributionValue: (a inverseDistributionValue: 0.001)) closeTo: 0.001. "ok" a := PMFisherTippettDistribution shape: -3 scale: 0.7. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9). + self assert: (a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9. "zerodivide" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.4)) closeTo: 0.4). + self assert: (a distributionValue: (a inverseDistributionValue: 0.4)) closeTo: 0.4. "zerodivide" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1) + self assert: (a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1 "zerodivide" ] @@ -187,13 +188,13 @@ PMStatisticsBugs >> testGammaDistribution [ a := PMGammaDistribution shape: 2 scale: 1. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.99)) closeTo: 0.99). + self assert: (a distributionValue: (a inverseDistributionValue: 0.99)) closeTo: 0.99. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5). + self assert: (a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5. "zerod" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. "zerod" - self assert: ((a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1) + self assert: (a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1 "zerod" ] @@ -207,11 +208,11 @@ PMStatisticsBugs >> testHistogramDistribution [ 20 timesRepeat: [ a accumulate: (random nextBetween: 0 and: 7) ]. b := PMHistogrammedDistribution histogram: a. - self assert: ((b distributionValue: (b inverseDistributionValue: 0.99)) closeTo: 0.99). + self assert: (b distributionValue: (b inverseDistributionValue: 0.99)) closeTo: 0.99. "ok" - self assert: ((b distributionValue: (b inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (b distributionValue: (b inverseDistributionValue: 0.0)) closeTo: 0. "ok" - self assert: ((b distributionValue: (b inverseDistributionValue: 1.0) asFloat) closeTo: 1) + self assert: (b distributionValue: (b inverseDistributionValue: 1.0) asFloat) closeTo: 1 "ok" ] @@ -221,14 +222,14 @@ PMStatisticsBugs >> testKernelSmoothingDensity [ | a | a := PMKernelSmoothedDensity fromData: #( 1 2 3 1 2.3 2.4 ). a epanechnikov. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9). + self assert: (a distributionValue: (a inverseDistributionValue: 0.9)) closeTo: 0.9. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5). + self assert: (a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5. "zerod" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. " -0.13122605895944042" "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1) + self assert: (a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1 "zerod" ] @@ -237,11 +238,11 @@ PMStatisticsBugs >> testLeplaceDistribution [ | a | a := PMLaplaceDistribution new. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.99)) closeTo: 0.99). + self assert: (a distributionValue: (a inverseDistributionValue: 0.99)) closeTo: 0.99. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1) + self assert: (a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1 "zerod" ] @@ -250,19 +251,19 @@ PMStatisticsBugs >> testLogNormalDistribution [ | a | a := PMLogNormalDistribution new. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.7)) closeTo: 0.7). + self assert: (a distributionValue: (a inverseDistributionValue: 0.7)) closeTo: 0.7. "zerodivide" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.004)) closeTo: 0.004). + self assert: (a distributionValue: (a inverseDistributionValue: 0.004)) closeTo: 0.004. "zerodivide" a := PMLogNormalDistribution new: 3 sigma: 1.4. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.7)) closeTo: 0.7). + self assert: (a distributionValue: (a inverseDistributionValue: 0.7)) closeTo: 0.7. "zerodivide" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. "zerodivide" self assert: ((a distributionValue: (a inverseDistributionValue: 1.0)) - 1) abs < 3e-7. "equalsTo: is a too strong condition in this case" a := PMLogNormalDistribution new: 3 sigma: 3. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.7)) closeTo: 0.7) + self assert: (a distributionValue: (a inverseDistributionValue: 0.7)) closeTo: 0.7 "zerodivide" ] @@ -275,24 +276,25 @@ PMStatisticsBugs >> testNormalDistribution [ "ocassionally 'Supplied derivative is not correct'" a := PMNormalDistribution new: 2 sigma: 0.7. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.8)) closeTo: 0.8). + self assert: (a distributionValue: (a inverseDistributionValue: 0.8)) closeTo: 0.8. "'Function''s derivative seems to be zero everywhere'" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.6)) closeTo: 0.6). + self assert: (a distributionValue: (a inverseDistributionValue: 0.6)) closeTo: 0.6. "zerodivide" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). - self assert: ((a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1) + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. + self assert: (a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1 "zerodivide" ] { #category : #tests } PMStatisticsBugs >> testProbabilityDensityWithUnknownDistribution [ + | d | d := PMLogNormalDistribution new. - self assert: ((d distributionValue: 1) closeTo: 0.5). - self assert: ((d distributionValue: 3.602) closeTo: 0.9). - self assert: ((d acceptanceBetween: 1 and: 3.602) closeTo: 0.4) + self assert: (d distributionValue: 1) closeTo: 0.5. + self assert: (d distributionValue: 3.602) closeTo: 0.9. + self assert: (d acceptanceBetween: 1 and: 3.602) closeTo: 0.4 ] { #category : #tests } @@ -300,9 +302,9 @@ PMStatisticsBugs >> testStudentDistribution [ | a | a := PMStudentDistribution degreeOfFreedom: 5. - self assert: ((a distributionValue: (a inverseDistributionValue: 1)) closeTo: 1). + self assert: (a distributionValue: (a inverseDistributionValue: 1)) closeTo: 1. "zerodivide" - self assert: ((a distributionValue: (a inverseDistributionValue: 0)) closeTo: 0) + self assert: (a distributionValue: (a inverseDistributionValue: 0)) closeTo: 0 "well, ok" ] @@ -314,9 +316,9 @@ PMStatisticsBugs >> testTriangularDistribution [ | a | a := PMTriangularDistribution new: 0.6 from: -1 to: 3. - self assert: ((a distributionValue: (a inverseDistributionValue: 1)) closeTo: 1). + self assert: (a distributionValue: (a inverseDistributionValue: 1)) closeTo: 1. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 0)) closeTo: 0) + self assert: (a distributionValue: (a inverseDistributionValue: 0)) closeTo: 0 "ok" ] @@ -325,11 +327,11 @@ PMStatisticsBugs >> testUniformDistribution [ | a | a := PMUniformDistribution from: 0 to: 3. - self assert: ((a distributionValue: (a inverseDistributionValue: 1)) closeTo: 1). + self assert: (a distributionValue: (a inverseDistributionValue: 1)) closeTo: 1. "ok " - self assert: ((a distributionValue: (a inverseDistributionValue: 0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0)) closeTo: 0. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.333333)) closeTo: 0.333333) + self assert: (a distributionValue: (a inverseDistributionValue: 0.333333)) closeTo: 0.333333 "ok" ] @@ -338,12 +340,12 @@ PMStatisticsBugs >> testWeibullDistribution [ | a | a := PMWeibullDistribution shape: 0.5 scale: 1. - self assert: ((a distributionValue: (a inverseDistributionValue: 0.99)) closeTo: 0.99). + self assert: (a distributionValue: (a inverseDistributionValue: 0.99)) closeTo: 0.99. "ok " - self assert: ((a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5). + self assert: (a distributionValue: (a inverseDistributionValue: 0.5)) closeTo: 0.5. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0). + self assert: (a distributionValue: (a inverseDistributionValue: 0.0)) closeTo: 0. "ok" - self assert: ((a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1) + self assert: (a distributionValue: (a inverseDistributionValue: 1.0)) closeTo: 1 "ok" ] diff --git a/src/Math-Tests-FunctionFit/PMAnotherGeneticOptimizerTest.class.st b/src/Math-Tests-FunctionFit/PMAnotherGeneticOptimizerTest.class.st index 766a3976..5c192004 100644 --- a/src/Math-Tests-FunctionFit/PMAnotherGeneticOptimizerTest.class.st +++ b/src/Math-Tests-FunctionFit/PMAnotherGeneticOptimizerTest.class.st @@ -47,7 +47,7 @@ PMAnotherGeneticOptimizerTest >> testEvaluate [ geneticOptimizer maximumIterations: 170. geneticOptimizer chromosomeManager populationSize: 50. - self assert: (geneticOptimizer evaluate closeTo: #( 0 0 0 )) + self assert: geneticOptimizer evaluate closeTo: #( 0 0 0 ) ] { #category : #tests } @@ -79,11 +79,11 @@ PMAnotherGeneticOptimizerTest >> testPrint [ PMAnotherGeneticOptimizerTest >> testRangeScale [ geneticOptimizer initializeIterations. - self assert: (geneticOptimizer rangeScale first closeTo: 0.1). - self assert: (geneticOptimizer rangeScale second closeTo: 0.19473684210526315). + self assert: geneticOptimizer rangeScale first closeTo: 0.1. + self assert: geneticOptimizer rangeScale second closeTo: 0.19473684210526315. geneticOptimizer initializeIterations. - self assert: (geneticOptimizer rangeScale first closeTo: 0.1). - self assert: (geneticOptimizer rangeScale second closeTo: 0.19473684210526315) + self assert: geneticOptimizer rangeScale first closeTo: 0.1. + self assert: geneticOptimizer rangeScale second closeTo: 0.19473684210526315 ] { #category : #tests } diff --git a/src/Math-Tests-FunctionFit/PMErrorMinimizerTest.class.st b/src/Math-Tests-FunctionFit/PMErrorMinimizerTest.class.st index 1ee1985e..bcb8fafe 100644 --- a/src/Math-Tests-FunctionFit/PMErrorMinimizerTest.class.st +++ b/src/Math-Tests-FunctionFit/PMErrorMinimizerTest.class.st @@ -19,5 +19,5 @@ PMErrorMinimizerTest >> testErrorMinimizer [ fit := PMErrorMinimizer function: er. fit evaluate. self assert: fit maxFunction > 2. - self assert: (fit parameters closeTo: #( 2 0.4 )) + self assert: fit parameters closeTo: #( 2 0.4 ) ] diff --git a/src/Math-Tests-FunctionFit/PMFunctionFitTest.class.st b/src/Math-Tests-FunctionFit/PMFunctionFitTest.class.st index 55360ecb..edae74c9 100644 --- a/src/Math-Tests-FunctionFit/PMFunctionFitTest.class.st +++ b/src/Math-Tests-FunctionFit/PMFunctionFitTest.class.st @@ -32,7 +32,7 @@ PMFunctionFitTest >> testFunctionFit [ self shouldnt: [ ff accumulate: p ] raise: Error. "function result will be NaN and should be ignored in the following calculations" ff parameters: ar. ff evaluate. - self assert: (ff parameters closeTo: #( 2 0.4 )) + self assert: ff parameters closeTo: #( 2 0.4 ) ] { #category : #tests } diff --git a/src/Math-Tests-FunctionFit/PMGeneralFunctionFitTest.class.st b/src/Math-Tests-FunctionFit/PMGeneralFunctionFitTest.class.st index 39fc4cb5..d4a86dbd 100644 --- a/src/Math-Tests-FunctionFit/PMGeneralFunctionFitTest.class.st +++ b/src/Math-Tests-FunctionFit/PMGeneralFunctionFitTest.class.st @@ -31,7 +31,7 @@ PMGeneralFunctionFitTest >> setUp [ PMGeneralFunctionFitTest >> testBasic [ | d | - self assert: (fit evaluate closeTo: #( 0.1 0.4 )). + self assert: fit evaluate closeTo: #( 0.1 0.4 ). (fit result - #( 0.1 0.4 )) abs with: (fit secondaryResult - #( 0.1 0.4 )) abs do: [ :e :s | self assert: s - e > 0 ]. d := fit error: fit secondaryResult. self assert: d < 1e-5. @@ -44,7 +44,7 @@ PMGeneralFunctionFitTest >> testFunction [ | y | y := fit function value: 3 value: 0.1 value: 0.4. fit evaluate. - self assert: ((fit function value: 3) closeTo: y) + self assert: (fit function value: 3) closeTo: y ] { #category : #tests } @@ -122,7 +122,7 @@ PMGeneralFunctionFitTest >> testRelativeError [ fit manager randomGenerator: (Random seed: 42). fit populationSize: 10. r := fit evaluate first. - self assert: (r closeTo: 4). + self assert: r closeTo: 4. fit errorType: #abs. fit relativeError: true. r := fit evaluate first. @@ -155,7 +155,7 @@ PMGeneralFunctionFitTest >> testTruncate [ fit manager randomGenerator: (Random seed: 42). fit errorType: #quartile. - self assert: (fit findQuartile closeTo: #( 0.1 0.4 )). + self assert: fit findQuartile closeTo: #( 0.1 0.4 ). self assert: fit quartile < (79 / 81). self assert: fit quartile > (75 / 81). self deny: fit dataTruncated. @@ -164,7 +164,7 @@ PMGeneralFunctionFitTest >> testTruncate [ self assert: fit optimizer functionBlock data size equals: fit quartile * col size. fit errorType: #abs. self assert: fit errorType equals: #abs. - self assert: (fit evaluate closeTo: #( 0.1 0.4 )). + self assert: fit evaluate closeTo: #( 0.1 0.4 ). fit resetData. self assert: fit optimizer functionBlock data size equals: col size ] diff --git a/src/Math-Tests-FunctionFit/PMSimpleParameterFunctionTest.class.st b/src/Math-Tests-FunctionFit/PMSimpleParameterFunctionTest.class.st index d3464155..32297b92 100644 --- a/src/Math-Tests-FunctionFit/PMSimpleParameterFunctionTest.class.st +++ b/src/Math-Tests-FunctionFit/PMSimpleParameterFunctionTest.class.st @@ -48,7 +48,7 @@ PMSimpleParameterFunctionTest >> testRest [ self assert: s parameters size equals: 3. vg := s valueAndGradient: 2. self assert: s parameters first equals: vg first. - self assert: (vg second closeTo: #( 1 0 0 )). + self assert: vg second closeTo: #( 1 0 0 ). s parameters: #( 2 0 0 ). self assert: (s value: 0) equals: 2. self assert: s parameters equals: #( 2 0 0 ). diff --git a/src/Math-Tests-KDTree/PMKDTreeTest.class.st b/src/Math-Tests-KDTree/PMKDTreeTest.class.st index 2ea88861..fe98a2d6 100644 --- a/src/Math-Tests-KDTree/PMKDTreeTest.class.st +++ b/src/Math-Tests-KDTree/PMKDTreeTest.class.st @@ -149,24 +149,20 @@ PMKDTreeTest >> testKDTreeExtremeCase [ { #category : #tests } PMKDTreeTest >> testPMVectorCompatibility [ + | aVector bVector r | - (Array lookupSelector: #asPMVector) - ifNil: [ ^ self skip: 'necessary PM package not loaded' ]. - aVector := #(0) asPMVector. - bVector := #(-2.0) asPMVector. - r := (Array with: aVector with: #(-5.0) asPMVector with: bVector) asPMVector. + (Array lookupSelector: #asPMVector) ifNil: [ ^ self skip: 'necessary PM package not loaded' ]. + aVector := #( 0 ) asPMVector. + bVector := #( -2.0 ) asPMVector. + r := (Array with: aVector with: #( -5.0 ) asPMVector with: bVector) asPMVector. self initializeTreeWith: r as: true. - self - assert: (tree nnSearch: bVector i: 2) - equals: (Array with: bVector with: aVector). - self - assert: (stupid nnSearch: bVector i: 2) - equals: (Array with: bVector with: aVector). + self assert: (tree nnSearch: bVector i: 2) equals: (Array with: bVector with: aVector). + self assert: (stupid nnSearch: bVector i: 2) equals: (Array with: bVector with: aVector). self initializeTreeWith: r as: false. r := tree nnSearch: bVector i: 2. - self assert: r first equals: #(3 0.0). + self assert: r first equals: #( 3 0.0 ). self assert: r second first equals: 1. - self assert: (r second second closeTo: 4.0) + self assert: r second second closeTo: 4.0 ] { #category : #tests } diff --git a/src/Math-Tests-Number-Extensions/PMNumberExtensionsTest.class.st b/src/Math-Tests-Number-Extensions/PMNumberExtensionsTest.class.st index 11730aec..83721ec3 100644 --- a/src/Math-Tests-Number-Extensions/PMNumberExtensionsTest.class.st +++ b/src/Math-Tests-Number-Extensions/PMNumberExtensionsTest.class.st @@ -14,11 +14,10 @@ PMNumberExtensionsTest >> testArTanh [ { #category : #tests } PMNumberExtensionsTest >> testSinc [ - "test cardinal sine" self assert: 0 sinc equals: 1. self assert: 0 sinc isInteger. self assert: 0.0 sinc isFloat. - self assert: (Float pi sinc closeTo: 0.0) + self assert: Float pi sinc closeTo: 0.0 ] diff --git a/src/Math-Tests-Numerical/PMCovarianceAccumulatorTest.class.st b/src/Math-Tests-Numerical/PMCovarianceAccumulatorTest.class.st index a229f22f..680b93e2 100644 --- a/src/Math-Tests-Numerical/PMCovarianceAccumulatorTest.class.st +++ b/src/Math-Tests-Numerical/PMCovarianceAccumulatorTest.class.st @@ -6,26 +6,23 @@ Class { { #category : #tests } PMCovarianceAccumulatorTest >> testCovarianceAccumulation [ - "Code example 12.2" | accumulator average covarianceMatrix | accumulator := PMCovarianceAccumulator new: 3. - #( #( 1 2 3 ) #( 2 3 4 ) #( 1 3 2 ) #( 4 3 1 ) #( 1 3 1 ) #( 1 4 2 ) - #( 3 1 2 ) #( 3 4 2 ) ) do: [ :x | - accumulator accumulate: x asPMVector ]. + #( #( 1 2 3 ) #( 2 3 4 ) #( 1 3 2 ) #( 4 3 1 ) #( 1 3 1 ) #( 1 4 2 ) #( 3 1 2 ) #( 3 4 2 ) ) do: [ :x | accumulator accumulate: x asPMVector ]. average := accumulator average. - self assert: ((average at: 1) closeTo: 2.0). - self assert: ((average at: 2) closeTo: 2.875). - self assert: ((average at: 3) closeTo: 2.125). + self assert: (average at: 1) closeTo: 2.0. + self assert: (average at: 2) closeTo: 2.875. + self assert: (average at: 3) closeTo: 2.125. covarianceMatrix := accumulator covarianceMatrix. - self assert: (((covarianceMatrix rowAt: 1) at: 1) closeTo: 1.25). - self assert: (((covarianceMatrix rowAt: 1) at: 2) closeTo: -0.125). - self assert: (((covarianceMatrix rowAt: 2) at: 1) closeTo: -0.125). - self assert: (((covarianceMatrix rowAt: 1) at: 3) closeTo: -0.25). - self assert: (((covarianceMatrix rowAt: 3) at: 1) closeTo: -0.25). - self assert: (((covarianceMatrix rowAt: 2) at: 2) closeTo: 0.859375). - self assert: (((covarianceMatrix rowAt: 2) at: 3) closeTo: -0.109375). - self assert: (((covarianceMatrix rowAt: 3) at: 2) closeTo: -0.109375). - self assert: (((covarianceMatrix rowAt: 3) at: 3) closeTo: 0.859375) + self assert: ((covarianceMatrix rowAt: 1) at: 1) closeTo: 1.25. + self assert: ((covarianceMatrix rowAt: 1) at: 2) closeTo: -0.125. + self assert: ((covarianceMatrix rowAt: 2) at: 1) closeTo: -0.125. + self assert: ((covarianceMatrix rowAt: 1) at: 3) closeTo: -0.25. + self assert: ((covarianceMatrix rowAt: 3) at: 1) closeTo: -0.25. + self assert: ((covarianceMatrix rowAt: 2) at: 2) closeTo: 0.859375. + self assert: ((covarianceMatrix rowAt: 2) at: 3) closeTo: -0.109375. + self assert: ((covarianceMatrix rowAt: 3) at: 2) closeTo: -0.109375. + self assert: ((covarianceMatrix rowAt: 3) at: 3) closeTo: 0.859375 ] diff --git a/src/Math-Tests-Numerical/PMGeneticOptimizerBugsTest.class.st b/src/Math-Tests-Numerical/PMGeneticOptimizerBugsTest.class.st index 8c800aff..d2538b00 100644 --- a/src/Math-Tests-Numerical/PMGeneticOptimizerBugsTest.class.st +++ b/src/Math-Tests-Numerical/PMGeneticOptimizerBugsTest.class.st @@ -27,8 +27,8 @@ PMGeneticOptimizerBugsTest >> testBug1 [ optimizer addPointAt: #( 2 3 ). optimizer addPointAt: #( 2 3 ). self shouldnt: [ r := optimizer randomScale ] raise: Error. - self assert: (r first closeTo: 1 / 2). - self assert: (r last closeTo: 1) + self assert: r first closeTo: 1 / 2. + self assert: r last closeTo: 1 ] { #category : #tests } diff --git a/src/Math-Tests-Numerical/PMHistogramTestsAndBugs.class.st b/src/Math-Tests-Numerical/PMHistogramTestsAndBugs.class.st index 01867125..6752af61 100644 --- a/src/Math-Tests-Numerical/PMHistogramTestsAndBugs.class.st +++ b/src/Math-Tests-Numerical/PMHistogramTestsAndBugs.class.st @@ -44,8 +44,7 @@ PMHistogramTestsAndBugs >> testBinWidth [ { #category : #tests } PMHistogramTestsAndBugs >> testChi2Against [ -self assert: ((h chi2Against: (PMScaledProbabilityDensityFunction histogram: h against: PMNormalDistribution new)) - closeTo: 2.937623). + self assert: (h chi2Against: (PMScaledProbabilityDensityFunction histogram: h against: PMNormalDistribution new)) closeTo: 2.937623 ] { #category : #tests } @@ -60,6 +59,7 @@ PMHistogramTestsAndBugs >> testCountAt [ { #category : #tests } PMHistogramTestsAndBugs >> testCountsBetween [ + self assert: (h countsBetween: 2 and: 4) equals: 2. "here is a bug in the original method: h countsBetween: 2 and: 3 resulted in -50" self assert: (h countsBetween: 2 and: 3) equals: 1. @@ -67,21 +67,22 @@ PMHistogramTestsAndBugs >> testCountsBetween [ self assert: (h countsBetween: 2 and: 4) equals: 2. self assert: (h countsBetween: 1 and: 4) equals: 3. self assert: (h countsBetween: 2.1 and: 2.2) equals: 0. - self assert: (h countsBetween: 2 and: 2.04) equals: 1. "binWidth is 0.04" - self assert: ((h countsBetween: 2 and: 2.01) closeTo: 0.25). "hence this the correct result" - self assert: ((h countsBetween: 2.01 and: 3) closeTo: 0.75). "and so on..." - self assert: ((h countsBetween: 1.01 and: 2.01) closeTo: 1). - self assert: ((h countsBetween: 2.01 and: 2.02) closeTo: 0.25) + self assert: (h countsBetween: 2 and: 2.04) equals: 1. "binWidth is 0.04" + self assert: (h countsBetween: 2 and: 2.01) closeTo: 0.25. "hence this the correct result" + self assert: (h countsBetween: 2.01 and: 3) closeTo: 0.75. "and so on..." + self assert: (h countsBetween: 1.01 and: 2.01) closeTo: 1. + self assert: (h countsBetween: 2.01 and: 2.02) closeTo: 0.25 ] { #category : #tests } PMHistogramTestsAndBugs >> testCountsUpTo [ + self assert: (h countsUpTo: 4) equals: 3. self assert: (h countsUpTo: 2.1) equals: 2. self assert: (h countsUpTo: 3) equals: 2. self assert: (h countsUpTo: 2) equals: 1. - self assert: (h countsUpTo: 1.04) equals: 1. "at 1.04 a new bin starts" - self assert: ((h countsUpTo: 1.02) closeTo: 0.5). "hence this is correct" + self assert: (h countsUpTo: 1.04) equals: 1. "at 1.04 a new bin starts" + self assert: (h countsUpTo: 1.02) closeTo: 0.5. "hence this is correct" self assert: (h countsUpTo: 1) equals: 0 ] diff --git a/src/Math-Tests-Numerical/PMNumericalMethodsTestCase.class.st b/src/Math-Tests-Numerical/PMNumericalMethodsTestCase.class.st index d8975269..7436271c 100644 --- a/src/Math-Tests-Numerical/PMNumericalMethodsTestCase.class.st +++ b/src/Math-Tests-Numerical/PMNumericalMethodsTestCase.class.st @@ -491,14 +491,12 @@ PMNumericalMethodsTestCase >> testLinearEquations [ PMNumericalMethodsTestCase >> testLinearEquationsSingle [ | s sol | - s := PMLinearEquationSystem - equations: #( #( 1 2 0 ) #( 3 5 4 ) #( 5 6 3 ) ) - constant: #( 0.1 12.5 10.3 ). + s := PMLinearEquationSystem equations: #( #( 1 2 0 ) #( 3 5 4 ) #( 5 6 3 ) ) constant: #( 0.1 12.5 10.3 ). sol := s solution. self assert: sol size equals: 3. - self assert: ((sol at: 1) closeTo: 0.5). - self assert: ((sol at: 2) closeTo: -0.2). - self assert: ((sol at: 3) closeTo: 3.0) + self assert: (sol at: 1) closeTo: 0.5. + self assert: (sol at: 2) closeTo: -0.2. + self assert: (sol at: 3) closeTo: 3.0 ] { #category : #'linear algebra' } diff --git a/src/Math-Tests-ODE/PMAB2SolverTest.class.st b/src/Math-Tests-ODE/PMAB2SolverTest.class.st index caa6773d..5db6c9a2 100644 --- a/src/Math-Tests-ODE/PMAB2SolverTest.class.st +++ b/src/Math-Tests-ODE/PMAB2SolverTest.class.st @@ -6,49 +6,106 @@ Class { { #category : #'tests-solving' } PMAB2SolverTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 1.5. - system := PMExplicitSystem block: [:x :t | 3 * (t negated exp) - (0.4 * x)]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMAB2Stepper onSystem: system. - solver := PMAB2Solver new stepper: stepper; system: system; dt: dt. - self assert: ((solver solve: system startState: 5 startTime: 0 endTime: 3) closeTo: 1.1237). - self assert: ((solver solve: system startState: 0 startTime: 1 endTime: 4) closeTo: -0.2451) + solver := PMAB2Solver new + stepper: stepper; + system: system; + dt: dt. + self + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 3) + closeTo: 1.1237. + self + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 4) + closeTo: -0.2451 ] { #category : #'tests-solving' } PMAB2SolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. - system := PMExplicitSystem block: [:x :t | 2 * t * x]. + system := PMExplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMAB2Stepper onSystem: system. - solver := PMAB2Solver new stepper: stepper; system: system; dt: dt. - self assert: ((solver solve: system startState: 1 startTime: 0 endTime: 1 ) closeTo: 2.1875). - self assert: ((solver solve: system startState: 1.25 startTime: 0.5 endTime: 2 ) closeTo: 17.4512) + solver := PMAB2Solver new + stepper: stepper; + system: system; + dt: dt. + self + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1) + closeTo: 2.1875. + self + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 2) + closeTo: 17.4512 ] { #category : #'tests-solving' } PMAB2SolverTest >> testSimpleSystem4 [ + | solver stepper system dt | dt := 0.5. - system := PMExplicitSystem block: [:x :t | 2 * (36 * (( t ln ) ** 2) + (6 * (t ln)) +7 ) / - ((t ** 3) * (1- (6 * (t ln))) ** 2)]. + system := PMExplicitSystem block: [ :x :t | 2 * (36 * (t ln ** 2) + (6 * t ln) + 7) / (t ** 3 * (1 - (6 * t ln)) ** 2) ]. stepper := PMAB2Stepper onSystem: system. - solver := PMAB2Solver new stepper: stepper; system: system; dt: dt. - self assert: ((solver solve: system startState: 2 startTime: 1 endTime: 4.5 ) closeTo: 22.3431) + solver := PMAB2Solver new + stepper: stepper; + system: system; + dt: dt. + self + assert: (solver + solve: system + startState: 2 + startTime: 1 + endTime: 4.5) + closeTo: 22.3431 ] { #category : #'tests-solving' } PMAB2SolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMExplicitSystem block: [:x :t | - | v | - v := PMVector new: 2. - v at: 1 put: t sin. - v at: 2 put: t cos. - v]. + system := PMExplicitSystem block: [ :x :t | + | v | + v := PMVector new: 2. + v at: 1 put: t sin. + v at: 2 put: t cos. + v ]. stepper := PMAB2Stepper onSystem: system. - solver := PMAB2Solver new stepper: stepper; system: system; dt: dt. - self assert: (((solver solve: system startState: #(-1 0) startTime: 0 endTime: Float pi ) at: 1) closeTo: 1). - self assert: (((solver solve: system startState: #(-1 0) startTime: 0 endTime: Float pi / 2 ) at: 2 ) closeTo: 1) + solver := PMAB2Solver new + stepper: stepper; + system: system; + dt: dt. + self + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. + self + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMAB2StepperTest.class.st b/src/Math-Tests-ODE/PMAB2StepperTest.class.st index 2e905305..045e2f60 100644 --- a/src/Math-Tests-ODE/PMAB2StepperTest.class.st +++ b/src/Math-Tests-ODE/PMAB2StepperTest.class.st @@ -11,86 +11,86 @@ PMAB2StepperTest >> testOrderIsTwo [ { #category : #'tests-stepping' } PMAB2StepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMExplicitSystem block: [ :x :t | t sin ]. stepper := PMAB2Stepper onSystem: system. solver := PMAB2Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } PMAB2StepperTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 1.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMAB2Stepper onSystem: system. solver := PMAB2Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 1.5) closeTo: 3.6756). - self - should: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 2.5) closeTo: 0.28534) + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 1.5) + closeTo: 3.6756. + self should: ((solver + solve: system + startState: 0 + startTime: 1 + endTime: 2.5) closeTo: 0.28534) ] { #category : #'tests-stepping' } PMAB2StepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMExplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMAB2Stepper onSystem: system. solver := PMAB2Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.2) closeTo: 1.04). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.2) + closeTo: 1.04. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.25). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.25. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1) closeTo: 2.4219). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1) + closeTo: 2.4219. self - assert: - ((solver - solve: system - startState: 2.4219 - startTime: 0.5 - endTime: 1) closeTo: 4.6924) + assert: (solver + solve: system + startState: 2.4219 + startTime: 0.5 + endTime: 1) + closeTo: 4.6924 ] diff --git a/src/Math-Tests-ODE/PMAB3SolverTest.class.st b/src/Math-Tests-ODE/PMAB3SolverTest.class.st index 88b00372..53da9b69 100644 --- a/src/Math-Tests-ODE/PMAB3SolverTest.class.st +++ b/src/Math-Tests-ODE/PMAB3SolverTest.class.st @@ -6,106 +6,104 @@ Class { { #category : #'tests-solving' } PMAB3SolverTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 1.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMAB3Stepper onSystem: system. solver := PMAB3Solver new - stepper: stepper; - system: system; - dt: dt. - self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 3) closeTo: 1.1237). + stepper: stepper; + system: system; + dt: dt. self - should: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 4) closeTo: -0.2451) + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 3) + closeTo: 1.1237. + self should: ((solver + solve: system + startState: 0 + startTime: 1 + endTime: 4) closeTo: -0.2451) ] { #category : #'tests-solving' } PMAB3SolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMExplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMAB3Stepper onSystem: system. solver := PMAB3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1) closeTo: 2.1875). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1) + closeTo: 2.1875. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 2) closeTo: 19.2822) + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 2) + closeTo: 19.2822 ] { #category : #'tests-solving' } PMAB3SolverTest >> testSimpleSystem4 [ + | solver stepper system dt | dt := 0.5. - system := PMExplicitSystem - block: - [ :x :t | (2 negated * (t ** 4) * (x ** 2) + 1 - (x * (t ** 2))) / (t ** 3) ]. + system := PMExplicitSystem block: [ :x :t | 2 negated * (t ** 4) * (x ** 2) + 1 - (x * (t ** 2)) / (t ** 3) ]. stepper := PMAB3Stepper onSystem: system. solver := PMAB3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 2 - startTime: 1 - endTime: 4.5) closeTo: -1.6539239077654698e49) + assert: (solver + solve: system + startState: 2 + startTime: 1 + endTime: 4.5) + closeTo: -1.6539239077654698e49 ] { #category : #'tests-solving' } PMAB3SolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.001. - system := PMExplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMExplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMAB3Stepper onSystem: system. solver := PMAB3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMAB3StepperTest.class.st b/src/Math-Tests-ODE/PMAB3StepperTest.class.st index ae66d20c..6d933101 100644 --- a/src/Math-Tests-ODE/PMAB3StepperTest.class.st +++ b/src/Math-Tests-ODE/PMAB3StepperTest.class.st @@ -11,79 +11,79 @@ PMAB3StepperTest >> testOrderIsThree [ { #category : #'tests-stepping' } PMAB3StepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMExplicitSystem block: [ :x :t | t sin ]. stepper := PMAB3Stepper onSystem: system. solver := PMAB3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } PMAB3StepperTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 1.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMAB3Stepper onSystem: system. solver := PMAB3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 1.5) closeTo: 3.67565). - self - should: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 2.5) closeTo: 0.28534) + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 1.5) + closeTo: 3.67565. + self should: ((solver + solve: system + startState: 0 + startTime: 1 + endTime: 2.5) closeTo: 0.28534) ] { #category : #'tests-stepping' } PMAB3StepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMExplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMAB3Stepper onSystem: system. solver := PMAB3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.25). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.25. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1) closeTo: 2.4219). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1) + closeTo: 2.4219. self - assert: - ((solver - solve: system - startState: 2.4219 - startTime: 0.5 - endTime: 1) closeTo: 4.6924) + assert: (solver + solve: system + startState: 2.4219 + startTime: 0.5 + endTime: 1) + closeTo: 4.6924 ] diff --git a/src/Math-Tests-ODE/PMAB4SolverTest.class.st b/src/Math-Tests-ODE/PMAB4SolverTest.class.st index 2d0df43f..46d397a4 100644 --- a/src/Math-Tests-ODE/PMAB4SolverTest.class.st +++ b/src/Math-Tests-ODE/PMAB4SolverTest.class.st @@ -6,106 +6,105 @@ Class { { #category : #'tests-solving' } PMAB4SolverTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 1.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMAB4Stepper onSystem: system. solver := PMAB4Solver new - stepper: stepper; - system: system; - dt: dt. - self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 3) closeTo: 1.1237). + stepper: stepper; + system: system; + dt: dt. self - should: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 4) closeTo: -0.2451) + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 3) + closeTo: 1.1237. + self should: ((solver + solve: system + startState: 0 + startTime: 1 + endTime: 4) closeTo: -0.2451) ] { #category : #'tests-solving' } PMAB4SolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMExplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMAB4Stepper onSystem: system. solver := PMAB4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1) closeTo: 2.1875). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1) + closeTo: 2.1875. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.5) closeTo: 5.546875). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.5) + closeTo: 5.546875. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.7) closeTo: 11.4082). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.7) + closeTo: 11.4082. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 2.0) closeTo: 20.2002). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 2.0) + closeTo: 20.2002. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 2.5) closeTo: 95.5152) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 2.5) + closeTo: 95.5152 ] { #category : #'tests-solving' } PMAB4SolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.001. - system := PMExplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMExplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMAB4Stepper onSystem: system. solver := PMAB4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMAB4StepperTest.class.st b/src/Math-Tests-ODE/PMAB4StepperTest.class.st index f766fcd7..54913ede 100644 --- a/src/Math-Tests-ODE/PMAB4StepperTest.class.st +++ b/src/Math-Tests-ODE/PMAB4StepperTest.class.st @@ -11,79 +11,79 @@ PMAB4StepperTest >> testOrderIsFour [ { #category : #'tests-stepping' } PMAB4StepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMExplicitSystem block: [ :x :t | t sin ]. stepper := PMAB4Stepper onSystem: system. solver := PMAB4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } PMAB4StepperTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 1.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMAB4Stepper onSystem: system. solver := PMAB4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 1.5) closeTo: 3.67565). - self - should: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 2.5) closeTo: 0.28534) + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 1.5) + closeTo: 3.67565. + self should: ((solver + solve: system + startState: 0 + startTime: 1 + endTime: 2.5) closeTo: 0.28534) ] { #category : #'tests-stepping' } PMAB4StepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMExplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMAB4Stepper onSystem: system. solver := PMAB4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.25). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.25. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1) closeTo: 2.4219). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1) + closeTo: 2.4219. self - assert: - ((solver - solve: system - startState: 2.4219 - startTime: 0.5 - endTime: 1) closeTo: 4.6924) + assert: (solver + solve: system + startState: 2.4219 + startTime: 0.5 + endTime: 1) + closeTo: 4.6924 ] diff --git a/src/Math-Tests-ODE/PMAM3SolverTest.class.st b/src/Math-Tests-ODE/PMAM3SolverTest.class.st index 20c012e4..61eb5fe9 100644 --- a/src/Math-Tests-ODE/PMAM3SolverTest.class.st +++ b/src/Math-Tests-ODE/PMAM3SolverTest.class.st @@ -18,72 +18,73 @@ PMAM3SolverTest >> testSimpleSystem2 [ { #category : #'tests-solving' } PMAM3SolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMAM3Stepper onSystem: system. solver := PMAM3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.5) closeTo: 9.7551). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.5) + closeTo: 9.7551. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1.5) closeTo: 9.7298). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1.5) + closeTo: 9.7298. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 2.5) closeTo: 0). + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 2.5) + closeTo: 0. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 2.5) closeTo: 415.6194) + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 2.5) + closeTo: 415.6194 ] { #category : #'tests-solving' } PMAM3SolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMImplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMImplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMAM3Stepper onSystem: system. solver := PMAM3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMAM3StepperTest.class.st b/src/Math-Tests-ODE/PMAM3StepperTest.class.st index 994f7589..5d433425 100644 --- a/src/Math-Tests-ODE/PMAM3StepperTest.class.st +++ b/src/Math-Tests-ODE/PMAM3StepperTest.class.st @@ -11,21 +11,22 @@ PMAM3StepperTest >> testOrderIsThree [ { #category : #'tests-stepping' } PMAM3StepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMImplicitSystem block: [ :x :t | t sin ]. stepper := PMAM3Stepper onSystem: system. solver := PMAM3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } @@ -43,72 +44,73 @@ PMAM3StepperTest >> testSimpleSystem2 [ { #category : #'tests-stepping' } PMAM3StepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMAM3Stepper onSystem: system. solver := PMAM3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.2) closeTo: 1.11). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.2) + closeTo: 1.11. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.3125). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.3125. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1.3) closeTo: 6.7429). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1.3) + closeTo: 6.7429. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.3) closeTo: 6.76035) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.3) + closeTo: 6.76035 ] { #category : #'tests-stepping' } PMAM3StepperTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMImplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMImplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMAM3Stepper onSystem: system. solver := PMAM3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMAM4SolverTest.class.st b/src/Math-Tests-ODE/PMAM4SolverTest.class.st index d2e926a4..6e5e462b 100644 --- a/src/Math-Tests-ODE/PMAM4SolverTest.class.st +++ b/src/Math-Tests-ODE/PMAM4SolverTest.class.st @@ -18,72 +18,73 @@ PMAM4SolverTest >> testSimpleSystem2 [ { #category : #'tests-solving' } PMAM4SolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMAM4Stepper onSystem: system. solver := PMAM4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.5) closeTo: 15.2741). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.5) + closeTo: 15.2741. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 2.2) closeTo: 191.3011). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 2.2) + closeTo: 191.3011. self - assert: - ((solver - solve: system - startState: 0.5 - startTime: 1 - endTime: 2.5) closeTo: 112.8325). + assert: (solver + solve: system + startState: 0.5 + startTime: 1 + endTime: 2.5) + closeTo: 112.8325. self - assert: - ((solver - solve: system - startState: 0.5 - startTime: 1 - endTime: 2.8) closeTo: 535.8236) + assert: (solver + solve: system + startState: 0.5 + startTime: 1 + endTime: 2.8) + closeTo: 535.8236 ] { #category : #'tests-solving' } PMAM4SolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMImplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMImplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMAM4Stepper onSystem: system. solver := PMAM4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMAM4StepperTest.class.st b/src/Math-Tests-ODE/PMAM4StepperTest.class.st index a0e81231..73df91be 100644 --- a/src/Math-Tests-ODE/PMAM4StepperTest.class.st +++ b/src/Math-Tests-ODE/PMAM4StepperTest.class.st @@ -11,21 +11,22 @@ PMAM4StepperTest >> testOrderIsFour [ { #category : #'tests-stepping' } PMAM4StepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMImplicitSystem block: [ :x :t | t sin ]. stepper := PMAM4Stepper onSystem: system. solver := PMAM4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } @@ -43,33 +44,34 @@ PMAM4StepperTest >> testSimpleSystem2 [ { #category : #'tests-stepping' } PMAM4StepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMAM4Stepper onSystem: system. solver := PMAM4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.3125). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.3125. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1.3) closeTo: 6.7429). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1.3) + closeTo: 6.7429. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.3) closeTo: 9.6147) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.3) + closeTo: 9.6147 ] diff --git a/src/Math-Tests-ODE/PMBDF2SolverTest.class.st b/src/Math-Tests-ODE/PMBDF2SolverTest.class.st index 742fe64d..a4d590bd 100644 --- a/src/Math-Tests-ODE/PMBDF2SolverTest.class.st +++ b/src/Math-Tests-ODE/PMBDF2SolverTest.class.st @@ -18,42 +18,43 @@ PMBDF2SolverTest >> testSimpleSystem2 [ { #category : #'tests-solving' } PMBDF2SolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMBDF2Stepper onSystem: system. solver := PMBDF2Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.5) closeTo: 11.9167). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.5) + closeTo: 11.9167. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1.5) closeTo: 9.5833). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1.5) + closeTo: 9.5833. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 2.5) closeTo: 21.9166). + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 2.5) + closeTo: 21.9166. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 2.5) closeTo: 273.7129) + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 2.5) + closeTo: 273.7129 ] { #category : #'tests-solving' } diff --git a/src/Math-Tests-ODE/PMBDF2StepperTest.class.st b/src/Math-Tests-ODE/PMBDF2StepperTest.class.st index cb9b70b6..aacea4b3 100644 --- a/src/Math-Tests-ODE/PMBDF2StepperTest.class.st +++ b/src/Math-Tests-ODE/PMBDF2StepperTest.class.st @@ -11,21 +11,22 @@ PMBDF2StepperTest >> testOrderIsTwo [ { #category : #'tests-stepping' } PMBDF2StepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMImplicitSystem block: [ :x :t | t sin ]. stepper := PMBDF2Stepper onSystem: system. solver := PMBDF2Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } @@ -43,72 +44,73 @@ PMBDF2StepperTest >> testSimpleSystem2 [ { #category : #'tests-stepping' } PMBDF2StepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMBDF2Stepper onSystem: system. solver := PMBDF2Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.2) closeTo: 1.3). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.2) + closeTo: 1.3. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.75). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.75. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1.3) closeTo: 6.0793). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1.3) + closeTo: 6.0793. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.3) closeTo: 7.5367) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.3) + closeTo: 7.5367 ] { #category : #'tests-stepping' } PMBDF2StepperTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.0001. - system := PMImplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMImplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMBDF2Stepper onSystem: system. solver := PMBDF2Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMBDF3SolverTest.class.st b/src/Math-Tests-ODE/PMBDF3SolverTest.class.st index cec568d4..a5b7320c 100644 --- a/src/Math-Tests-ODE/PMBDF3SolverTest.class.st +++ b/src/Math-Tests-ODE/PMBDF3SolverTest.class.st @@ -18,72 +18,73 @@ PMBDF3SolverTest >> testSimpleSystem2 [ { #category : #'tests-solving' } PMBDF3SolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMBDF3Stepper onSystem: system. solver := PMBDF3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.5) closeTo: 11.0227). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.5) + closeTo: 11.0227. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 2.5) closeTo: 219.4525). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 2.5) + closeTo: 219.4525. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 2.5) closeTo: 19.4318). + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 2.5) + closeTo: 19.4318. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 2.8) closeTo: 73.5867) + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 2.8) + closeTo: 73.5867 ] { #category : #'tests-solving' } PMBDF3SolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMImplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMImplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMBDF3Stepper onSystem: system. solver := PMBDF3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMBDF3StepperTest.class.st b/src/Math-Tests-ODE/PMBDF3StepperTest.class.st index 77f5013f..c127feab 100644 --- a/src/Math-Tests-ODE/PMBDF3StepperTest.class.st +++ b/src/Math-Tests-ODE/PMBDF3StepperTest.class.st @@ -11,21 +11,22 @@ PMBDF3StepperTest >> testOrderIsThree [ { #category : #'tests-stepping' } PMBDF3StepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMImplicitSystem block: [ :x :t | t sin ]. stepper := PMBDF3Stepper onSystem: system. solver := PMBDF3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } @@ -43,33 +44,34 @@ PMBDF3StepperTest >> testSimpleSystem2 [ { #category : #'tests-stepping' } PMBDF3StepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMBDF3Stepper onSystem: system. solver := PMBDF3Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.75). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.75. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1.3) closeTo: 6.0793). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1.3) + closeTo: 6.0793. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.3) closeTo: 7.4391) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.3) + closeTo: 7.4391 ] diff --git a/src/Math-Tests-ODE/PMBDF4SolverTest.class.st b/src/Math-Tests-ODE/PMBDF4SolverTest.class.st index 15557e0c..42d7d811 100644 --- a/src/Math-Tests-ODE/PMBDF4SolverTest.class.st +++ b/src/Math-Tests-ODE/PMBDF4SolverTest.class.st @@ -19,79 +19,80 @@ PMBDF4SolverTest >> testSimpleSystem2 [ { #category : #'tests-solving' } PMBDF4SolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMBDF4Stepper onSystem: system. solver := PMBDF4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 0.25 - startTime: 0.5 - endTime: 2.0) closeTo: 13.4091). + assert: (solver + solve: system + startState: 0.25 + startTime: 0.5 + endTime: 2.0) + closeTo: 13.4091. self - assert: - ((solver - solve: system - startState: 0.25 - startTime: 0.5 - endTime: 2.3) closeTo: 41.21625). + assert: (solver + solve: system + startState: 0.25 + startTime: 0.5 + endTime: 2.3) + closeTo: 41.21625. self - assert: - ((solver - solve: system - startState: 0.25 - startTime: 0.5 - endTime: 2.5) closeTo: 69.9482). + assert: (solver + solve: system + startState: 0.25 + startTime: 0.5 + endTime: 2.5) + closeTo: 69.9482. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 2.8) closeTo: 71.9236). + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 2.8) + closeTo: 71.9236. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.5) closeTo: 11.0227) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.5) + closeTo: 11.0227 ] { #category : #'tests-solving' } PMBDF4SolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMImplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMImplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMBDF4Stepper onSystem: system. solver := PMBDF4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMBDF4StepperTest.class.st b/src/Math-Tests-ODE/PMBDF4StepperTest.class.st index f44bdb8b..a32e2864 100644 --- a/src/Math-Tests-ODE/PMBDF4StepperTest.class.st +++ b/src/Math-Tests-ODE/PMBDF4StepperTest.class.st @@ -11,21 +11,22 @@ PMBDF4StepperTest >> testOrderIsFour [ { #category : #'tests-stepping' } PMBDF4StepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMImplicitSystem block: [ :x :t | t sin ]. stepper := PMBDF4Stepper onSystem: system. solver := PMBDF4Solver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } @@ -53,31 +54,41 @@ PMBDF4StepperTest >> testSimpleSystem3 [ stepper: stepper; system: system; dt: dt. - self assert: ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.75). - self assert: ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.0) closeTo: 3.75). - self assert: ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.5) closeTo: 11.0227). - self assert: ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 2.0) closeTo: 43.2181). - self assert: ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 2.3) closeTo: 132.2771). + self + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.75. + self + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.0) + closeTo: 3.75. + self + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.5) + closeTo: 11.0227. + self + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 2.0) + closeTo: 43.2181. + self + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 2.3) + closeTo: 132.2771. self assert: ((solver solve: system startState: 1 diff --git a/src/Math-Tests-ODE/PMBeckwardEulerSolverTest.class.st b/src/Math-Tests-ODE/PMBeckwardEulerSolverTest.class.st index 7a2fc18a..3c632302 100644 --- a/src/Math-Tests-ODE/PMBeckwardEulerSolverTest.class.st +++ b/src/Math-Tests-ODE/PMBeckwardEulerSolverTest.class.st @@ -6,21 +6,22 @@ Class { { #category : #'tests-solving' } PMBeckwardEulerSolverTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMImplicitSystem block: [ :x :t | t sin ]. stepper := PMImplicitStepper onSystem: system. solver := PMImplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-solving' } @@ -36,32 +37,32 @@ PMBeckwardEulerSolverTest >> testSimpleSystem2 [ { #category : #'tests-solving' } PMBeckwardEulerSolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMImplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMImplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMImplicitStepper onSystem: system. solver := PMImplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 0.995) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 0.995 ] diff --git a/src/Math-Tests-ODE/PMBeckwardEulerStepperTest.class.st b/src/Math-Tests-ODE/PMBeckwardEulerStepperTest.class.st index 3be63c38..e4ed49fe 100644 --- a/src/Math-Tests-ODE/PMBeckwardEulerStepperTest.class.st +++ b/src/Math-Tests-ODE/PMBeckwardEulerStepperTest.class.st @@ -50,19 +50,20 @@ PMBeckwardEulerStepperTest >> testSimpleSystem2 [ { #category : #'tests-stepping' } PMBeckwardEulerStepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMImplicitStepper onSystem: system. solver := PMImplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.75) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.75 ] diff --git a/src/Math-Tests-ODE/PMEulerSolverTest.class.st b/src/Math-Tests-ODE/PMEulerSolverTest.class.st index 92cb286a..b1da50e7 100644 --- a/src/Math-Tests-ODE/PMEulerSolverTest.class.st +++ b/src/Math-Tests-ODE/PMEulerSolverTest.class.st @@ -9,29 +9,27 @@ Class { { #category : #'tests-solving' } PMEulerSolverTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 1.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMHeunStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. - self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 1.5) closeTo: 4.30204). + stepper: stepper; + system: system; + dt: dt. self - should: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 2.5) closeTo: 0.5158) + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 1.5) + closeTo: 4.30204. + self should: ((solver + solve: system + startState: 0 + startTime: 1 + endTime: 2.5) closeTo: 0.5158) ] { #category : #'tests-solving' } diff --git a/src/Math-Tests-ODE/PMEulerStepperTest.class.st b/src/Math-Tests-ODE/PMEulerStepperTest.class.st index 3aea4e28..8d621cc5 100644 --- a/src/Math-Tests-ODE/PMEulerStepperTest.class.st +++ b/src/Math-Tests-ODE/PMEulerStepperTest.class.st @@ -49,32 +49,32 @@ PMEulerStepperTest >> testOrderOfBaseExplicitStepperIsOne [ { #category : #'tests-stepping' } PMEulerStepperTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.001. - system := PMExplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMExplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMExplicitStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1.0004) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1.0004 ] diff --git a/src/Math-Tests-ODE/PMHeunStepperTest.class.st b/src/Math-Tests-ODE/PMHeunStepperTest.class.st index 65eef6e5..9b12d03b 100644 --- a/src/Math-Tests-ODE/PMHeunStepperTest.class.st +++ b/src/Math-Tests-ODE/PMHeunStepperTest.class.st @@ -11,104 +11,104 @@ PMHeunStepperTest >> testOrderIsTwo [ { #category : #tests } PMHeunStepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMExplicitSystem block: [ :x :t | t sin ]. stepper := PMHeunStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #tests } PMHeunStepperTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 0.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMHeunStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. - self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 0.5) closeTo: 5.15489). + stepper: stepper; + system: system; + dt: dt. self - should: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 1.5) closeTo: 0.3881) + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 0.5) + closeTo: 5.15489. + self should: ((solver + solve: system + startState: 0 + startTime: 1 + endTime: 1.5) closeTo: 0.3881) ] { #category : #tests } PMHeunStepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMExplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMHeunStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.25). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.25. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1) closeTo: 2.5) + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1) + closeTo: 2.5 ] { #category : #tests } PMHeunStepperTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMExplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMExplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMHeunStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMImplicitMidpointStepperTest.class.st b/src/Math-Tests-ODE/PMImplicitMidpointStepperTest.class.st index a42fc600..f1af63c8 100644 --- a/src/Math-Tests-ODE/PMImplicitMidpointStepperTest.class.st +++ b/src/Math-Tests-ODE/PMImplicitMidpointStepperTest.class.st @@ -11,21 +11,22 @@ PMImplicitMidpointStepperTest >> testOrderIsTwo [ { #category : #'tests-stepping' } PMImplicitMidpointStepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMImplicitSystem block: [ :x :t | t sin ]. stepper := PMImplicitMidpointStepper onSystem: system. solver := PMImplicitMidpointSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } @@ -41,51 +42,52 @@ PMImplicitMidpointStepperTest >> testSimpleSystem2 [ { #category : #'tests-stepping' } PMImplicitMidpointStepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMImplicitMidpointStepper onSystem: system. solver := PMImplicitMidpointSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1) closeTo: 2.6348) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1) + closeTo: 2.6348 ] { #category : #'tests-stepping' } PMImplicitMidpointStepperTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMImplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMImplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMImplicitMidpointStepper onSystem: system. solver := PMImplicitMidpointSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMMidpointSolverTest.class.st b/src/Math-Tests-ODE/PMMidpointSolverTest.class.st index 4b3090fc..8c22e3d5 100644 --- a/src/Math-Tests-ODE/PMMidpointSolverTest.class.st +++ b/src/Math-Tests-ODE/PMMidpointSolverTest.class.st @@ -6,158 +6,161 @@ Class { { #category : #'tests-solving' } PMMidpointSolverTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMExplicitSystem block: [ :x :t | t sin ]. stepper := PMMidpointStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-solving' } PMMidpointSolverTest >> testSimpleSystem1 [ + | solver stepper system dt | dt := 0.025. system := PMExplicitSystem block: [ :x :t | t tan + 1 ]. stepper := PMMidpointStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 1.05) closeTo: 0.13237). + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 1.05) + closeTo: 0.13237. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 1.09) closeTo: 0.2455). + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 1.09) + closeTo: 0.2455. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 1.11) closeTo: 0.3048) + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 1.11) + closeTo: 0.3048 ] { #category : #'tests-solving' } PMMidpointSolverTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 0.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMMidpointStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 1.5) closeTo: 4.32246). + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 1.5) + closeTo: 4.32246. self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 3) closeTo: 2.7326). + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 3) + closeTo: 2.7326. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.1) closeTo: 2.14437) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.1) + closeTo: 2.14437 ] { #category : #'tests-solving' } PMMidpointSolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMExplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMMidpointStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.2) closeTo: 1.04). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.2) + closeTo: 1.04. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.25). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.25. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.1) closeTo: 2.9813). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.1) + closeTo: 2.9813. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.5) closeTo: 6.9629) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.5) + closeTo: 6.9629 ] { #category : #'tests-solving' } PMMidpointSolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMExplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMExplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMMidpointStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMMidpointStepperTest.class.st b/src/Math-Tests-ODE/PMMidpointStepperTest.class.st index a3d1866c..9c3e94a2 100644 --- a/src/Math-Tests-ODE/PMMidpointStepperTest.class.st +++ b/src/Math-Tests-ODE/PMMidpointStepperTest.class.st @@ -11,131 +11,133 @@ PMMidpointStepperTest >> testOrderIsTwo [ { #category : #'tests-stepping' } PMMidpointStepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMExplicitSystem block: [ :x :t | t sin ]. stepper := PMMidpointStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } PMMidpointStepperTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 1.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMMidpointStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 1.5) closeTo: 3.6756). + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 1.5) + closeTo: 3.6756. self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 3) closeTo: 2.3049) + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 3) + closeTo: 2.3049 ] { #category : #'tests-stepping' } PMMidpointStepperTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMExplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMMidpointStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.2) closeTo: 1.04). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.2) + closeTo: 1.04. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.25). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.25. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1) closeTo: 2.4219) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1) + closeTo: 2.4219 ] { #category : #'tests-stepping' } PMMidpointStepperTest >> testSimpleSystem4 [ + | solver stepper system dt | dt := 0.0001. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMMidpointStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 1.5) closeTo: 4.3724) + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 1.5) + closeTo: 4.3724 ] { #category : #'tests-stepping' } PMMidpointStepperTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMExplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMExplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMMidpointStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMRungeKuttaSolverTest.class.st b/src/Math-Tests-ODE/PMRungeKuttaSolverTest.class.st index 79535a63..c41901f4 100644 --- a/src/Math-Tests-ODE/PMRungeKuttaSolverTest.class.st +++ b/src/Math-Tests-ODE/PMRungeKuttaSolverTest.class.st @@ -6,158 +6,161 @@ Class { { #category : #'tests-solving' } PMRungeKuttaSolverTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMExplicitSystem block: [ :x :t | t sin ]. stepper := PMRungeKuttaStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-solving' } PMRungeKuttaSolverTest >> testSimpleSystem1 [ + | solver stepper system dt | dt := 0.025. system := PMExplicitSystem block: [ :x :t | t tan + 1 ]. stepper := PMRungeKuttaStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 1.05) closeTo: 0.1324). + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 1.05) + closeTo: 0.1324. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 1.09) closeTo: 0.2455). + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 1.09) + closeTo: 0.2455. self - assert: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 1.11) closeTo: 0.3048) + assert: (solver + solve: system + startState: 0 + startTime: 1 + endTime: 1.11) + closeTo: 0.3048 ] { #category : #'tests-solving' } PMRungeKuttaSolverTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 0.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMRungeKuttaStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 1.5) closeTo: 4.3724). + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 1.5) + closeTo: 4.3724. self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 3) closeTo: 2.7629). + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 3) + closeTo: 2.7629. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.1) closeTo: 2.1997) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.1) + closeTo: 2.1997 ] { #category : #'tests-solving' } PMRungeKuttaSolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMExplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMRungeKuttaStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.2) closeTo: 1.0408). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.2) + closeTo: 1.0408. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.5) closeTo: 1.2838). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.5) + closeTo: 1.2838. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.1) closeTo: 3.3471). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.1) + closeTo: 3.3471. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.5) closeTo: 9.3723) + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.5) + closeTo: 9.3723 ] { #category : #'tests-solving' } PMRungeKuttaSolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMExplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMExplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMRungeKuttaStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMRungeKuttaStepperTest.class.st b/src/Math-Tests-ODE/PMRungeKuttaStepperTest.class.st index be6f1035..6a86e6b4 100644 --- a/src/Math-Tests-ODE/PMRungeKuttaStepperTest.class.st +++ b/src/Math-Tests-ODE/PMRungeKuttaStepperTest.class.st @@ -19,15 +19,13 @@ PMRungeKuttaStepperTest >> testDoStepTimeStepSize1 [ { #category : #'tests-stepping' } PMRungeKuttaStepperTest >> testDoStepTimeStepSize2 [ + | stepper sys dt | - sys := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + sys := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMRungeKuttaStepper onSystem: sys. dt := 0.1. - self - assert: ((stepper doStep: 1 time: 1 stepSize: dt) closeTo: 1.0638). - self - assert: ((stepper doStep: 10 time: 1 stepSize: dt) closeTo: 9.7109) + self assert: (stepper doStep: 1 time: 1 stepSize: dt) closeTo: 1.0638. + self assert: (stepper doStep: 10 time: 1 stepSize: dt) closeTo: 9.7109 ] { #category : #'tests-stepping' } @@ -37,78 +35,77 @@ PMRungeKuttaStepperTest >> testOrderIsFour [ { #category : #'tests-stepping' } PMRungeKuttaStepperTest >> testSimpleSystem [ + | solver stepper system dt | dt := 0.01. system := PMExplicitSystem block: [ :x :t | t sin ]. stepper := PMRungeKuttaStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: -1 - startTime: 0 - endTime: Float pi) closeTo: 1) + assert: (solver + solve: system + startState: -1 + startTime: 0 + endTime: Float pi) + closeTo: 1 ] { #category : #'tests-stepping' } PMRungeKuttaStepperTest >> testSimpleSystem2 [ + | solver stepper system dt | dt := 1.5. - system := PMExplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + system := PMExplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMRungeKuttaStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. - self - assert: - ((solver - solve: system - startState: 5 - startTime: 0 - endTime: 1.5) closeTo: 4.3646). + stepper: stepper; + system: system; + dt: dt. self - should: - ((solver - solve: system - startState: 0 - startTime: 1 - endTime: 2.5) closeTo: 0.5951) + assert: (solver + solve: system + startState: 5 + startTime: 0 + endTime: 1.5) + closeTo: 4.3646. + self should: ((solver + solve: system + startState: 0 + startTime: 1 + endTime: 2.5) closeTo: 0.5951) ] { #category : #'tests-stepping' } PMRungeKuttaStepperTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMExplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMExplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMRungeKuttaStepper onSystem: system. solver := PMExplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMTrapezoidSolverTest.class.st b/src/Math-Tests-ODE/PMTrapezoidSolverTest.class.st index 0d517af5..0ca440f1 100644 --- a/src/Math-Tests-ODE/PMTrapezoidSolverTest.class.st +++ b/src/Math-Tests-ODE/PMTrapezoidSolverTest.class.st @@ -18,72 +18,73 @@ PMTrapezoidSolverTest >> testSimpleSystem2 [ { #category : #'tests-solving' } PMTrapezoidSolverTest >> testSimpleSystem3 [ + | solver stepper system dt | dt := 0.5. system := PMImplicitSystem block: [ :x :t | 2 * t * x ]. stepper := PMTrapezoidStepper onSystem: system. solver := PMImplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 0.2) closeTo: 1.11). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 0.2) + closeTo: 1.11. self - assert: - ((solver - solve: system - startState: 1 - startTime: 0 - endTime: 1.5) closeTo: 11.0742). + assert: (solver + solve: system + startState: 1 + startTime: 0 + endTime: 1.5) + closeTo: 11.0742. self - assert: - ((solver - solve: system - startState: 1.25 - startTime: 0.5 - endTime: 1.5) closeTo: 10.5468). + assert: (solver + solve: system + startState: 1.25 + startTime: 0.5 + endTime: 1.5) + closeTo: 10.5468. self - assert: - ((solver - solve: system - startState: 0.1 - startTime: 1 - endTime: 2.5) closeTo: 20.6718) + assert: (solver + solve: system + startState: 0.1 + startTime: 1 + endTime: 2.5) + closeTo: 20.6718 ] { #category : #'tests-solving' } PMTrapezoidSolverTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMImplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMImplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMTrapezoidStepper onSystem: system. solver := PMImplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-ODE/PMTrapezoidStepperTest.class.st b/src/Math-Tests-ODE/PMTrapezoidStepperTest.class.st index fc4ac22c..e766d2b3 100644 --- a/src/Math-Tests-ODE/PMTrapezoidStepperTest.class.st +++ b/src/Math-Tests-ODE/PMTrapezoidStepperTest.class.st @@ -14,14 +14,13 @@ PMTrapezoidStepperTest >> testDoStepTime [ dt := 0.1. stepper stepSize: dt. self assert: stepper stepSize equals: dt. - self assert: ((stepper doStep: 0 time: 10) closeTo: 0). - self assert: ((stepper doStep: 10 time: 0 stepSize: 1) closeTo: 17.5). + self assert: (stepper doStep: 0 time: 10) closeTo: 0. + self assert: (stepper doStep: 10 time: 0 stepSize: 1) closeTo: 17.5. "stepSize parameter changes the stored stepSize" self assert: stepper stepSize equals: 1. - self assert: ((stepper doStep: 1 time: 1) closeTo: 5). - self - assert: ((stepper doStep: 10 time: 1 stepSize: 0.2) closeTo: 12.4928) + self assert: (stepper doStep: 1 time: 1) closeTo: 5. + self assert: (stepper doStep: 10 time: 1 stepSize: 0.2) closeTo: 12.4928 ] { #category : #'tests-stepping' } @@ -39,15 +38,13 @@ PMTrapezoidStepperTest >> testDoStepTimeStepSize1 [ { #category : #'tests-stepping' } PMTrapezoidStepperTest >> testDoStepTimeStepSize2 [ + | stepper sys dt | - sys := PMImplicitSystem - block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. + sys := PMImplicitSystem block: [ :x :t | 3 * t negated exp - (0.4 * x) ]. stepper := PMTrapezoidStepper onSystem: sys. dt := 0.1. - self - assert: ((stepper doStep: 1 time: 1 stepSize: dt) closeTo: 1.0638). - self - assert: ((stepper doStep: 10 time: 1 stepSize: dt) closeTo: 9.7109) + self assert: (stepper doStep: 1 time: 1 stepSize: dt) closeTo: 1.0638. + self assert: (stepper doStep: 10 time: 1 stepSize: dt) closeTo: 9.7109 ] { #category : #'tests-stepping' } @@ -57,32 +54,32 @@ PMTrapezoidStepperTest >> testOrderIsTwo [ { #category : #'tests-stepping' } PMTrapezoidStepperTest >> testVectorSystem [ + | solver stepper system dt | dt := 0.01. - system := PMImplicitSystem - block: [ :x :t | - | c | - c := PMVector new: 2. - c at: 1 put: t sin. - c at: 2 put: t cos. - c ]. + system := PMImplicitSystem block: [ :x :t | + | c | + c := PMVector new: 2. + c at: 1 put: t sin. + c at: 2 put: t cos. + c ]. stepper := PMTrapezoidStepper onSystem: system. solver := PMImplicitSolver new - stepper: stepper; - system: system; - dt: dt. + stepper: stepper; + system: system; + dt: dt. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi) at: 1) closeTo: 1). + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi) at: 1) + closeTo: 1. self - assert: - (((solver - solve: system - startState: #(-1 0) - startTime: 0 - endTime: Float pi / 2) at: 2) closeTo: 1) + assert: ((solver + solve: system + startState: #( -1 0 ) + startTime: 0 + endTime: Float pi / 2) at: 2) + closeTo: 1 ] diff --git a/src/Math-Tests-Quaternion/PMQuaternionTest.class.st b/src/Math-Tests-Quaternion/PMQuaternionTest.class.st index 324c54d8..8b9b7b57 100644 --- a/src/Math-Tests-Quaternion/PMQuaternionTest.class.st +++ b/src/Math-Tests-Quaternion/PMQuaternionTest.class.st @@ -149,7 +149,6 @@ PMQuaternionTest >> testHash [ { #category : #running } PMQuaternionTest >> testLog [ - "this ensures that log and ln have the expected relationship" | qln qlg10ln | @@ -157,10 +156,10 @@ PMQuaternionTest >> testLog [ qlg10ln := q1234 log * 10 ln. "this inspires me to implement Quaternion>>equalsTo: " - self assert: (qln qr closeTo: qlg10ln real). - self assert: (qln qi closeTo: qlg10ln qi). - self assert: (qln qj closeTo: qlg10ln qj). - self assert: (qln qk closeTo: qlg10ln qk) + self assert: qln qr closeTo: qlg10ln real. + self assert: qln qi closeTo: qlg10ln qi. + self assert: qln qj closeTo: qlg10ln qj. + self assert: qln qk closeTo: qlg10ln qk ] { #category : #'testing - arithmetic' }