From 8eeec56d0c204b7baa601b7ce4a6afef2ccc019e Mon Sep 17 00:00:00 2001 From: Jacob Collins <18370334+josrepo@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:34:56 +0000 Subject: [PATCH 1/2] Fix error object not returned correctly --- Smalltalk/Vector.som | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Smalltalk/Vector.som b/Smalltalk/Vector.som index 30eccd32..0e55f64d 100644 --- a/Smalltalk/Vector.som +++ b/Smalltalk/Vector.som @@ -78,7 +78,7 @@ Vector = ( "Removing" remove = ( | value | - self isEmpty ifTrue: [ self error: 'Vector: Attempting to remove the last element from an empty Vector' ]. + self isEmpty ifTrue: [ ^ self error: 'Vector: Attempting to remove the last element from an empty Vector' ]. last := last - 1. value := storage at: last. storage at: last put: nil. @@ -158,7 +158,7 @@ Vector = ( "DeltaBlue" removeFirst = ( | value | - self isEmpty ifTrue: [ self error: 'Vector: Attempting to remove the first element from an empty Vector' ]. + self isEmpty ifTrue: [ ^ self error: 'Vector: Attempting to remove the first element from an empty Vector' ]. value := storage at: first. storage at: first put: nil. first := first + 1. From 42c7d157f0d09cfafd94957af72b0ef98491525c Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Fri, 26 Jan 2024 21:48:30 +0000 Subject: [PATCH 2/2] Added unit test for the error case of Vector>>#remove and #removeFirst Signed-off-by: Stefan Marr --- TestSuite/VectorSubclass.som | 5 +++++ TestSuite/VectorTest.som | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 TestSuite/VectorSubclass.som diff --git a/TestSuite/VectorSubclass.som b/TestSuite/VectorSubclass.som new file mode 100644 index 00000000..891b264b --- /dev/null +++ b/TestSuite/VectorSubclass.som @@ -0,0 +1,5 @@ +VectorSubclass = Vector ( + error: string = ( + ^ #error + ) +) diff --git a/TestSuite/VectorTest.som b/TestSuite/VectorTest.som index 7ef820f3..36915fc0 100644 --- a/TestSuite/VectorTest.som +++ b/TestSuite/VectorTest.som @@ -103,6 +103,18 @@ VectorTest = TestCase ( v remove ] ) + testRemoveOnEmptyWithSubclass = ( + | v | + v := VectorSubclass new. + self assert: #error is: v remove. + ) + + testRemoveFirstOnEmptyWithSubclass = ( + | v | + v := VectorSubclass new. + self assert: #error is: v removeFirst. + ) + testContains = ( self assert: (a contains: 'hello'). self assert: (a contains: #world).