Created
December 18, 2013 18:47
-
-
Save anonymous/8027618 to your computer and use it in GitHub Desktop.
w00t
This file contains 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 ops = { | |
"-": function (num1, num2) { return num1 - num2; }, | |
"*": function (num1, num2) { return num1 * num2; }, | |
"+": function (num1, num2) { return num1 + num2; } | |
}; | |
module.exports = function (str) { | |
var args = str.split(" "); | |
var num1 = parseInt(args[0], 10), | |
action = args[1], | |
num2 = parseInt(args[2], 10); | |
return ops[action](num1, num2); | |
}; |
This file contains 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 buster = require('buster'); | |
var expect = buster.referee.expect; | |
var calculate = require('../src/calc'); | |
buster.testCase("calc", { | |
"should sum 2 numbers": function () { | |
expect(calculate("1 + 1")).toEqual(2); | |
}, | |
"should subtract 2 numbers": function () { | |
expect(calculate("2 - 1")).toEqual(1); | |
}, | |
"should multiply 2 numbers": function () { | |
expect(calculate("2 * 3")).toEqual(6); | |
}, | |
"should use actual numbers for multiplication": function () { | |
expect(calculate("2 * 4")).toEqual(8); | |
}, | |
"should use actual numbers for addition": function () { | |
expect(calculate("2 + 4")).toEqual(6); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment