|
| 1 | +var should = require('should'); |
| 2 | +var vm = require('vm'); |
| 3 | +var fs = require('fs'); |
| 4 | +var filename = __filename.replace(/\.test\.js$/, '.js'); |
| 5 | +vm.runInThisContext(fs.readFileSync(filename), filename); |
| 6 | + |
| 7 | + |
| 8 | +describe('sumNumbers', function() { |
| 9 | + it('should exist', function(){ |
| 10 | + should.exist(sumNumbers); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should be a function', function() { |
| 14 | + sumNumbers.should.be.a.Function; |
| 15 | + }); |
| 16 | + |
| 17 | + it('should return a Number', function() { |
| 18 | + var result = sumNumbers(5); |
| 19 | + should.exist(result); |
| 20 | + result.should.be.an.instanceof(Number); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should return zero if no input provided', function() { |
| 24 | + var result = sumNumbers(); |
| 25 | + result.should.be.eql(0); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should return one if input is 1', function(){ |
| 29 | + var result = sumNumbers(1); |
| 30 | + result.should.be.eql(1); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should have the right answer', function(){ |
| 34 | + var result = sumNumbers(5); |
| 35 | + result.should.be.eql(15); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should handle large numbers', function() { |
| 39 | + var result = sumNumbers(15); |
| 40 | + result.should.be.eql(120); |
| 41 | + }); |
| 42 | + |
| 43 | +}); |
0 commit comments