From 96197e49645ee9ae88978e0123faa0d8a35b2a6b Mon Sep 17 00:00:00 2001 From: ayobamiu Date: Sat, 30 Aug 2025 08:06:33 -0700 Subject: [PATCH 01/12] test calculator pr --- src/utils/calculator.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/utils/calculator.ts diff --git a/src/utils/calculator.ts b/src/utils/calculator.ts new file mode 100644 index 0000000..152113a --- /dev/null +++ b/src/utils/calculator.ts @@ -0,0 +1,8 @@ +// src/utils/calculator.ts +export function add(a: number, b: number): number { + return a + b; +} + +export function multiply(a: number, b: number): number { + return a * b; +} \ No newline at end of file From 65079f9c1ed986c73cdb19a38365ebb4fbf11072 Mon Sep 17 00:00:00 2001 From: ayobamiu Date: Sat, 30 Aug 2025 08:15:55 -0700 Subject: [PATCH 02/12] Add division function to calculator utility --- src/utils/calculator.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/calculator.ts b/src/utils/calculator.ts index 152113a..5716ebb 100644 --- a/src/utils/calculator.ts +++ b/src/utils/calculator.ts @@ -5,4 +5,8 @@ export function add(a: number, b: number): number { export function multiply(a: number, b: number): number { return a * b; +} + +export function divide(a: number, b: number): number { + return a / b; } \ No newline at end of file From 3e2bc41f467e39d449e549d3f714846ec2c92193 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 30 Aug 2025 15:59:53 +0000 Subject: [PATCH 03/12] Add auto-generated tests for src/utils/calculator.ts --- src/utils/__tests__/calculator.test.ts | 62 ++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/utils/__tests__/calculator.test.ts diff --git a/src/utils/__tests__/calculator.test.ts b/src/utils/__tests__/calculator.test.ts new file mode 100644 index 0000000..ed925dd --- /dev/null +++ b/src/utils/__tests__/calculator.test.ts @@ -0,0 +1,62 @@ +```js +// tests/calculator.test.ts +import { add, multiply, divide } from '../src/utils/calculator'; + +describe('add function', () => { + test('should return the sum of two positive numbers', () => { + expect(add(3, 5)).toBe(8); + }); + + test('should return the sum of a positive and a negative number', () => { + expect(add(10, -5)).toBe(5); + }); + + test('should return the sum of two negative numbers', () => { + expect(add(-3, -5)).toBe(-8); + }); + + test('should return the sum when one of the numbers is zero', () => { + expect(add(0, 5)).toBe(5); + }); +}); + +describe('multiply function', () => { + test('should return the product of two positive numbers', () => { + expect(multiply(3, 5)).toBe(15); + }); + + test('should return the product of a positive and a negative number', () => { + expect(multiply(10, -5)).toBe(-50); + }); + + test('should return the product of two negative numbers', () => { + expect(multiply(-3, -5)).toBe(15); + }); + + test('should return zero when one of the numbers is zero', () => { + expect(multiply(0, 5)).toBe(0); + }); +}); + +describe('divide function', () => { + test('should return the quotient of two positive numbers', () => { + expect(divide(10, 2)).toBe(5); + }); + + test('should return the quotient of a positive and a negative number', () => { + expect(divide(10, -2)).toBe(-5); + }); + + test('should return the quotient of two negative numbers', () => { + expect(divide(-10, -2)).toBe(5); + }); + + test('should return zero when numerator is zero', () => { + expect(divide(0, 5)).toBe(0); + }); + + test('should throw an error when dividing by zero', () => { + expect(() => divide(10, 0)).toThrow(); + }); +}); +``` \ No newline at end of file From ba3ba02bab538a854aa6bcd3d44efcc06a59ad51 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 30 Aug 2025 16:43:31 +0000 Subject: [PATCH 04/12] Add auto-generated tests for src/utils/__tests__/calculator.test.ts --- .../__tests__/calculator.test.test.ts | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/utils/__tests__/__tests__/calculator.test.test.ts diff --git a/src/utils/__tests__/__tests__/calculator.test.test.ts b/src/utils/__tests__/__tests__/calculator.test.test.ts new file mode 100644 index 0000000..7770b6f --- /dev/null +++ b/src/utils/__tests__/__tests__/calculator.test.test.ts @@ -0,0 +1,74 @@ +```js +// tests/calculator.test.ts +import { add, multiply, divide } from '../src/utils/calculator'; + +describe('add function', () => { + test('should return the sum of two positive numbers', () => { + expect(add(3, 5)).toBe(8); + }); + + test('should return the sum of a positive and a negative number', () => { + expect(add(10, -5)).toBe(5); + }); + + test('should return the sum of two negative numbers', () => { + expect(add(-3, -5)).toBe(-8); + }); + + test('should return the sum when one of the numbers is zero', () => { + expect(add(0, 5)).toBe(5); + }); + + test('should return zero when both numbers are zero', () => { + expect(add(0, 0)).toBe(0); + }); +}); + +describe('multiply function', () => { + test('should return the product of two positive numbers', () => { + expect(multiply(3, 5)).toBe(15); + }); + + test('should return the product of a positive and a negative number', () => { + expect(multiply(10, -5)).toBe(-50); + }); + + test('should return the product of two negative numbers', () => { + expect(multiply(-3, -5)).toBe(15); + }); + + test('should return zero when one of the numbers is zero', () => { + expect(multiply(0, 5)).toBe(0); + }); + + test('should return zero when both numbers are zero', () => { + expect(multiply(0, 0)).toBe(0); + }); +}); + +describe('divide function', () => { + test('should return the quotient of two positive numbers', () => { + expect(divide(10, 2)).toBe(5); + }); + + test('should return the quotient of a positive and a negative number', () => { + expect(divide(10, -2)).toBe(-5); + }); + + test('should return the quotient of two negative numbers', () => { + expect(divide(-10, -2)).toBe(5); + }); + + test('should return zero when numerator is zero', () => { + expect(divide(0, 5)).toBe(0); + }); + + test('should throw an error when dividing by zero', () => { + expect(() => divide(10, 0)).toThrow('Cannot divide by zero'); + }); + + test('should handle division resulting in a fraction', () => { + expect(divide(7, 2)).toBeCloseTo(3.5); + }); +}); +``` \ No newline at end of file From 3eb20a8c9ee7be09e6707c723fa14f64dcd3ca96 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 30 Aug 2025 16:43:37 +0000 Subject: [PATCH 05/12] Add auto-generated tests for src/utils/calculator.ts --- src/utils/__tests__/calculator.test.ts | 84 +++++++++++++------------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/src/utils/__tests__/calculator.test.ts b/src/utils/__tests__/calculator.test.ts index ed925dd..98417db 100644 --- a/src/utils/__tests__/calculator.test.ts +++ b/src/utils/__tests__/calculator.test.ts @@ -2,61 +2,63 @@ // tests/calculator.test.ts import { add, multiply, divide } from '../src/utils/calculator'; -describe('add function', () => { - test('should return the sum of two positive numbers', () => { - expect(add(3, 5)).toBe(8); - }); +describe('Calculator', () => { + describe('add', () => { + it('should return the sum of two positive numbers', () => { + expect(add(2, 3)).toBe(5); + }); - test('should return the sum of a positive and a negative number', () => { - expect(add(10, -5)).toBe(5); - }); + it('should return the sum of a positive and a negative number', () => { + expect(add(5, -3)).toBe(2); + }); - test('should return the sum of two negative numbers', () => { - expect(add(-3, -5)).toBe(-8); - }); + it('should return the sum of two negative numbers', () => { + expect(add(-4, -6)).toBe(-10); + }); - test('should return the sum when one of the numbers is zero', () => { - expect(add(0, 5)).toBe(5); + it('should return the sum when adding zero', () => { + expect(add(0, 5)).toBe(5); + }); }); -}); -describe('multiply function', () => { - test('should return the product of two positive numbers', () => { - expect(multiply(3, 5)).toBe(15); - }); + describe('multiply', () => { + it('should return the product of two positive numbers', () => { + expect(multiply(4, 5)).toBe(20); + }); - test('should return the product of a positive and a negative number', () => { - expect(multiply(10, -5)).toBe(-50); - }); + it('should return the product of a positive and a negative number', () => { + expect(multiply(4, -3)).toBe(-12); + }); - test('should return the product of two negative numbers', () => { - expect(multiply(-3, -5)).toBe(15); - }); + it('should return the product of two negative numbers', () => { + expect(multiply(-2, -3)).toBe(6); + }); - test('should return zero when one of the numbers is zero', () => { - expect(multiply(0, 5)).toBe(0); + it('should return zero when multiplying by zero', () => { + expect(multiply(0, 5)).toBe(0); + }); }); -}); -describe('divide function', () => { - test('should return the quotient of two positive numbers', () => { - expect(divide(10, 2)).toBe(5); - }); + describe('divide', () => { + it('should return the quotient of two positive numbers', () => { + expect(divide(10, 2)).toBe(5); + }); - test('should return the quotient of a positive and a negative number', () => { - expect(divide(10, -2)).toBe(-5); - }); + it('should return the quotient of a positive and a negative number', () => { + expect(divide(10, -2)).toBe(-5); + }); - test('should return the quotient of two negative numbers', () => { - expect(divide(-10, -2)).toBe(5); - }); + it('should return the quotient of two negative numbers', () => { + expect(divide(-10, -2)).toBe(5); + }); - test('should return zero when numerator is zero', () => { - expect(divide(0, 5)).toBe(0); - }); + it('should return zero when the numerator is zero', () => { + expect(divide(0, 5)).toBe(0); + }); - test('should throw an error when dividing by zero', () => { - expect(() => divide(10, 0)).toThrow(); + it('should throw an error when dividing by zero', () => { + expect(() => divide(5, 0)).toThrow(); + }); }); }); ``` \ No newline at end of file From b3566f4a33c10bdcf8aa868566feced7dc21bc4b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 30 Aug 2025 17:04:07 +0000 Subject: [PATCH 06/12] Add auto-generated tests for src/utils/calculator.ts --- src/utils/__tests__/calculator.test.ts | 71 ++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/utils/__tests__/calculator.test.ts diff --git a/src/utils/__tests__/calculator.test.ts b/src/utils/__tests__/calculator.test.ts new file mode 100644 index 0000000..d056898 --- /dev/null +++ b/src/utils/__tests__/calculator.test.ts @@ -0,0 +1,71 @@ +// src/utils/__tests__/calculator.test.ts +import { add, multiply, divide } from '../calculator'; + +describe('Calculator Utility Functions', () => { + describe('add', () => { + it('should return the sum of two positive numbers', () => { + expect(add(2, 3)).toBe(5); + }); + + it('should return the sum of two negative numbers', () => { + expect(add(-2, -3)).toBe(-5); + }); + + it('should return the sum of a positive and a negative number', () => { + expect(add(2, -3)).toBe(-1); + }); + + it('should return the sum when one of the numbers is zero', () => { + expect(add(0, 5)).toBe(5); + expect(add(5, 0)).toBe(5); + }); + }); + + describe('multiply', () => { + it('should return the product of two positive numbers', () => { + expect(multiply(2, 3)).toBe(6); + }); + + it('should return the product of two negative numbers', () => { + expect(multiply(-2, -3)).toBe(6); + }); + + it('should return the product of a positive and a negative number', () => { + expect(multiply(2, -3)).toBe(-6); + }); + + it('should return zero when one of the numbers is zero', () => { + expect(multiply(0, 5)).toBe(0); + expect(multiply(5, 0)).toBe(0); + }); + }); + + describe('divide', () => { + it('should return the quotient of two positive numbers', () => { + expect(divide(6, 3)).toBe(2); + }); + + it('should return the quotient of two negative numbers', () => { + expect(divide(-6, -3)).toBe(2); + }); + + it('should return the quotient of a positive and a negative number', () => { + expect(divide(6, -3)).toBe(-2); + }); + + it('should handle division by one correctly', () => { + expect(divide(5, 1)).toBe(5); + }); + + it('should handle division of zero correctly', () => { + expect(divide(0, 5)).toBe(0); + }); + + it('should throw an error when dividing by zero', () => { + expect(() => divide(5, 0)).toThrowError('Cannot divide by zero'); + }); + }); +}); +``` + +Note: The original code does not handle division by zero, so the test case `it('should throw an error when dividing by zero', () => { ... })` will fail unless the original code is modified to throw an error in such cases. However, as per your instructions, I have not changed the original code logic. \ No newline at end of file From 1c5b47f25bade24bf15156d399a41717ab0443a9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 31 Aug 2025 06:00:48 +0000 Subject: [PATCH 07/12] Add auto-generated tests for src/utils/__tests__/calculator.test.ts --- .../__tests__/calculator.test.test.ts | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/utils/__tests__/__tests__/calculator.test.test.ts diff --git a/src/utils/__tests__/__tests__/calculator.test.test.ts b/src/utils/__tests__/__tests__/calculator.test.test.ts new file mode 100644 index 0000000..6d244bd --- /dev/null +++ b/src/utils/__tests__/__tests__/calculator.test.test.ts @@ -0,0 +1,67 @@ +import { add, multiply, divide } from '../calculator'; + +describe('Calculator Utility Functions', () => { + describe('add', () => { + it('should return the sum of two positive numbers', () => { + expect(add(2, 3)).toBe(5); + }); + + it('should return the sum of two negative numbers', () => { + expect(add(-2, -3)).toBe(-5); + }); + + it('should return the sum of a positive and a negative number', () => { + expect(add(2, -3)).toBe(-1); + }); + + it('should return the sum when one of the numbers is zero', () => { + expect(add(0, 5)).toBe(5); + expect(add(5, 0)).toBe(5); + }); + }); + + describe('multiply', () => { + it('should return the product of two positive numbers', () => { + expect(multiply(2, 3)).toBe(6); + }); + + it('should return the product of two negative numbers', () => { + expect(multiply(-2, -3)).toBe(6); + }); + + it('should return the product of a positive and a negative number', () => { + expect(multiply(2, -3)).toBe(-6); + }); + + it('should return zero when one of the numbers is zero', () => { + expect(multiply(0, 5)).toBe(0); + expect(multiply(5, 0)).toBe(0); + }); + }); + + describe('divide', () => { + it('should return the quotient of two positive numbers', () => { + expect(divide(6, 3)).toBe(2); + }); + + it('should return the quotient of two negative numbers', () => { + expect(divide(-6, -3)).toBe(2); + }); + + it('should return the quotient of a positive and a negative number', () => { + expect(divide(6, -3)).toBe(-2); + }); + + it('should handle division by one correctly', () => { + expect(divide(5, 1)).toBe(5); + }); + + it('should handle division of zero correctly', () => { + expect(divide(0, 5)).toBe(0); + }); + + it('should throw an error when dividing by zero', () => { + expect(() => divide(5, 0)).toThrowError('Cannot divide by zero'); + }); + }); +}); \ No newline at end of file From 64f9ec7ca640b165c9b6a554be6ce62455efb4e7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 31 Aug 2025 06:00:54 +0000 Subject: [PATCH 08/12] Add auto-generated tests for src/utils/calculator.ts --- src/utils/__tests__/calculator.test.ts | 46 ++++++++++---------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/utils/__tests__/calculator.test.ts b/src/utils/__tests__/calculator.test.ts index d056898..6035a78 100644 --- a/src/utils/__tests__/calculator.test.ts +++ b/src/utils/__tests__/calculator.test.ts @@ -1,71 +1,61 @@ -// src/utils/__tests__/calculator.test.ts import { add, multiply, divide } from '../calculator'; -describe('Calculator Utility Functions', () => { +describe('Calculator functions', () => { describe('add', () => { it('should return the sum of two positive numbers', () => { - expect(add(2, 3)).toBe(5); + expect(add(1, 2)).toBe(3); }); - it('should return the sum of two negative numbers', () => { - expect(add(-2, -3)).toBe(-5); + it('should return the sum of a positive and a negative number', () => { + expect(add(5, -3)).toBe(2); }); - it('should return the sum of a positive and a negative number', () => { - expect(add(2, -3)).toBe(-1); + it('should return the sum of two negative numbers', () => { + expect(add(-4, -6)).toBe(-10); }); it('should return the sum when one of the numbers is zero', () => { expect(add(0, 5)).toBe(5); - expect(add(5, 0)).toBe(5); }); }); describe('multiply', () => { it('should return the product of two positive numbers', () => { - expect(multiply(2, 3)).toBe(6); + expect(multiply(3, 4)).toBe(12); }); - it('should return the product of two negative numbers', () => { - expect(multiply(-2, -3)).toBe(6); + it('should return the product of a positive and a negative number', () => { + expect(multiply(-2, 3)).toBe(-6); }); - it('should return the product of a positive and a negative number', () => { - expect(multiply(2, -3)).toBe(-6); + it('should return the product of two negative numbers', () => { + expect(multiply(-3, -3)).toBe(9); }); it('should return zero when one of the numbers is zero', () => { - expect(multiply(0, 5)).toBe(0); - expect(multiply(5, 0)).toBe(0); + expect(multiply(0, 7)).toBe(0); }); }); describe('divide', () => { it('should return the quotient of two positive numbers', () => { - expect(divide(6, 3)).toBe(2); - }); - - it('should return the quotient of two negative numbers', () => { - expect(divide(-6, -3)).toBe(2); + expect(divide(10, 2)).toBe(5); }); it('should return the quotient of a positive and a negative number', () => { - expect(divide(6, -3)).toBe(-2); + expect(divide(-9, 3)).toBe(-3); }); - it('should handle division by one correctly', () => { - expect(divide(5, 1)).toBe(5); + it('should return the quotient of two negative numbers', () => { + expect(divide(-8, -2)).toBe(4); }); - it('should handle division of zero correctly', () => { + it('should return zero when the numerator is zero', () => { expect(divide(0, 5)).toBe(0); }); it('should throw an error when dividing by zero', () => { - expect(() => divide(5, 0)).toThrowError('Cannot divide by zero'); + expect(() => divide(5, 0)).toThrowError(); }); }); }); -``` - -Note: The original code does not handle division by zero, so the test case `it('should throw an error when dividing by zero', () => { ... })` will fail unless the original code is modified to throw an error in such cases. However, as per your instructions, I have not changed the original code logic. \ No newline at end of file From b5884b4c874fb758aed5c0381c773a26c12839d8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 31 Aug 2025 18:49:42 +0000 Subject: [PATCH 09/12] Add auto-generated tests for src/utils/__tests__/calculator.test.ts --- .../__tests__/calculator.test.test.ts | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/utils/__tests__/__tests__/calculator.test.test.ts diff --git a/src/utils/__tests__/__tests__/calculator.test.test.ts b/src/utils/__tests__/__tests__/calculator.test.test.ts new file mode 100644 index 0000000..6035a78 --- /dev/null +++ b/src/utils/__tests__/__tests__/calculator.test.test.ts @@ -0,0 +1,61 @@ +import { add, multiply, divide } from '../calculator'; + +describe('Calculator functions', () => { + describe('add', () => { + it('should return the sum of two positive numbers', () => { + expect(add(1, 2)).toBe(3); + }); + + it('should return the sum of a positive and a negative number', () => { + expect(add(5, -3)).toBe(2); + }); + + it('should return the sum of two negative numbers', () => { + expect(add(-4, -6)).toBe(-10); + }); + + it('should return the sum when one of the numbers is zero', () => { + expect(add(0, 5)).toBe(5); + }); + }); + + describe('multiply', () => { + it('should return the product of two positive numbers', () => { + expect(multiply(3, 4)).toBe(12); + }); + + it('should return the product of a positive and a negative number', () => { + expect(multiply(-2, 3)).toBe(-6); + }); + + it('should return the product of two negative numbers', () => { + expect(multiply(-3, -3)).toBe(9); + }); + + it('should return zero when one of the numbers is zero', () => { + expect(multiply(0, 7)).toBe(0); + }); + }); + + describe('divide', () => { + it('should return the quotient of two positive numbers', () => { + expect(divide(10, 2)).toBe(5); + }); + + it('should return the quotient of a positive and a negative number', () => { + expect(divide(-9, 3)).toBe(-3); + }); + + it('should return the quotient of two negative numbers', () => { + expect(divide(-8, -2)).toBe(4); + }); + + it('should return zero when the numerator is zero', () => { + expect(divide(0, 5)).toBe(0); + }); + + it('should throw an error when dividing by zero', () => { + expect(() => divide(5, 0)).toThrowError(); + }); + }); +}); From 6c4c6e0f7b5087d804672fe5cff6f84588ceae7a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 31 Aug 2025 18:49:52 +0000 Subject: [PATCH 10/12] Add auto-generated tests for src/utils/calculator.ts --- src/utils/__tests__/calculator.test.ts | 34 ++++++++++++-------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/utils/__tests__/calculator.test.ts b/src/utils/__tests__/calculator.test.ts index 6035a78..c2ce054 100644 --- a/src/utils/__tests__/calculator.test.ts +++ b/src/utils/__tests__/calculator.test.ts @@ -1,9 +1,9 @@ import { add, multiply, divide } from '../calculator'; -describe('Calculator functions', () => { +describe('Calculator Utility Functions', () => { describe('add', () => { it('should return the sum of two positive numbers', () => { - expect(add(1, 2)).toBe(3); + expect(add(2, 3)).toBe(5); }); it('should return the sum of a positive and a negative number', () => { @@ -11,51 +11,47 @@ describe('Calculator functions', () => { }); it('should return the sum of two negative numbers', () => { - expect(add(-4, -6)).toBe(-10); + expect(add(-2, -3)).toBe(-5); }); - it('should return the sum when one of the numbers is zero', () => { - expect(add(0, 5)).toBe(5); + it('should return 0 when adding 0 and 0', () => { + expect(add(0, 0)).toBe(0); }); }); describe('multiply', () => { it('should return the product of two positive numbers', () => { - expect(multiply(3, 4)).toBe(12); + expect(multiply(2, 3)).toBe(6); }); it('should return the product of a positive and a negative number', () => { - expect(multiply(-2, 3)).toBe(-6); + expect(multiply(5, -3)).toBe(-15); }); it('should return the product of two negative numbers', () => { - expect(multiply(-3, -3)).toBe(9); + expect(multiply(-2, -3)).toBe(6); }); - it('should return zero when one of the numbers is zero', () => { - expect(multiply(0, 7)).toBe(0); + it('should return 0 when multiplying any number by 0', () => { + expect(multiply(5, 0)).toBe(0); }); }); describe('divide', () => { it('should return the quotient of two positive numbers', () => { - expect(divide(10, 2)).toBe(5); + expect(divide(6, 3)).toBe(2); }); it('should return the quotient of a positive and a negative number', () => { - expect(divide(-9, 3)).toBe(-3); + expect(divide(6, -3)).toBe(-2); }); it('should return the quotient of two negative numbers', () => { - expect(divide(-8, -2)).toBe(4); - }); - - it('should return zero when the numerator is zero', () => { - expect(divide(0, 5)).toBe(0); + expect(divide(-6, -3)).toBe(2); }); it('should throw an error when dividing by zero', () => { - expect(() => divide(5, 0)).toThrowError(); + expect(() => divide(6, 0)).toThrowError('Cannot divide by zero'); }); }); -}); +}); \ No newline at end of file From 17642e337a45d1a2c5d0c6981fe0e4309dae7e95 Mon Sep 17 00:00:00 2001 From: ayobamiu Date: Sun, 31 Aug 2025 12:16:25 -0700 Subject: [PATCH 11/12] Update calculator utility with subtraction function and clean up test files - Added a new `subtract` function to the calculator utility. - Removed redundant test file `calculator.test.test.ts`. --- .../__tests__/calculator.test.test.ts | 61 ------------------- src/utils/__tests__/calculator.test.ts | 4 -- src/utils/calculator.ts | 4 ++ 3 files changed, 4 insertions(+), 65 deletions(-) delete mode 100644 src/utils/__tests__/__tests__/calculator.test.test.ts diff --git a/src/utils/__tests__/__tests__/calculator.test.test.ts b/src/utils/__tests__/__tests__/calculator.test.test.ts deleted file mode 100644 index 6035a78..0000000 --- a/src/utils/__tests__/__tests__/calculator.test.test.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { add, multiply, divide } from '../calculator'; - -describe('Calculator functions', () => { - describe('add', () => { - it('should return the sum of two positive numbers', () => { - expect(add(1, 2)).toBe(3); - }); - - it('should return the sum of a positive and a negative number', () => { - expect(add(5, -3)).toBe(2); - }); - - it('should return the sum of two negative numbers', () => { - expect(add(-4, -6)).toBe(-10); - }); - - it('should return the sum when one of the numbers is zero', () => { - expect(add(0, 5)).toBe(5); - }); - }); - - describe('multiply', () => { - it('should return the product of two positive numbers', () => { - expect(multiply(3, 4)).toBe(12); - }); - - it('should return the product of a positive and a negative number', () => { - expect(multiply(-2, 3)).toBe(-6); - }); - - it('should return the product of two negative numbers', () => { - expect(multiply(-3, -3)).toBe(9); - }); - - it('should return zero when one of the numbers is zero', () => { - expect(multiply(0, 7)).toBe(0); - }); - }); - - describe('divide', () => { - it('should return the quotient of two positive numbers', () => { - expect(divide(10, 2)).toBe(5); - }); - - it('should return the quotient of a positive and a negative number', () => { - expect(divide(-9, 3)).toBe(-3); - }); - - it('should return the quotient of two negative numbers', () => { - expect(divide(-8, -2)).toBe(4); - }); - - it('should return zero when the numerator is zero', () => { - expect(divide(0, 5)).toBe(0); - }); - - it('should throw an error when dividing by zero', () => { - expect(() => divide(5, 0)).toThrowError(); - }); - }); -}); diff --git a/src/utils/__tests__/calculator.test.ts b/src/utils/__tests__/calculator.test.ts index c2ce054..3d9dae5 100644 --- a/src/utils/__tests__/calculator.test.ts +++ b/src/utils/__tests__/calculator.test.ts @@ -49,9 +49,5 @@ describe('Calculator Utility Functions', () => { it('should return the quotient of two negative numbers', () => { expect(divide(-6, -3)).toBe(2); }); - - it('should throw an error when dividing by zero', () => { - expect(() => divide(6, 0)).toThrowError('Cannot divide by zero'); - }); }); }); \ No newline at end of file diff --git a/src/utils/calculator.ts b/src/utils/calculator.ts index 5716ebb..891971b 100644 --- a/src/utils/calculator.ts +++ b/src/utils/calculator.ts @@ -9,4 +9,8 @@ export function multiply(a: number, b: number): number { export function divide(a: number, b: number): number { return a / b; +} + +export function subtract(a: number, b: number): number { + return a - b; } \ No newline at end of file From 5c899ab4020bea6ad2afb6b2921b79212ffb9115 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 31 Aug 2025 19:16:44 +0000 Subject: [PATCH 12/12] Add auto-generated tests for src/utils/calculator.ts --- src/utils/__tests__/calculator.test.ts | 44 +++++++++++++++----------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/utils/__tests__/calculator.test.ts b/src/utils/__tests__/calculator.test.ts index 3d9dae5..88599e5 100644 --- a/src/utils/__tests__/calculator.test.ts +++ b/src/utils/__tests__/calculator.test.ts @@ -1,43 +1,35 @@ -import { add, multiply, divide } from '../calculator'; +import { add, multiply, divide, subtract } from '../calculator'; -describe('Calculator Utility Functions', () => { - describe('add', () => { +describe('Calculator Functions', () => { + describe('add()', () => { it('should return the sum of two positive numbers', () => { - expect(add(2, 3)).toBe(5); + expect(add(1, 2)).toBe(3); }); it('should return the sum of a positive and a negative number', () => { - expect(add(5, -3)).toBe(2); + expect(add(1, -2)).toBe(-1); }); it('should return the sum of two negative numbers', () => { - expect(add(-2, -3)).toBe(-5); - }); - - it('should return 0 when adding 0 and 0', () => { - expect(add(0, 0)).toBe(0); + expect(add(-1, -2)).toBe(-3); }); }); - describe('multiply', () => { + describe('multiply()', () => { it('should return the product of two positive numbers', () => { expect(multiply(2, 3)).toBe(6); }); it('should return the product of a positive and a negative number', () => { - expect(multiply(5, -3)).toBe(-15); + expect(multiply(2, -3)).toBe(-6); }); it('should return the product of two negative numbers', () => { expect(multiply(-2, -3)).toBe(6); }); - - it('should return 0 when multiplying any number by 0', () => { - expect(multiply(5, 0)).toBe(0); - }); }); - describe('divide', () => { + describe('divide()', () => { it('should return the quotient of two positive numbers', () => { expect(divide(6, 3)).toBe(2); }); @@ -46,8 +38,22 @@ describe('Calculator Utility Functions', () => { expect(divide(6, -3)).toBe(-2); }); - it('should return the quotient of two negative numbers', () => { - expect(divide(-6, -3)).toBe(2); + it('should handle division by zero', () => { + expect(() => divide(6, 0)).toThrowError('Cannot divide by zero'); + }); + }); + + describe('subtract()', () => { + it('should return the difference of two positive numbers', () => { + expect(subtract(5, 3)).toBe(2); + }); + + it('should return the difference of a positive and a negative number', () => { + expect(subtract(5, -3)).toBe(8); + }); + + it('should return the difference of two negative numbers', () => { + expect(subtract(-5, -3)).toBe(-2); }); }); }); \ No newline at end of file