From cdf582acb69a11a8f6dce9236da13b5ba92ed147 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 8 Nov 2023 10:01:39 +0100 Subject: [PATCH 01/22] Test to kill mutants in GEllipse --- src/Geometry-Tests/GEllipseTest.class.st | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Geometry-Tests/GEllipseTest.class.st b/src/Geometry-Tests/GEllipseTest.class.st index f2643b3..cff6af8 100644 --- a/src/Geometry-Tests/GEllipseTest.class.st +++ b/src/Geometry-Tests/GEllipseTest.class.st @@ -20,3 +20,17 @@ GEllipseTest >> testEquals [ assert: (GEllipse center: 10 @ 10 a: 5 b: 10) hash equals: (GEllipse center: 10 @ 10 a: 5 b: 10) hash ] + +{ #category : #tests } +GEllipseTest >> testNotEquals [ + + self + deny: (GCircle center: 2 @ 2 radius: 3) + equals: (GEllipse center: 5 @ 5 a: 2 b: 3). + self + deny: (GEllipse center: 10 @ 10 a: 5 b: 10) + equals: (GEllipse center: 5 @ 5 a: 2 b: 3). + self + deny: (GEllipse center: 10 @ 10 a: 5 b: 10) hash + equals: (GEllipse center: 5 @ 5 a: 2 b: 3) hash +] From be18e4f62f25d0a2bbf1653497e9e30ac70570f5 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 8 Nov 2023 10:02:46 +0100 Subject: [PATCH 02/22] Added method dist to Point, fixed failing tests in Geometry --- src/Geometry/Point.extension.st | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Geometry/Point.extension.st b/src/Geometry/Point.extension.st index fd58a83..b31dad5 100644 --- a/src/Geometry/Point.extension.st +++ b/src/Geometry/Point.extension.st @@ -6,6 +6,12 @@ Point >> =~ aPoint [ ] +{ #category : #'*Geometry' } +Point >> dist: aPoint [ + + ^ self distanceTo: aPoint +] + { #category : #'*Geometry' } Point >> has: aPoint onTheSameSideAs: p [ (self x <= p x) From 1bbafae02cdbec7da26f11cd069e8f645eb7841e Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 8 Nov 2023 10:15:19 +0100 Subject: [PATCH 03/22] Test that kill mutant in GEllipse --- src/Geometry-Tests/GEllipseTest.class.st | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Geometry-Tests/GEllipseTest.class.st b/src/Geometry-Tests/GEllipseTest.class.st index cff6af8..6402cee 100644 --- a/src/Geometry-Tests/GEllipseTest.class.st +++ b/src/Geometry-Tests/GEllipseTest.class.st @@ -21,6 +21,14 @@ GEllipseTest >> testEquals [ equals: (GEllipse center: 10 @ 10 a: 5 b: 10) hash ] +{ #category : #tests } +GEllipseTest >> testHash [ + + self + assert: (GEllipse center: 10 @ 10 a: 5 b: 10) hash + equals: 17696867 +] + { #category : #tests } GEllipseTest >> testNotEquals [ From 7d1f76a06c634720895ca64afeeb61859763f3d2 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 8 Nov 2023 11:13:33 +0100 Subject: [PATCH 04/22] Added test to kill mutants for dist: --- src/Geometry-Tests/GLineTest.class.st | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Geometry-Tests/GLineTest.class.st b/src/Geometry-Tests/GLineTest.class.st index 99cc40e..41731e2 100644 --- a/src/Geometry-Tests/GLineTest.class.st +++ b/src/Geometry-Tests/GLineTest.class.st @@ -25,17 +25,19 @@ GLineTest >> testCutWith [ { #category : #tests } GLineTest >> testDist [ -self - assert: ((GLine a:1 b:0 c: -7)dist: 7 @ 0) - equals: 0. -self - assert: ((GLine a:1 b:0 c: -7)dist: 7 @ 7) - equals: 0. -self - assert: ((GLine a:1 b:0 c: -7)dist: 0 @ 0) - equals: 7. - + self + assert: ((GLine a: 1 b: 0 c: -7) dist: 7 @ 0) + equals: 0. + self + assert: ((GLine a: 1 b: 0 c: -7) dist: 7 @ 7) + equals: 0. + self + assert: ((GLine a: 1 b: 0 c: -7) dist: 0 @ 0) + equals: 7. + self + assert: ((GLine a: -4 b: 2 c: -3) dist: 2 @ 2) + equals: 1.5652475842498528 ] { #category : #tests } From cda275896128c04ef0ebc92c129d5f595ebd9760 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 8 Nov 2023 14:46:11 +0100 Subject: [PATCH 05/22] Added tests to kill mutants of parallelTo:, through:and:, and = --- src/Geometry-Tests/GLineTest.class.st | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Geometry-Tests/GLineTest.class.st b/src/Geometry-Tests/GLineTest.class.st index 41731e2..6594cdb 100644 --- a/src/Geometry-Tests/GLineTest.class.st +++ b/src/Geometry-Tests/GLineTest.class.st @@ -111,6 +111,14 @@ self ] +{ #category : #tests } +GLineTest >> testEquel5 [ + + self + assert: (GLine a: 6000000 b: 6000000 c: 2000000) = (GLine a: 0.000006 b: 0.000006 c: 0.000002) + equals: true +] + { #category : #tests } GLineTest >> testHasPoint [ "self @@ -164,6 +172,23 @@ self self assert: ((GLine a: 0 b: 2 c: 0.5) parallelTo: (GLine a: 0 b: 2 c: 0.5)) equals: true. +self + assert: ((GLine a: 1 b: 0 c: 0.5) parallelTo: (GLine a: 2 b: 0 c: 4)) + equals: true +. +self + assert: ((GLine a: 0 b: 0 c: 0) parallelTo: (GLine a: 0 b: 0 c: 0)) + equals: true +] + +{ #category : #tests } +GLineTest >> testThroughAnd [ + + | l1 l2 | + l1 := GLine through: 2 @ 3 and: 3 @ 3. + l2 := GLine through: 2 @ 2 and: 2 @ 3. + self assert: l1 equals: (GLine a: 0 b: 1 c: -3). + self assert: l2 equals: (GLine a: 1 b: 0 c: -2) ] { #category : #tests } From b7d4c52c4ffcc8445fb167b6d2767a9835a44db5 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 8 Nov 2023 17:13:25 +0100 Subject: [PATCH 06/22] Put useless code as comment --- src/Geometry-Tests/GLineTest.class.st | 64 ++++++++++++++++++++++++++- src/Geometry/GLine.class.st | 4 +- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/Geometry-Tests/GLineTest.class.st b/src/Geometry-Tests/GLineTest.class.st index 6594cdb..b2f077c 100644 --- a/src/Geometry-Tests/GLineTest.class.st +++ b/src/Geometry-Tests/GLineTest.class.st @@ -115,8 +115,65 @@ self GLineTest >> testEquel5 [ self - assert: (GLine a: 6000000 b: 6000000 c: 2000000) = (GLine a: 0.000006 b: 0.000006 c: 0.000002) - equals: true + assert: (GLine a: 6000000 b: 6000000 c: 2000000) + = (GLine a: 0.000006 b: 0.000006 c: 0.000002) + equals: true. + self + assert: (GLine a: 2 b: 5 c: 3) = (GLine a: 2 b: 5 c: 2) + equals: false. + self + assert: (GLine a: 2 b: 5 c: 3) = (GLine a: 1 b: 5 c: 3) + equals: false. + self + assert: (GLine a: 2 b: 5 c: 3) = (GLine a: 2 b: 4 c: 3) + equals: false. + self + assert: (GLine a: 1 b: 0 c: 0) = (GLine a: 6 b: 0 c: 0) + equals: true. + self + assert: (GLine a: 0 b: 0 c: 1) = (GLine a: 0 b: 0 c: 6) + equals: true. + self + assert: (GLine a: 5 b: 4 c: 4) = (GLine a: 0 b: 2 c: 2) + equals: false. + self + assert: (GLine a: 5 b: 4 c: 4) = (GLine a: 2 b: 2 c: 0) + equals: false. + self + assert: (GLine a: 4 b: 0 c: 4) = (GLine a: 2 b: 2 c: 2) + equals: false +] + +{ #category : #tests } +GLineTest >> testEquel6 [ + + self + assert: (GLine a: 1 b: 0 c: 0) = (GLine a: 0 b: 1 c: 0) + equals: false. + self + assert: (GLine a: 1 b: 0 c: 0) = (GLine a: 0 b: 0 c: 1) + equals: false. + self + assert: (GLine a: 0 b: 1 c: 0) = (GLine a: 1 b: 0 c: 0) + equals: false. + self + assert: (GLine a: 0 b: 1 c: 0) = (GLine a: 0 b: 0 c: 1) + equals: false. + self + assert: (GLine a: 0 b: 0 c: 1) = (GLine a: 1 b: 0 c: 0) + equals: false. + self + assert: (GLine a: 0 b: 0 c: 1) = (GLine a: 0 b: 1 c: 0) + equals: false. + self + assert: (GLine a: 0 b: 1 c: 1) = (GLine a: 1 b: 0 c: 0) + equals: false. + self + assert: (GLine a: 1 b: 0 c: 1) = (GLine a: 0 b: 1 c: 0) + equals: false. + self + assert: (GLine a: 1 b: 1 c: 0) = (GLine a: 0 b: 0 c: 1) + equals: false ] { #category : #tests } @@ -142,6 +199,9 @@ self assert: ((GSegment with: ((17674/229)@(14582/229)) with:(76.82622578909061@64.97050543967634)) asLine hasPoint: ((9244/147)@(1090/21)) withApproximation: 0.525738602984892 ) equals: true." +self + assert: ((GLine a: -2 b: 1 c: -1) hasPoint: 1@3 withApproximation: 0) + equals: true ] { #category : #tests } diff --git a/src/Geometry/GLine.class.st b/src/Geometry/GLine.class.st index d88f734..a8f74f3 100644 --- a/src/Geometry/GLine.class.st +++ b/src/Geometry/GLine.class.st @@ -12,7 +12,7 @@ Class { 'b', 'c' ], - #category : 'Geometry' + #category : #Geometry } { #category : #'as yet unclassified' } @@ -112,7 +112,7 @@ GLine >> hasPoint: aPoint [ { #category : #properties } GLine >> hasPoint: aPoint withApproximation: approx [ - (self a * aPoint x) + (self b * aPoint y) + self c - (((self a * approx) + (self b * approx))abs + self c) <=~ 0. + "(self a * aPoint x) + (self b * aPoint y) + self c - (((self a * approx) + (self b * approx))abs + self c) <=~ 0." ^ "(self a * aPoint x) + (self b * aPoint y) + self c <=~ (2 * approx)" (self dist: aPoint) <=~ (2 * approx) From 6d166758d9c9884ed928938b1159ec05883b1cfa Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 8 Nov 2023 17:14:12 +0100 Subject: [PATCH 07/22] Fixed the #= method to work in more cases --- src/Geometry/GLine.class.st | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Geometry/GLine.class.st b/src/Geometry/GLine.class.st index a8f74f3..3d3fa7a 100644 --- a/src/Geometry/GLine.class.st +++ b/src/Geometry/GLine.class.st @@ -49,7 +49,12 @@ or: ifTrue:[ ( self b / line b ) asFloat =~ ( self c / line c ) asFloat ] ifFalse:[ ( line a ~=~ 0 and:[ line b ~=~ 0] ) ifTrue:[ ( self a / line a ) asFloat =~ ( self b / line b ) asFloat ] - ifFalse:[ ( line a =~ 0 and: [ line c =~ 0 ] ) or: [ ( line b =~ 0 and: [ line c =~ 0 ] ) ] + ifFalse:[ line a ~=~ 0 + ifTrue: [ self b =~ 0 and: [ self c =~ 0 ] ] + ifFalse: [ line b ~=~0 + ifTrue: [ self a =~ 0 and: [ self c =~ 0 ] ] + ifFalse: [ self a =~ 0 and: [ self b =~ 0 ] ] + ] ] ] ]]] From 92a8c2a9d4cd032f13bcde9a05138ac56cac6f1d Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 9 Nov 2023 10:06:17 +0100 Subject: [PATCH 08/22] Added test to kill mutant for #cutWith: --- src/Geometry-Tests/GLineTest.class.st | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Geometry-Tests/GLineTest.class.st b/src/Geometry-Tests/GLineTest.class.st index b2f077c..174ff3e 100644 --- a/src/Geometry-Tests/GLineTest.class.st +++ b/src/Geometry-Tests/GLineTest.class.st @@ -23,6 +23,20 @@ GLineTest >> testCutWith [ equals: nil. ] +{ #category : #tests } +GLineTest >> testCutWith2 [ + + self + assert: ((GLine a: 0 b: 1 c: -3) cutWith: (GPolygon newVertices: { + (1 @ 5). + (1 @ 2). + (1 @ 4). + (1 @ 1). + (3 @ 1). + (3 @ 5) })) v2 + equals: 3 @ 3 +] + { #category : #tests } GLineTest >> testDist [ From 449bf0934c4663a80d9deb0264f6e1cc0b1fd4ad Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 9 Nov 2023 11:00:07 +0100 Subject: [PATCH 09/22] Added tests that increase code coverage and kill mutants for GLine --- src/Geometry-Tests/GLineTest.class.st | 90 +++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/src/Geometry-Tests/GLineTest.class.st b/src/Geometry-Tests/GLineTest.class.st index 174ff3e..a8c4983 100644 --- a/src/Geometry-Tests/GLineTest.class.st +++ b/src/Geometry-Tests/GLineTest.class.st @@ -218,6 +218,15 @@ self equals: true ] +{ #category : #tests } +GLineTest >> testHash [ + + self assert: (GLine a: 1 b: 3 c: -2) hash equals: 242268498. + self + deny: (GLine a: 1 b: 3 c: -2) hash + equals: (GLine a: 1 b: 3 c: 2) hash +] + { #category : #tests } GLineTest >> testIntersect [ self @@ -255,6 +264,71 @@ self equals: true ] +{ #category : #tests } +GLineTest >> testPointsWithDist1To [ + + self + assert: ((GLine a: -1 b: 1 c: 0) pointsWithDist: 2 to: 1 @ 1) + equals: { + (2.414213562373095 @ 2.414213562373095). + (-0.4142135623730949 @ -0.4142135623730949) }. + self + assert: ((GLine a: -2 b: 3 c: 0) pointsWithDist: 2 to: 3 @ 2) + equals: { + (4.664100588675687 @ 3.1094003924504583). + (1.3358994113243126 @ 0.8905996075495417) }. + self + assert: ((GLine a: 1 b: 0 c: -2) pointsWithDist: 2 to: 2 @ 1) + equals: { + (2 @ 3). + (2 @ -1) } +] + +{ #category : #tests } +GLineTest >> testPointsWithDistTo [ + + self + assert: ((GLine a: -1 b: 1 c: 0) pointsWithDist1: 2 to: 1 @ 1) + equals: { + (2.414213562373095 @ 2.414213562373095). + (-0.4142135623730949 @ -0.4142135623730949) }. + self + assert: ((GLine a: -2 b: 3 c: 0) pointsWithDist1: 2 to: 3 @ 2) + equals: { + (4.664100588675687 @ 3.1094003924504583). + (1.3358994113243126 @ 0.8905996075495417) }. + self + assert: ((GLine a: 1 b: 0 c: -2) pointsWithDist1: 2 to: 2 @ 1) + equals: { + (2 @ 3). + (2 @ -1) } +] + +{ #category : #tests } +GLineTest >> testPointsWithDistToRaiseError [ + + self + should: [ (GLine a: -2 b: 1 c: 0) pointsWithDist: 2 to: 1 @ 1 ] + raise: Error +] + +{ #category : #tests } +GLineTest >> testPrintOn [ + + self + assert: + (String streamContents: [ :s | (GLine a: 1 b: 2 c: 3) printOn: s ]) + equals: '1x +2y +3 = 0'. + self + assert: + (String streamContents: [ :s | (GLine a: 1 b: 0 c: 0) printOn: s ]) + equals: '1x +0y +0 = 0'. + self + assert: + (String streamContents: [ :s | (GLine a: 1 b: -2 c: -3) printOn: s ]) + equals: '1x -2y -3 = 0' +] + { #category : #tests } GLineTest >> testThroughAnd [ @@ -277,3 +351,19 @@ self assert: ((GLine through: 1@1 and: 2@2)through: 1@1 and: 2@2 hasPoint: 2@1 ) equals: false. ] + +{ #category : #tests } +GLineTest >> testXFor [ + + self assert: ((GLine a: -3 b: 1 c: 0) xFor: 3) equals: 1. + self assert: ((GLine a: -3 b: 2 c: 0) xFor: 3) equals: 2. + self assert: ((GLine a: -3 b: 1 c: 2) xFor: 1) equals: 1 +] + +{ #category : #tests } +GLineTest >> testYFor [ + + self assert: ((GLine a: -3 b: 1 c: 0) yFor: 1) equals: 3. + self assert: ((GLine a: -3 b: 2 c: 0) yFor: 2) equals: 3. + self assert: ((GLine a: -3 b: 1 c: 2) yFor: 1) equals: 1 +] From 1b35ddb367e85c1dbaf76edea712f4d931331084 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 9 Nov 2023 11:32:23 +0100 Subject: [PATCH 10/22] Added test that increase code coverage and kill mutant in GEllipse --- src/Geometry-Tests/GEllipseTest.class.st | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Geometry-Tests/GEllipseTest.class.st b/src/Geometry-Tests/GEllipseTest.class.st index 6402cee..9a7654a 100644 --- a/src/Geometry-Tests/GEllipseTest.class.st +++ b/src/Geometry-Tests/GEllipseTest.class.st @@ -29,6 +29,17 @@ GEllipseTest >> testHash [ equals: 17696867 ] +{ #category : #tests } +GEllipseTest >> testIntersectLineSegment [ + + self + assert: ((GEllipse center: 0 @ 0 a: 3 b: 2) intersectLineSegment: + (GLineSegment from: 0 @ 0 to: 0 @ 3)) + equals: { + (0 @ -2). + (0 @ 2) } asOrderedCollection +] + { #category : #tests } GEllipseTest >> testNotEquals [ From 68fd2eda911b38c4d7ca0ec71363d4ef49bdc70c Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 9 Nov 2023 14:39:07 +0100 Subject: [PATCH 11/22] Added tests to kill mutants of #has: --- src/Geometry-Tests/GSegmentTest.class.st | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/Geometry-Tests/GSegmentTest.class.st b/src/Geometry-Tests/GSegmentTest.class.st index 4d63272..5d864f9 100644 --- a/src/Geometry-Tests/GSegmentTest.class.st +++ b/src/Geometry-Tests/GSegmentTest.class.st @@ -222,6 +222,52 @@ GSegmentTest >> testHas [ equals: true. ] +{ #category : #tests } +GSegmentTest >> testHas2 [ + + self + assert: ((GSegment with: 0 @ 0 with: 2 @ 2) has: 2 @ 1) + equals: false. + self + assert: ((GSegment with: 0 @ 0 with: 2 @ 3) has: 2 @ 3) + equals: true. + self + assert: ((GSegment with: 0 @ 0 with: 2 @ 3) has: 0 @ 0) + equals: true. + self + assert: ((GSegment with: 2 @ 3 with: 0 @ 0) has: 2 @ 3) + equals: true. + self + assert: ((GSegment with: 2 @ 3 with: 0 @ 0) has: 0 @ 0) + equals: true. + self + assert: ((GSegment with: 2 @ 3 with: 0 @ 0) has: 1 @ (3/2)) + equals: true +] + +{ #category : #tests } +GSegmentTest >> testHas3 [ + + self + assert: ((GSegment with: 2 @ 0 with: 2 @ 2) has: 2 @ 3) + equals: false. + self + assert: ((GSegment with: 2 @ 0 with: 2 @ 2) has: 2 @ -1) + equals: false. + self + assert: ((GSegment with: 2 @ 0 with: 2 @ 2) has: 2 @ 1) + equals: true. + self + assert: ((GSegment with: 0 @ 2 with: 2 @ 2) has: 3 @ 2) + equals: false. + self + assert: ((GSegment with: 0 @ 2 with: 2 @ 2) has: -1 @ 2) + equals: false. + self + assert: ((GSegment with: 0 @ 2 with: 2 @ 2) has: 1 @ 2) + equals: true +] + { #category : #tests } GSegmentTest >> testHasPoint [ From 34550dcc977d5c67a8223b4979afb35c36e24e3f Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 9 Nov 2023 14:41:10 +0100 Subject: [PATCH 12/22] Refactoring #has: method to eliminate remaining mutants --- src/Geometry/GSegment.class.st | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Geometry/GSegment.class.st b/src/Geometry/GSegment.class.st index 5f9f1fa..f88e283 100644 --- a/src/Geometry/GSegment.class.st +++ b/src/Geometry/GSegment.class.st @@ -9,7 +9,7 @@ Class { 'v2', 'epsilon' ], - #category : 'Geometry' + #category : #Geometry } { #category : #'as yet unclassified' } @@ -130,16 +130,14 @@ GSegment >> extendWith: point and: frame [ { #category : #properties } GSegment >> has: p [ - (self asLine hasPoint: p) - ifFalse:[^false] - ifTrue:[ ^(( - ((self v1 x <= p x and:[ p x <= self v2 x]) - or:[ self v2 x <= p x and:[ p x <= self v1 x]])) - and:[ - ((self v1 y <= p y and:[ p y <= self v2 y]) - or:[ self v2 y <= p y and:[ p y <= self v1 y]])]) - ] + (self asLine hasPoint: p) + ifFalse: [ ^ false ] + ifTrue: [ + ^ ((p x between: self v1 x and: self v2 x) or: [ + p x between: self v2 x and: self v1 x ]) and: [ + (p y between: self v1 y and: self v2 y) or: [ + p y between: self v2 y and: self v1 y ] ] ] ] { #category : #properties } From ec58a4d74e9c6e3fc4a09019b29f65e77ea6a956 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 9 Nov 2023 15:03:12 +0100 Subject: [PATCH 13/22] Tests to kill mutants in #= for GSegment --- src/Geometry-Tests/GSegmentTest.class.st | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Geometry-Tests/GSegmentTest.class.st b/src/Geometry-Tests/GSegmentTest.class.st index 5d864f9..00e2a53 100644 --- a/src/Geometry-Tests/GSegmentTest.class.st +++ b/src/Geometry-Tests/GSegmentTest.class.st @@ -168,6 +168,31 @@ GSegmentTest >> testEqual3 [ equals:true ] +{ #category : #tests } +GSegmentTest >> testEqual4 [ + + self + assert: (GSegment with: 1 @ 1 with: 1 @ 1) + = (GSegment with: 1 @ 1 with: 1 @ 1) + equals: true. + self + assert: (GSegment with: 1 @ 2 with: 3 @ 4) + = (GSegment with: 1 @ 2 with: 3 @ 3) + equals: false. + self + assert: (GSegment with: 1 @ 2 with: 3 @ 3) + = (GSegment with: 1 @ 1 with: 3 @ 3) + equals: false. + self + assert: (GSegment with: 1 @ 2 with: 3 @ 4) + = (GSegment with: 3 @ 3 with: 1 @ 2) + equals: false. + self + assert: (GSegment with: 1 @ 2 with: 3 @ 3) + = (GSegment with: 3 @ 3 with: 1 @ 1) + equals: false +] + { #category : #tests } GSegmentTest >> testExtendSegmVert [ | segm1 segm2 segm3 frame | From f2ab507babe4ceffab4b66cfee92bc9137eb3904 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 9 Nov 2023 16:15:56 +0100 Subject: [PATCH 14/22] Revert --- src/Geometry/GSegment.class.st | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Geometry/GSegment.class.st b/src/Geometry/GSegment.class.st index f88e283..1c4ac16 100644 --- a/src/Geometry/GSegment.class.st +++ b/src/Geometry/GSegment.class.st @@ -130,14 +130,16 @@ GSegment >> extendWith: point and: frame [ { #category : #properties } GSegment >> has: p [ - (self asLine hasPoint: p) - ifFalse: [ ^ false ] - ifTrue: [ - ^ ((p x between: self v1 x and: self v2 x) or: [ - p x between: self v2 x and: self v1 x ]) and: [ - (p y between: self v1 y and: self v2 y) or: [ - p y between: self v2 y and: self v1 y ] ] ] + ifFalse:[^false] + ifTrue:[ ^(( + ((self v1 x <= p x and:[ p x <= self v2 x]) + or:[ self v2 x <= p x and:[ p x <= self v1 x]])) + and:[ + ((self v1 y <= p y and:[ p y <= self v2 y]) + or:[ self v2 y <= p y and:[ p y <= self v1 y]])]) + ] + ] { #category : #properties } From b63d9689acc05f0a6155388572b75b625347322a Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 9 Nov 2023 16:16:41 +0100 Subject: [PATCH 15/22] Added tests to kill mutants for #hasPoint --- src/Geometry-Tests/GSegmentTest.class.st | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Geometry-Tests/GSegmentTest.class.st b/src/Geometry-Tests/GSegmentTest.class.st index 00e2a53..5df3a68 100644 --- a/src/Geometry-Tests/GSegmentTest.class.st +++ b/src/Geometry-Tests/GSegmentTest.class.st @@ -304,6 +304,20 @@ GSegmentTest >> testHasPoint [ equals: true. ] +{ #category : #tests } +GSegmentTest >> testHasPoint2 [ + + self + assert: ((GSegment with: 1 @ 1 with: 3 @ 3) hasPoint: 4 @ 4) + equals: false. + self + assert: ((GSegment with: 1 @ 3 with: 3 @ 1) hasPoint: 4 @ 2) + equals: false. + self + assert: ((GSegment with: 3 @ 1 with: 1 @ 3) hasPoint: 2 @ 0) + equals: false. +] + { #category : #tests } GSegmentTest >> testIntersect [ self From 6f44472b2f65d60937b94210e980bd3c1ed7f1d4 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 9 Nov 2023 17:14:04 +0100 Subject: [PATCH 16/22] Tests to kill mutants for #hash, #hasPoint:, #extendWith:And:, #cutWith: --- src/Geometry-Tests/GSegmentTest.class.st | 55 +++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/Geometry-Tests/GSegmentTest.class.st b/src/Geometry-Tests/GSegmentTest.class.st index 5df3a68..2e6c289 100644 --- a/src/Geometry-Tests/GSegmentTest.class.st +++ b/src/Geometry-Tests/GSegmentTest.class.st @@ -99,6 +99,30 @@ GSegmentTest >> testCutWith [ equals: nil. ] +{ #category : #tests } +GSegmentTest >> testCutWith2 [ + + self + assert: ((GSegment with: 1 @ 2 with: 2 @ 2) cutWith: + (Rectangle origin: 0 @ 2 corner: 3 @ 0)) + equals: (GSegment with: 1 @ 2 with: 2 @ 2). + self + assert: ((GSegment with: 20 @ 30 with: -10 @ 10) cutWith: + (Rectangle origin: -15 @ 0 corner: 15 @ 15)) + equals: (GSegment with: -5 / 2 @ 15 with: -10 @ 10). + self + assert: + ((GSegment with: 1 @ 3 with: 5 @ 3) cutWith: + (GPolygon newVertices: { + (1 @ 5). + (1 @ 2). + (1 @ 4). + (1 @ 1). + (3 @ 1). + (3 @ 5) })) v2 + equals: 3 @ 3 +] + { #category : #tests } GSegmentTest >> testDist1 [ self assert:( ((GSegment with: ((838/41)@(4811/82)) with:((57583/914)@(56095/914))) dist: (57.998905906959145@61.11074842728413)) <=~ (2 * 0.02757564283371476 ) ) @@ -236,6 +260,29 @@ self assert:((GSegment with: -2 @ 4 with: 2 @ 4) extendWith: 3 @ 4 and: frame) equals: (GSegment with: 3 @ 4 with: -5 @ 4). ] +{ #category : #tests } +GSegmentTest >> testExtendWithAnd2 [ + + | frame | + frame := Rectangle origin: -5 @ 0 corner: 5 @ 5. + self + assert: + ((GSegment with: -2 @ 4 with: 2 @ 4) extendWith: -3 @ 4 and: frame) + equals: (GSegment with: -3 @ 4 with: 5 @ 4). + self + assert: + ((GSegment with: -2 @ 4 with: 2 @ 4) extendWith: -3 @ 4 and: frame) + equals: (GSegment with: 5 @ 4 with: -3 @ 4). + self + assert: + ((GSegment with: -2 @ 4 with: 2 @ 4) extendWith: 3 @ 3 and: frame) + equals: (GSegment with: -2 @ 4 with: 2 @ 4). + self + assert: + ((GSegment with: -2 @ 4 with: 2 @ 4) extendWith: 6 @ 4 and: frame) + equals: (GSegment with: 6 @ 4 with: -5 @ 4) +] + { #category : #tests } GSegmentTest >> testHas [ @@ -315,7 +362,13 @@ GSegmentTest >> testHasPoint2 [ equals: false. self assert: ((GSegment with: 3 @ 1 with: 1 @ 3) hasPoint: 2 @ 0) - equals: false. + equals: false +] + +{ #category : #tests } +GSegmentTest >> testHash [ + + self assert: (GSegment with: 0 @ 1 with: 2 @ 3) hash equals: 1571190 ] { #category : #tests } From 98446ae098f4c45f9baeece6d2a6944ec0dc987c Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 9 Nov 2023 17:31:17 +0100 Subject: [PATCH 17/22] Tests to kill mutants for #intersectionPointWithLine:, #intersectionPointWithRay: --- src/Geometry-Tests/GSegmentTest.class.st | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Geometry-Tests/GSegmentTest.class.st b/src/Geometry-Tests/GSegmentTest.class.st index 2e6c289..a6486fe 100644 --- a/src/Geometry-Tests/GSegmentTest.class.st +++ b/src/Geometry-Tests/GSegmentTest.class.st @@ -395,6 +395,21 @@ GSegmentTest >> testIntersect2 [ equals: (0@0) ] +{ #category : #tests } +GSegmentTest >> testIntersectionPointWithLine [ + + self + assert: + ((GSegment with: 2 @ 0 with: 2 @ 3) intersectionPointWithLine: + (GLine through: 0 @ 1 and: 2 @ 1)) + equals: 2 @ 1. + self + assert: + ((GSegment with: 2 @ 2 with: 2 @ 3) intersectionPointWithLine: + (GLine through: 0 @ 1 and: 2 @ 1)) + equals: nil +] + { #category : #tests } GSegmentTest >> testIntersectionPointWithVector [ self @@ -411,6 +426,21 @@ GSegmentTest >> testIntersectionPointWithVector [ equals: 0 @ 0. ] +{ #category : #tests } +GSegmentTest >> testIntersectionPointWithVector2 [ + + self + assert: + ((GSegment with: 0 @ 0 with: 0 @ 3) intersectionPointWithRay: + (GRay origin: 1 @ 2 direction: 2 @ 2)) + equals: nil. + self + assert: + ((GSegment with: 0 @ 0 with: 0 @ 1) intersectionPointWithRay: + (GRay origin: 0 @ 2 direction: 2 @ 2)) + equals: nil +] + { #category : #tests } GSegmentTest >> testIsOnLinePointWithRespectWith [ "self assert: ((GSegment with:((18427/974)@(57187/974)) with:(362.2460738148583@ -421.94450334080176)) hasOnLinePoint: ((838/41)@(4811/82)) withRespectTo: ((18427/974)@(57187/974)) withApprox: 0.8902246907382428) From 5cd8643a680955a4697203b7d00d81fcdc4437c0 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Fri, 10 Nov 2023 10:51:59 +0100 Subject: [PATCH 18/22] Tests to kill mutants and increase code coverage --- src/Geometry-Tests/GSegmentTest.class.st | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Geometry-Tests/GSegmentTest.class.st b/src/Geometry-Tests/GSegmentTest.class.st index a6486fe..4566215 100644 --- a/src/Geometry-Tests/GSegmentTest.class.st +++ b/src/Geometry-Tests/GSegmentTest.class.st @@ -80,6 +80,23 @@ self assert:((GSegment with: -2 @ 4 with: -2 @ 0) belowPoint: -4 @ 2 ) equals: false. ] +{ #category : #tests } +GSegmentTest >> testBoundBy [ + + self + assert: ((GSegment with: 0 @ 0 with: 1 @ 1) boundBy: 0 @ 0) + equals: true. + self + assert: ((GSegment with: 0 @ 0 with: 1 @ 1) boundBy: 1 @ 1) + equals: true. + self + assert: ((GSegment with: 0 @ 0 with: 1 @ 1) boundBy: 1 @ 0) + equals: false. + self + assert: ((GSegment with: 0 @ 0 with: 0 @ 0) boundBy: 0 @ 0) + equals: true +] + { #category : #tests } GSegmentTest >> testCutWith [ self @@ -473,6 +490,20 @@ GSegmentTest >> testLength1 [ equals: 34 sqrt ] +{ #category : #tests } +GSegmentTest >> testLocationOf [ + + self + assert: ((GSegment with: 0 @ 0 with: 2 @ 2) locationOf: 1 @ 1) + equals: 0. + self + assert: ((GSegment with: 10 @ 10 with: 30 @ 20) locationOf: 15 @ 15) + equals: 1. + self + assert: ((GSegment with: 10 @ 10 with: 20 @ 30) locationOf: 15 @ 15) + equals: -1 +] + { #category : #tests } GSegmentTest >> testMidPoint [ self From 33ffa42d7c4d96347f7e8d4b7bf07388b5f9a3d9 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Fri, 10 Nov 2023 12:17:15 +0100 Subject: [PATCH 19/22] Added tests to kill mutants in GTriangle --- src/Geometry-Tests/GTriangleTest.class.st | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Geometry-Tests/GTriangleTest.class.st b/src/Geometry-Tests/GTriangleTest.class.st index 484fbbc..416c53b 100644 --- a/src/Geometry-Tests/GTriangleTest.class.st +++ b/src/Geometry-Tests/GTriangleTest.class.st @@ -51,6 +51,15 @@ GTriangleTest >> testCircumscribedCircle3 [ +] + +{ #category : #tests } +GTriangleTest >> testCircumscribedCircle4 [ + + self + assert: (GTriangle with: 1000 @ 0 with: 50 @ 0 with: 0 @ 0) + circumscribedCircle + equals: nil ] { #category : #tests } @@ -97,6 +106,19 @@ self ] +{ #category : #tests } +GTriangleTest >> testIsDegenerate5 [ + + self assert: + (GTriangle with: 0 @ 0 with: 0 @ 3 with: 0 @ 1) isDegenerate. + self assert: + (GTriangle with: 0 @ 0 with: 0 @ 0 with: 0 @ 1) isDegenerate. + self assert: + (GTriangle with: 0 @ 0 with: 0 @ 3 with: 0 @ 3) isDegenerate. + self assert: + (GTriangle with: 0 @ 0 with: 0 @ 0 with: 0 @ 0) isDegenerate +] + { #category : #tests } GTriangleTest >> testPerimeter [ self From 80cdca2eb6296171fa73013f353eee69bb4e75c2 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Fri, 10 Nov 2023 14:25:08 +0100 Subject: [PATCH 20/22] Added test to kill mutant in GRectangle --- src/Geometry-Tests/GRectangleTest.class.st | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Geometry-Tests/GRectangleTest.class.st b/src/Geometry-Tests/GRectangleTest.class.st index a8c8019..8749478 100644 --- a/src/Geometry-Tests/GRectangleTest.class.st +++ b/src/Geometry-Tests/GRectangleTest.class.st @@ -38,6 +38,18 @@ GRectangleTest >> testHasPoint [ equals: false. ] +{ #category : #tests } +GRectangleTest >> testIntersectLineSegment [ + + self + assert: + ((GRectangle origin: 1 @ 3 corner: 3 @ 0) intersectLineSegment: + (GLineSegment from: 0 @ 2 to: 4 @ 2)) + equals: { + (1 @ 2). + (3 @ 2) } asSet +] + { #category : #tests } GRectangleTest >> testIntersectionPointWithRay [ self assert:((Rectangle origin: 1 @ 3 corner: 3 @ 0) intersectionPointWithRay: ((GRay origin: 2@1 direction: 4@1 ))) From f22a9dcbb985a5d6d4aa73519b8e6d3f129ae1e2 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Fri, 10 Nov 2023 15:01:28 +0100 Subject: [PATCH 21/22] Commented duplicated method --- src/Geometry/GRoundedRectangle.class.st | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Geometry/GRoundedRectangle.class.st b/src/Geometry/GRoundedRectangle.class.st index a3505b4..084fdd7 100644 --- a/src/Geometry/GRoundedRectangle.class.st +++ b/src/Geometry/GRoundedRectangle.class.st @@ -8,7 +8,7 @@ Class { 'rectangle', 'borderRadius' ], - #category : 'Geometry' + #category : #Geometry } { #category : #'instance creation' } @@ -73,9 +73,13 @@ GRoundedRectangle >> encompassingRectangle [ { #category : #comparing } GRoundedRectangle >> intersectLine: aLine [ - (self corners flatCollect: [ :each | aLine intersectCircleArc: each ]) + "same as intersectLineSegment:" + + "(self corners flatCollect: [ :each | aLine intersectCircleArc: each ]) ifNotEmpty: [ :col | ^ col ]. - ^ aLine intersectRectangle: self rectangle + ^ aLine intersectRectangle: self rectangle" + + ] { #category : #comparing } From da2694bdd8e582bc095fb7aa619be028d825ab8b Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Fri, 10 Nov 2023 15:02:02 +0100 Subject: [PATCH 22/22] Added tests for GRoundedRectangle to kill mutants --- .../GRoundedRectangleTest.class.st | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/src/Geometry-Tests/GRoundedRectangleTest.class.st b/src/Geometry-Tests/GRoundedRectangleTest.class.st index c19b155..10d1f40 100644 --- a/src/Geometry-Tests/GRoundedRectangleTest.class.st +++ b/src/Geometry-Tests/GRoundedRectangleTest.class.st @@ -4,6 +4,16 @@ Class { #category : #'Geometry-Tests' } +{ #category : #tests } +GRoundedRectangleTest >> testCenter [ + + self + assert: (GRoundedRectangle + rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1) + borderRadius: 0.5) center + equals: 0 @ 0 +] + { #category : #tests } GRoundedRectangleTest >> testCorners [ | rect | @@ -39,3 +49,74 @@ GRoundedRectangleTest >> testCorners [ startAngle: Float threePi / 2 endAngle: Float twoPi)) ] + +{ #category : #tests } +GRoundedRectangleTest >> testEncompassingRectangle [ + + | rect | + rect := GRoundedRectangle + rectangle: (GRectangle origin: -40 @ -20 corner: 40 @ 20) + borderRadius: 10. + self + assert: (GRoundedRectangle + rectangle: (GRectangle origin: -40 @ -20 corner: 40 @ 20) + borderRadius: 10) encompassingRectangle + equals: (GRectangle origin: -40 @ -20 corner: 40 @ 20) +] + +{ #category : #tests } +GRoundedRectangleTest >> testEqual [ + + self + assert: (GRoundedRectangle + rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1) + borderRadius: 0.5) + equals: (GRoundedRectangle + rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1) + borderRadius: 0.5). + self + deny: (GRoundedRectangle + rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1) + borderRadius: 0.5) + equals: (GRoundedRectangle + rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1) + borderRadius: 1). + self + deny: (GRoundedRectangle + rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1) + borderRadius: 0.5) + equals: (GRoundedRectangle + rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 2) + borderRadius: 0.5). + self + deny: (GRoundedRectangle + rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1) + borderRadius: 0.5) + equals: (GRoundedRectangle + rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 2) + borderRadius: 1). + self deny: (GRoundedRectangle + rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1) + borderRadius: 0.5) = (Rectangle origin: -2 @ -1 corner: 2 @ 1) +] + +{ #category : #tests } +GRoundedRectangleTest >> testIntersectLineSegment [ + + | rect | + rect := GRoundedRectangle + rectangle: (GRectangle origin: -40 @ -20 corner: 40 @ 20) + borderRadius: 10. + self + assert: + (rect intersectLineSegment: (GLineSegment from: -40 @ 15 to: 40 @ 15)) + equals: { + (-38.66025403784438 @ 15.0). + (38.660254037844396 @ 15.0) }. + self + assert: + (rect intersectLineSegment: (GLineSegment from: -40 @ 5 to: 40 @ 5)) + equals: { + (-40 @ 5). + (40 @ 5) } asSet +]