From 693a8ff66f4c4f833d26ce8bcdef60c0f97ea656 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 25 Aug 2025 10:56:31 +0200 Subject: [PATCH] Initialization method tested --- src/MyCounter/Counter.class.st | 15 +++++++++++++-- src/MyCounter/CounterTest.class.st | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/MyCounter/Counter.class.st b/src/MyCounter/Counter.class.st index caf12cc..df8c7fe 100644 --- a/src/MyCounter/Counter.class.st +++ b/src/MyCounter/Counter.class.st @@ -16,6 +16,11 @@ Class { #category : #MyCounter } +{ #category : #accessing } +Counter class >> startingAt: anInteger [ + ^ self new count: anInteger +] + { #category : #accessing } Counter >> count [ @@ -28,14 +33,20 @@ Counter >> count: anInteger [ count := anInteger ] -{ #category : #accessing } +{ #category : #operation } Counter >> decrement [ count := count - 1 ] -{ #category : #accessing } +{ #category : #operation } Counter >> increment [ count := count + 1 ] + +{ #category : #initialization } +Counter >> initialize [ + super initialize. + count := 0 +] diff --git a/src/MyCounter/CounterTest.class.st b/src/MyCounter/CounterTest.class.st index 29ba9b9..ba2afe5 100644 --- a/src/MyCounter/CounterTest.class.st +++ b/src/MyCounter/CounterTest.class.st @@ -12,6 +12,11 @@ CounterTest >> testCountIsSetAndRead [ self assert: c count equals: 7 ] +{ #category : #tests } +CounterTest >> testCounterWellInitialized [ + self assert: (Counter new increment; increment; count) equals: 2 +] + { #category : #tests } CounterTest >> testDecrement [ | c | @@ -29,3 +34,22 @@ CounterTest >> testIncrement [ c increment; increment. self assert: c count equals: 4 ] + +{ #category : #tests } +CounterTest >> testInizialize [ + self assert: Counter new count equals: 0 +] + +{ #category : #tests } +CounterTest >> testStartingAt5 [ + | c | + c := Counter startingAt: 5. + self assert: c count equals: 5 +] + +{ #category : #tests } +CounterTest >> testStartingAt5Increment [ + | c | + c := Counter startingAt: 5. + self assert: (c increment; count) equals: 6 +]