Created
November 6, 2014 20:56
-
-
Save johnelliott/f2717dd25c3d720cda84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var converter = { | |
usdExchangeRate: function(currencySymbol) { | |
var rates = { | |
'USD': 1, | |
'GBP': 0.63 | |
} | |
return rates[currencySymbol]; | |
}, | |
dollarsToPounds: function(usdAmount) { | |
return usdAmount * this.usdExchangeRate('GBP'); | |
} | |
}; | |
// converter.exchange(amount, from , to) | |
describe("Currency", function() { | |
describe("usdExchangeRate", function() { | |
it("should be 1 for 1 dollar", function() { | |
var rate = converter.usdExchangeRate('USD'); | |
expect(rate).toBe(1); | |
}); | |
// £: option key + 3 key on Mac OS X | |
it("should be 1 for pounds", function() { | |
var rate = converter.usdExchangeRate('GBP'); | |
expect(rate).toBe(0.63); | |
}); | |
}); | |
describe("dollarsToPounds", function() { | |
it("should convert 3.2USD to 2GBP", function() { | |
expect(converter.dollarsToPounds(3.2)).toBeCloseTo(2.02, 2) | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment