Initialization method tested

This commit is contained in:
2025-08-25 10:56:31 +02:00
parent 4c919ae5cb
commit 693a8ff66f
2 changed files with 37 additions and 2 deletions

View File

@@ -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
]

View File

@@ -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
]