Skip to content
Permalink
Browse files

2.4 / Add circumference selector to Wheel class. And add a constructo…

…r method to make testRatio green.
  • Loading branch information
yujihamaguchi committed Dec 29, 2019
1 parent c9d8b6f commit a2ac249d8576572a286394aac87e720af8efc462
@@ -6,9 +6,13 @@ Class {

{ #category : #tests }
GearTest >> testGearInches [
self assert: (Gear chainring: 52 cog: 11 rim: 26 tire: 1.5) gearInches equals: 137.0909090909091.
self assert: (Gear chainring: 52 cog: 11 rim: 24 tire: 1.25) gearInches equals: 125.27272727272728

| wheel1 gear1 wheel2 gear2 |
wheel1 := Wheel rim: 26 tire: 1.5.
gear1 := Gear chainring: 52 cog: 11 wheel: wheel1.
wheel2 := Wheel rim: 24 tire: 1.25.
gear2 := Gear chainring: 52 cog: 11 wheel: wheel2.
self assert: gear1 gearInches equals: 137.0909090909091.
self assert: gear2 gearInches equals: 125.27272727272728
]

{ #category : #tests }
@@ -4,11 +4,17 @@ Class {
#category : #'Example-OOD-Tests'
}

{ #category : #tests }
WheelTest >> testCircumference [
self
assert: (Wheel rim: 26 tire: 1.5) circumference
equals: 91.106186954104
]

{ #category : #tests }
WheelTest >> testDiameter [
self assert: (Wheel rim: 622 tire: 20) diameter equals: 662.
self assert: (Wheel rim: 622 tire: 23) diameter equals: 668.
self assert: (Wheel rim: 559 tire: 30) diameter equals: 619.
self assert: (Wheel rim: 559 tire: 40) diameter equals: 639

self assert: (Wheel rim: 559 tire: 40) diameter equals: 639
]
@@ -10,13 +10,21 @@ Class {
}

{ #category : #'instance creation' }
Gear class >> chainring: chainringInteger cog: cogInteger rim: rimInteger tire: tireFloat [
^ self basicNew setChainring: chainringInteger cog: cogInteger rim: rimInteger tire: tireFloat .
Gear class >> chainring: chainringInteger cog: cogInteger [
^ self basicNew setChainring: chainringInteger cog: cogInteger
]

{ #category : #'instance creation' }
Gear class >> chainring: chainringInteger cog: cogInteger wheel: aWheel [
^ self basicNew
setChainring: chainringInteger
cog: cogInteger
wheel: aWheel
]

{ #category : #calculating }
Gear >> gearInches [
^ self ratio * wheel diameter
^ self ratio * wheel diameter
]

{ #category : #calculating }
@@ -25,9 +33,16 @@ Gear >> ratio [
]

{ #category : #private }
Gear >> setChainring: chainringInteger cog: cogInteger rim: rimInteger tire: tireFloat [
Gear >> setChainring: chainringInteger cog: cogInteger [
chainring := chainringInteger.
cog := cogInteger.
^ self
]

{ #category : #private }
Gear >> setChainring: chainringInteger cog: cogInteger wheel: aWheel [
chainring := chainringInteger.
cog := cogInteger.
wheel := Wheel rim: rimInteger tire: tireFloat .
wheel := aWheel.
^ self
]
@@ -13,6 +13,11 @@ Wheel class >> rim: rimInteger tire: tireFloat [
^ self basicNew setRim: rimInteger tire: tireFloat
]

{ #category : #calculating }
Wheel >> circumference [
^ self diameter * Float pi
]

{ #category : #calculating }
Wheel >> diameter [
^ rim + (tire * 2)

0 comments on commit a2ac249

Please sign in to comment.
You can’t perform that action at this time.