From d11119fd93b82fe4d1077b9590613db927c3f4e0 Mon Sep 17 00:00:00 2001 From: Ghosdak Date: Thu, 29 Oct 2015 23:12:52 +0800 Subject: [PATCH 1/2] commit --- test/.gitattributes | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/.gitattributes diff --git a/test/.gitattributes b/test/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/test/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain From 23e1556cd50bd4366009f251113d9213aebfca8f Mon Sep 17 00:00:00 2001 From: Ghosdak Date: Thu, 29 Oct 2015 23:17:06 +0800 Subject: [PATCH 2/2] commit --- Sinon.js.js | 25 ++++++++++++++++++++++++ calculator.js | 11 +++++++++++ index.html | 2 ++ main.js | 6 ++++++ test/.gitignore | 43 +++++++++++++++++++++++++++++++++++++++++ test/test_calculator.js | 26 ++++++++++++++++++++++++- 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 Sinon.js.js create mode 100644 test/.gitignore diff --git a/Sinon.js.js b/Sinon.js.js new file mode 100644 index 0000000..1b2c837 --- /dev/null +++ b/Sinon.js.js @@ -0,0 +1,25 @@ + var test = require('unit.js'); + + function once(fn) { + var returnValue; + var called = false; + return function() { + if (!called) { + called = true; + returnValue = fn.apply(this, arguments); + } + return returnValue; + }; +}; +var jQuery = { + ajax: function() {} +}; +function getTodos(listId, callback) { + jQuery.ajax({ + url: '/todo/' + listId + '/items', + success: function(data) { + // Node-style CPS: callback(err, data) + callback(null, data); + } + }); +} \ No newline at end of file diff --git a/calculator.js b/calculator.js index caf34db..90e04d6 100644 --- a/calculator.js +++ b/calculator.js @@ -11,5 +11,16 @@ function substract(num1, num2){ return num1 - num2; } +function multiplicate(num1, num2){ + return num1 * num2; +} + +function divide(num1, num2){ + return num1 / num2; +} + module.exports.add = add; +module.exports.substract = substract; +module.exports.multiplicate = multiplicate; +module.exports.divide = divide; module.exports.isNumber = isNumber; diff --git a/index.html b/index.html index cc6a9d9..9a3a6f6 100644 --- a/index.html +++ b/index.html @@ -22,6 +22,8 @@

Silly Calculator

=
diff --git a/main.js b/main.js index 957a234..f1e4457 100644 --- a/main.js +++ b/main.js @@ -16,6 +16,12 @@ window.onload = function(){ else if (operator == "substract"){ document.getElementById('ans').value = substract(num1, num2); } + else if (operator == "multiplicate"){ + document.getElementById('ans').value = multiplicate(num1, num2); + } + else if (operator == "divide"){ + document.getElementById('ans').value = divide(num1, num2); + } else { alert("Bad operator!") } diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..96374c4 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,43 @@ +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# ========================= +# Operating System Files +# ========================= + +# OSX +# ========================= + +.DS_Store +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk diff --git a/test/test_calculator.js b/test/test_calculator.js index 13f6205..e83c231 100644 --- a/test/test_calculator.js +++ b/test/test_calculator.js @@ -1,10 +1,34 @@ var assert = require('assert'); var cal = require('../calculator.js') + describe('Calculator', function(){ describe('add', function(){ it('add', function(){ assert.equal('2', cal.add(1, 1)); }) }) -}) + describe('substract', function(){ + it('substract', function(){ + assert.equal('0', cal.substract(1, 1)); + }) + }) + describe('multiplicate', function(){ + it('multiplicate', function(){ + assert.equal('1', cal.multiplicate(1, 1)); + }) + }) + describe('divide', function(){ + it('divide', function(){ + assert.equal('1', cal.divide(1, 1)); + }) + }) + describe('returnvalue', function(){ + it("returns the return value from the original function", function () { + var callback = sinon.stub().returns(42); + var proxy = once(callback); + assert.equals(proxy(), 42); + }) + }) +}); +