Added Jest
This commit is contained in:
		
							parent
							
								
									bbdfafe5d4
								
							
						
					
					
						commit
						34731c04f4
					
				| 
						 | 
				
			
			@ -1,5 +1,15 @@
 | 
			
		|||
const sumAll = function() {
 | 
			
		||||
 | 
			
		||||
const sumAll = function (numStart, numEnd) {
 | 
			
		||||
  // final sum variable
 | 
			
		||||
  let sum = 0;
 | 
			
		||||
  if (numStart < 0 || numEnd < 0 || typeof numStart != "number" || typeof numEnd != "number") {
 | 
			
		||||
    return "ERROR";
 | 
			
		||||
  } else if (numStart > numEnd) {
 | 
			
		||||
    [numStart, numEnd] = [numEnd, numStart];
 | 
			
		||||
  }
 | 
			
		||||
  for (let i = numStart; i <= numEnd; i++) {
 | 
			
		||||
    sum += i;
 | 
			
		||||
  }
 | 
			
		||||
  return sum;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports = sumAll;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,22 +1,22 @@
 | 
			
		|||
const sumAll = require('./sumAll')
 | 
			
		||||
const sumAll = require("./sumAll");
 | 
			
		||||
 | 
			
		||||
describe('sumAll', () => {
 | 
			
		||||
  test('sums numbers within the range', () => {
 | 
			
		||||
describe("sumAll", () => {
 | 
			
		||||
  test("sums numbers within the range", () => {
 | 
			
		||||
    expect(sumAll(1, 4)).toEqual(10);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with large numbers', () => {
 | 
			
		||||
  test("works with large numbers", () => {
 | 
			
		||||
    expect(sumAll(1, 4000)).toEqual(8002000);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with larger number first', () => {
 | 
			
		||||
  test("works with larger number first", () => {
 | 
			
		||||
    expect(sumAll(123, 1)).toEqual(7626);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('returns ERROR with negative numbers', () => {
 | 
			
		||||
    expect(sumAll(-10, 4)).toEqual('ERROR');
 | 
			
		||||
  test("returns ERROR with negative numbers", () => {
 | 
			
		||||
    expect(sumAll(-10, 4)).toEqual("ERROR");
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('returns ERROR with non-number parameters', () => {
 | 
			
		||||
    expect(sumAll(10, "90")).toEqual('ERROR');
 | 
			
		||||
  test("returns ERROR with non-number parameters", () => {
 | 
			
		||||
    expect(sumAll(10, "90")).toEqual("ERROR");
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('returns ERROR with non-number parameters', () => {
 | 
			
		||||
    expect(sumAll(10, [90, 1])).toEqual('ERROR');
 | 
			
		||||
  test("returns ERROR with non-number parameters", () => {
 | 
			
		||||
    expect(sumAll(10, [90, 1])).toEqual("ERROR");
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue