Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Custom Printing Broke Regular; Should Be Avail. to All Units #21

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions source/Aconcagua-Core/BaseUnit.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {
'nameForMany',
'sign'
],
#category : 'Aconcagua-Core-MeasureModel'
#category : #'Aconcagua-Core-MeasureModel'
}

{ #category : #'instance creation' }
Expand Down Expand Up @@ -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 [

Expand Down
11 changes: 10 additions & 1 deletion source/Aconcagua-Core/SimpleUnit.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #SimpleUnit,
#superclass : #UnitBehavior,
#category : 'Aconcagua-Core-MeasureModel'
#category : #'Aconcagua-Core-MeasureModel'
}

{ #category : #'mathematic operations' }
Expand Down Expand Up @@ -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 [

Expand Down
13 changes: 13 additions & 0 deletions source/Aconcagua-Tests/DummyCentUnit.class.st
Original file line number Diff line number Diff line change
@@ -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'
]
12 changes: 11 additions & 1 deletion source/Aconcagua-Tests/ProportionalDerivedUnitTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Class {
'peso',
'centavo'
],
#category : 'Aconcagua-Tests-MeasureModel'
#category : #'Aconcagua-Tests-MeasureModel'
}

{ #category : #initialization }
Expand Down Expand Up @@ -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 [

Expand Down