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

Adds Gu You and Cham #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 29 additions & 16 deletions lib/kopi.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Kopi
# defaults
evaporated_milk = condensed_milk = water = coffee = sugar = 0
ice = false
mixin = ''

if /^kopi/.test name

Expand Down Expand Up @@ -40,18 +41,8 @@ class Kopi
sugar = 0

# gah dai = more sweet
else if /\b(gah|ka)\sdai\b/.test(name)
if condensed_milk > 0
condensed_milk += .1
water -= .05
coffee -= .05
else if evaporated_milk > 0
evaporated_milk += .1
water -= .05
coffee -= .05
else
sugar = 1.5

else if /\b(gah|ka)\sdai\b/.test(name)
sugar = 1.5

# siu dai = less sweet
else if /\bsi(u|ew)\sdai\b/.test name
Expand All @@ -72,10 +63,22 @@ class Kopi
coffee += water
water = 0

# huan = add more condensed milk
else if /\bhuan\b/.test name
condensed_milk = .4

# 3. ICE

ice = true if /\speng$/.test name

# 4. BUTTER

mixin = 'butter' if /\sgu you$/.test name

# 5. Tea (also known as YuangYang)

mixin = 'tea' if /\scham$/.test name

else if /^water$/.test name
water = 1

Expand All @@ -85,6 +88,7 @@ class Kopi
condensed_milk: condensed_milk
evaporated_milk: evaporated_milk
ice: ice
mixin: mixin

stringify: (i={}) ->
if i.condensed_milk > 0
Expand All @@ -98,18 +102,20 @@ class Kopi
sugarLevel = ' Kosong'
else if i.sugar < 1
sugarLevel = ' Siew Dai'
else if i.sugar >= 1
else if i.sugar == 1
sugarLevel = ''
else if i.sugar > 1
sugarLevel = ' Gah Dai'

if i.coffee == i.water
coffeeLevel = ''
else if i.coffee > i.water
if i.water == 0
coffeeLevel = ' Di Lo'
else if i.condensed_milk > i.water
coffeeLevel = ' Gah Dai'
else
coffeeLevel = ' Gau'
else if i.condensed_milk >= i.water
coffeeLevel = ' Huan'
else
coffeeLevel = ' Po'

Expand All @@ -118,6 +124,13 @@ class Kopi
else
ice = ''

"Kopi#{milk}#{coffeeLevel}#{sugarLevel}#{ice}"
mixin = ''

if i.butter
mixin = ' Gu You'
else if i.tea
mixin = ' Cham'

"Kopi#{milk}#{coffeeLevel}#{sugarLevel}#{ice}#{mixin}"

module.exports = new Kopi
66 changes: 57 additions & 9 deletions test/kopi_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe 'Kopi', ->
condensed_milk: .2
evaporated_milk: 0
ice: false
mixin: ''

it 'returns Kopi O contents if pass in "Kopi O"', ->
content = Kopi.parse 'Kopi O'
Expand All @@ -23,6 +24,7 @@ describe 'Kopi', ->
condensed_milk: 0
evaporated_milk: 0
ice: false
mixin: ''

it 'returns Kopi C contents if pass in "Kopi C"', ->
content = Kopi.parse 'Kopi C'
Expand All @@ -33,19 +35,32 @@ describe 'Kopi', ->
condensed_milk: 0
evaporated_milk: .2
ice: false
mixin: ''

it 'returns Kopi Huan contents if pass in "Kopi Huan"', ->
content = Kopi.parse 'Kopi Huan'
expect(content).to.deep.equal
water: .4
coffee: .4
sugar: 1
condensed_milk: .4
evaporated_milk: 0
ice: false
mixin: ''

it 'returns no sugar if pass in "Kosong"', ->
content = Kopi.parse 'Kopi O Kosong'
expect(content.sugar).to.equal 0

it 'returns more condensed milk if pass in "Gah Dai"', ->
it 'returns more sugar if pass in "Gah Dai"', ->
content = Kopi.parse 'Kopi'
contentGahDai = Kopi.parse 'Kopi Gah Dai'
expect(contentGahDai.condensed_milk).to.be.gt content.condensed_milk
expect(contentGahDai.sugar).to.be.gt content.sugar

it 'returns less sugar if pass in "Siu Dai"', ->
content = Kopi.parse 'Kopi Siu Dai'
expect(content.sugar).to.be.equal .5
content = Kopi.parse 'Kopi'
contentGahDai = Kopi.parse 'Kopi Siu Dai'
expect(contentGahDai.sugar).to.be.lt content.sugar

it 'returns more water, less coffee if pass in "Po"', ->
content = Kopi.parse 'Kopi Po'
Expand All @@ -64,6 +79,14 @@ describe 'Kopi', ->
content = Kopi.parse 'Kopi Peng'
expect(content.ice).to.be.true

it 'returns mixin as butter if pass in "Gu You"', ->
content = Kopi.parse 'Kopi Gu You'
expect(content.mixin).to.equal 'butter'

it 'returns tea if pass in "Cham"', ->
content = Kopi.parse 'Kopi Cham'
expect(content.mixin).to.be.equal 'tea'

it 'returns water if pass in "Water"', ->
content = Kopi.parse 'Water'
expect(content.water).to.be.equal 1
Expand Down Expand Up @@ -109,22 +132,29 @@ describe 'Kopi', ->
sugar: 0
expect(name).to.equal 'Kopi Kosong'

it 'returns "Kopi Gah Dai" if more milk is added', ->
it 'returns "Kopi Gah Dai" if more suagr is added', ->
name = Kopi.stringify
condensed_milk: .4
water: .2
condensed_milk: .2
water: .4
coffee: .4
sugar: 1
sugar: 1.5
expect(name).to.equal 'Kopi Gah Dai'

it 'returns "Kopi Di Lo" if no water is added', ->
name = Kopi.stringify
condensed_milk: .2
water: 0
coffee: .4
coffee: .8
sugar: 1
expect(name).to.equal 'Kopi Di Lo'

it 'returns "Kopi Huan" if extra condensed milk is added', ->
name = Kopi.stringify
condensed_milk: .4
water: .4
coffee: .2
sugar: 1
expect(name).to.equal 'Kopi Huan'

it 'returns Kopi name appended with "Peng" if ice is added', ->
name = Kopi.stringify
Expand All @@ -142,6 +172,24 @@ describe 'Kopi', ->
ice: true
expect(name).to.equal 'Kopi Gau Peng'

it 'returns Kopi name appended with "Gu You" if butter is added', ->
name = Kopi.stringify
condensed_milk: .2
water: .4
coffee: .4
sugar: 1
butter: true
expect(name).to.equal 'Kopi Gu You'

it 'returns Kopi name appended with "Cham" if tea is mixed', ->
name = Kopi.stringify
condensed_milk: .2
water: .4
coffee: .4
sugar: 1
tea: true
expect(name).to.equal 'Kopi Cham'

context 'when no milk is added', ->
it 'returns "Kopi O" if equal amounts of water and coffee is added', ->
name = Kopi.stringify
Expand Down