Worked through, added tests for everything

This commit is contained in:
Peter Hart 2021-02-06 18:15:53 -05:00
parent bf91d19a0e
commit de470d6c33
3 changed files with 33 additions and 1 deletions

View File

@ -4,7 +4,7 @@ This class contains tests for the Counter class
Class { Class {
#name : #CounterTest, #name : #CounterTest,
#superclass : #TestCase, #superclass : #TestCase,
#category : #MyCounter #category : #'MyCounter-Tests'
} }
{ #category : #tests } { #category : #tests }

View File

@ -0,0 +1 @@
Package { #name : #'MyCounter-Tests' }

View File

@ -16,6 +16,11 @@ Class {
#category : #MyCounter #category : #MyCounter
} }
{ #category : #accessing }
Counter class >> startingAt: val [
^ self new count: val; yourself
]
{ #category : #accessing } { #category : #accessing }
Counter >> count [ Counter >> count [
"returns the current count" "returns the current count"
@ -29,3 +34,29 @@ Counter >> count: val [
^ val ^ val
] ]
{ #category : #API }
Counter >> decrement [
"decrease the value of count by 1"
count := count - 1.
^ self
]
{ #category : #API }
Counter >> increment [
"updates the count by 1"
count := count + 1.
^ self
]
{ #category : #initialization }
Counter >> initialize [
"Set the initial value to 0"
count := 0
]
{ #category : #printing }
Counter >> printOn: aStream [
super printOn: aStream.
aStream nextPutAll: ' with value: ', count printString.
]