From 760b6a5fe91d1386385bb944839474b8c49984d0 Mon Sep 17 00:00:00 2001 From: henryma68 Date: Fri, 30 Oct 2015 23:53:52 +0800 Subject: [PATCH] ver1 --- calculator.js | 2 +- test/test_calculator.js | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/calculator.js b/calculator.js index caf34db..081b0ef 100644 --- a/calculator.js +++ b/calculator.js @@ -1,5 +1,5 @@ function isNumber(numStr){ - var re = /^[0-9\.]+$/; + var re = /^[+-]?[0-9]+\.{0,1}[0-9]*$/; return re.test(numStr); } diff --git a/test/test_calculator.js b/test/test_calculator.js index 13f6205..5877a9d 100644 --- a/test/test_calculator.js +++ b/test/test_calculator.js @@ -1,10 +1,17 @@ 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('Calculator', function () { + describe('add_positive', function () { + it('add', function () { + assert.equal('2', cal.add(1, 1)); + + }) + }) + describe('add_nagative', function () { + it('add', function () { + assert.equal('-2', cal.add(-1, -1)); + + }) }) - }) })