Skip to content

Instantly share code, notes, and snippets.

@johnelliott
Created November 6, 2014 20:56
Show Gist options
  • Save johnelliott/f2717dd25c3d720cda84 to your computer and use it in GitHub Desktop.
Save johnelliott/f2717dd25c3d720cda84 to your computer and use it in GitHub Desktop.
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