From 1ceca09860870123a37bc35f92a3ceb4e12e91a6 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Fri, 12 Apr 2024 14:10:04 +0200 Subject: [PATCH] add comments to smalltalk impl --- lab2/zad3/src/GF.st | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lab2/zad3/src/GF.st b/lab2/zad3/src/GF.st index ae3b88b..b4ca62e 100644 --- a/lab2/zad3/src/GF.st +++ b/lab2/zad3/src/GF.st @@ -23,12 +23,14 @@ Object subclass: GF [ ifTrue: [Error signal: 'both arguments must have the same characteristic'] ] + "throws Error on different characteristics" + rhs [ self verifyCharacteristics: rhs. ^GF create: characteristic withValue: ((value + rhs value) \\ characteristic) ] + "throws Error on different characteristics" - rhs [ self verifyCharacteristics: rhs. "^GF create: characteristic @@ -46,12 +48,15 @@ Object subclass: GF [ ]. ] + "throws Error on different characteristics" * rhs [ self verifyCharacteristics: rhs. ^GF create: characteristic withValue: ((value * rhs value) \\ characteristic) ] + "throws ZeroDivide on division by 0" + "throws Error on different characteristics" / rhs [ | inverse | self verifyCharacteristics: rhs. @@ -67,44 +72,53 @@ Object subclass: GF [ withValue: ((value * inverse) \\ characteristic) ] + "throws Error on different characteristics" = rhs [ self verifyCharacteristics: rhs. ^value = rhs value ] + "throws Error on different characteristics" ~= rhs [ self verifyCharacteristics: rhs. ^value ~= rhs value ] + "throws Error on different characteristics" > rhs [ self verifyCharacteristics: rhs. ^value > rhs value ] + "throws Error on different characteristics" < rhs [ self verifyCharacteristics: rhs. ^value < rhs value ] + "throws Error on different characteristics" >= rhs [ self verifyCharacteristics: rhs. ^value >= rhs value ] + "throws Error on different characteristics" <= rhs [ self verifyCharacteristics: rhs. ^value <= rhs value ] - + + "returns the characteristic of `self`" characteristic [ ^characteristic ] + "returns the value of `self`" value [ ^value ] + "prints `self` in a pretty format" displayOn: stream [ 'GF<' displayOn: stream. characteristic displayOn: stream.