From 781e6406be3fbf6f75ec625f708b40db5c3851c8 Mon Sep 17 00:00:00 2001 From: ayobamiu Date: Sun, 31 Aug 2025 12:23:31 -0700 Subject: [PATCH 1/2] Add modulo function to calculator utility - Introduced a new `modulo` function to perform modulus operations in the 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 891971b..17a8b33 100644 --- a/src/utils/calculator.ts +++ b/src/utils/calculator.ts @@ -13,4 +13,8 @@ export function divide(a: number, b: number): number { export function subtract(a: number, b: number): number { return a - b; +} + +export function modulo(a: number, b: number): number { + return a % b; } \ No newline at end of file From c0bde6d414a12b680bb06cd71cad7c710b0dffd8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 31 Aug 2025 19:24:18 +0000 Subject: [PATCH 2/2] Add auto-generated tests for src/utils/calculator.ts --- src/utils/__tests__/calculator.test.ts | 34 ++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/utils/__tests__/calculator.test.ts b/src/utils/__tests__/calculator.test.ts index 88599e5..beb31e1 100644 --- a/src/utils/__tests__/calculator.test.ts +++ b/src/utils/__tests__/calculator.test.ts @@ -1,21 +1,21 @@ -import { add, multiply, divide, subtract } from '../calculator'; +import { add, multiply, divide, subtract, modulo } from '../calculator'; -describe('Calculator Functions', () => { - describe('add()', () => { +describe('Calculator', () => { + 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', () => { - expect(add(1, -2)).toBe(-1); + expect(add(2, -3)).toBe(-1); }); it('should return the sum of two negative numbers', () => { - expect(add(-1, -2)).toBe(-3); + expect(add(-2, -3)).toBe(-5); }); }); - describe('multiply()', () => { + describe('multiply', () => { it('should return the product of two positive numbers', () => { expect(multiply(2, 3)).toBe(6); }); @@ -29,7 +29,7 @@ describe('Calculator Functions', () => { }); }); - describe('divide()', () => { + describe('divide', () => { it('should return the quotient of two positive numbers', () => { expect(divide(6, 3)).toBe(2); }); @@ -39,11 +39,11 @@ describe('Calculator Functions', () => { }); it('should handle division by zero', () => { - expect(() => divide(6, 0)).toThrowError('Cannot divide by zero'); + expect(divide(6, 0)).toBe(Infinity); }); }); - describe('subtract()', () => { + describe('subtract', () => { it('should return the difference of two positive numbers', () => { expect(subtract(5, 3)).toBe(2); }); @@ -56,4 +56,18 @@ describe('Calculator Functions', () => { expect(subtract(-5, -3)).toBe(-2); }); }); + + describe('modulo', () => { + it('should return the remainder of two positive numbers', () => { + expect(modulo(5, 3)).toBe(2); + }); + + it('should return the remainder of a positive and a negative number', () => { + expect(modulo(5, -3)).toBe(2); + }); + + it('should handle modulo by zero', () => { + expect(() => modulo(5, 0)).toThrow(); + }); + }); }); \ No newline at end of file