diff --git a/source/Aconcagua-Core/BaseUnit.class.st b/source/Aconcagua-Core/BaseUnit.class.st index b1eea8d..42cd389 100644 --- a/source/Aconcagua-Core/BaseUnit.class.st +++ b/source/Aconcagua-Core/BaseUnit.class.st @@ -6,7 +6,7 @@ Class { 'nameForMany', 'sign' ], - #category : 'Aconcagua-Core-MeasureModel' + #category : #'Aconcagua-Core-MeasureModel' } { #category : #'instance creation' } @@ -92,15 +92,6 @@ BaseUnit >> nothingAmount [ ^0 ] -{ #category : #printing } -BaseUnit >> printMeasure: aMeasure on: aStream [ - "If you need more flexibility, override in subclasses. E.g. '10 dollars' might want to print as '$10'" - - aMeasure amount printOn: aStream. - aStream space. - aStream nextPutAll: (aMeasure unit nameFor: self amount) asString -] - { #category : #accessing } BaseUnit >> sign [ diff --git a/source/Aconcagua-Core/SimpleUnit.class.st b/source/Aconcagua-Core/SimpleUnit.class.st index c236f74..a6aaf50 100644 --- a/source/Aconcagua-Core/SimpleUnit.class.st +++ b/source/Aconcagua-Core/SimpleUnit.class.st @@ -1,7 +1,7 @@ Class { #name : #SimpleUnit, #superclass : #UnitBehavior, - #category : 'Aconcagua-Core-MeasureModel' + #category : #'Aconcagua-Core-MeasureModel' } { #category : #'mathematic operations' } @@ -65,6 +65,15 @@ SimpleUnit >> multiplySimpleUnit: aUnit [ ^MultipliedUnit simpleUnit: self simpleUnit: aUnit ] +{ #category : #printing } +SimpleUnit >> printMeasure: aMeasure on: aStream [ + "If you need more flexibility, override in subclasses. E.g. '10 dollars' might want to print as '$10'" + + aMeasure amount printOn: aStream. + aStream space. + aStream nextPutAll: (aMeasure unit nameFor: aMeasure amount) asString +] + { #category : #'measurement creation' } SimpleUnit >> with: aNumber [ diff --git a/source/Aconcagua-Tests/DummyCentUnit.class.st b/source/Aconcagua-Tests/DummyCentUnit.class.st new file mode 100644 index 0000000..73b88f5 --- /dev/null +++ b/source/Aconcagua-Tests/DummyCentUnit.class.st @@ -0,0 +1,13 @@ +Class { + #name : #DummyCentUnit, + #superclass : #ProportionalDerivedUnit, + #category : #'Aconcagua-Tests-MeasureModel' +} + +{ #category : #printing } +DummyCentUnit >> printMeasure: aMeasure on: aStream [ + + aStream + print: aMeasure amount; + nextPutAll: 'c USD' +] diff --git a/source/Aconcagua-Tests/ProportionalDerivedUnitTest.class.st b/source/Aconcagua-Tests/ProportionalDerivedUnitTest.class.st index 43e1f14..c29f1a9 100644 --- a/source/Aconcagua-Tests/ProportionalDerivedUnitTest.class.st +++ b/source/Aconcagua-Tests/ProportionalDerivedUnitTest.class.st @@ -5,7 +5,7 @@ Class { 'peso', 'centavo' ], - #category : 'Aconcagua-Tests-MeasureModel' + #category : #'Aconcagua-Tests-MeasureModel' } { #category : #initialization } @@ -299,6 +299,16 @@ ProportionalDerivedUnitTest >> testNumerator [ self assert: unit numerator = unit ] +{ #category : #'test printing' } +ProportionalDerivedUnitTest >> testPrintingCustomization [ + + | unit measure | + + unit := DummyCentUnit baseUnit: DummyDollarUnit new conversionFactor: 1/100 named: 'cent'. + measure := Measure amount: 5 unit: unit. + self assert: measure printString equals: '5c USD'. +] + { #category : #'test accessing' } ProportionalDerivedUnitTest >> testReciprocal [