From 4c919ae5cb311eef2b1a2ad63785747b4dca3aaa Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 25 Aug 2025 10:28:07 +0200 Subject: [PATCH] Initial commit --- .project | 3 +++ src/.properties | 3 +++ src/MyCounter/Counter.class.st | 41 ++++++++++++++++++++++++++++++ src/MyCounter/CounterTest.class.st | 31 ++++++++++++++++++++++ src/MyCounter/package.st | 1 + 5 files changed, 79 insertions(+) create mode 100644 .project create mode 100644 src/.properties create mode 100644 src/MyCounter/Counter.class.st create mode 100644 src/MyCounter/CounterTest.class.st create mode 100644 src/MyCounter/package.st diff --git a/.project b/.project new file mode 100644 index 0000000..81083cc --- /dev/null +++ b/.project @@ -0,0 +1,3 @@ +{ + 'srcDirectory' : 'src' +} \ No newline at end of file diff --git a/src/.properties b/src/.properties new file mode 100644 index 0000000..ad0471d --- /dev/null +++ b/src/.properties @@ -0,0 +1,3 @@ +{ + #format : #tonel +} \ No newline at end of file diff --git a/src/MyCounter/Counter.class.st b/src/MyCounter/Counter.class.st new file mode 100644 index 0000000..caf12cc --- /dev/null +++ b/src/MyCounter/Counter.class.st @@ -0,0 +1,41 @@ +" +Counter is a simple concrete class which supports incrementing and +decrementing a counter. + +Its API is +- decrement, increment +- count +Its creation API is message startingAt: +" +Class { + #name : #Counter, + #superclass : #Object, + #instVars : [ + 'count' + ], + #category : #MyCounter +} + +{ #category : #accessing } +Counter >> count [ + + ^ count +] + +{ #category : #accessing } +Counter >> count: anInteger [ + + count := anInteger +] + +{ #category : #accessing } +Counter >> decrement [ + + count := count - 1 +] + +{ #category : #accessing } +Counter >> increment [ + + count := count + 1 +] diff --git a/src/MyCounter/CounterTest.class.st b/src/MyCounter/CounterTest.class.st new file mode 100644 index 0000000..29ba9b9 --- /dev/null +++ b/src/MyCounter/CounterTest.class.st @@ -0,0 +1,31 @@ +Class { + #name : #CounterTest, + #superclass : #TestCase, + #category : #MyCounter +} + +{ #category : #tests } +CounterTest >> testCountIsSetAndRead [ + | c | + c := Counter new. + c count: 7. + self assert: c count equals: 7 +] + +{ #category : #tests } +CounterTest >> testDecrement [ + | c | + c := Counter new. + c count: 2. + c decrement; decrement. + self assert: c count equals: 0 +] + +{ #category : #tests } +CounterTest >> testIncrement [ + | c | + c := Counter new. + c count: 2. + c increment; increment. + self assert: c count equals: 4 +] diff --git a/src/MyCounter/package.st b/src/MyCounter/package.st new file mode 100644 index 0000000..242e6c9 --- /dev/null +++ b/src/MyCounter/package.st @@ -0,0 +1 @@ +Package { #name : #MyCounter }