Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2013 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8027618 to your computer and use it in GitHub Desktop.
Save anonymous/8027618 to your computer and use it in GitHub Desktop.
w00t
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);
};
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