From be91926949d9c109568a16c7facaa5f2ebe50cf6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 16:38:13 +0000 Subject: [PATCH 1/2] Initial plan From 8662ec46e0dd22f3934485b3a743e8c01992e898 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 16:42:40 +0000 Subject: [PATCH 2/2] Add modulo operator and comprehensive tests Co-authored-by: haslam93 <36418598+haslam93@users.noreply.github.com> --- api/controller.js | 1 + test/arithmetic.test.js | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/api/controller.js b/api/controller.js index 949731c..adf878a 100644 --- a/api/controller.js +++ b/api/controller.js @@ -16,6 +16,7 @@ exports.calculate = function(req, res) { 'subtract': function(a, b) { return a - b }, 'multiply': function(a, b) { return a * b }, 'divide': function(a, b) { return a / b }, + 'modulo': function(a, b) { return a % b }, }; if (!req.query.operation) { diff --git a/test/arithmetic.test.js b/test/arithmetic.test.js index deded48..b4eca1a 100644 --- a/test/arithmetic.test.js +++ b/test/arithmetic.test.js @@ -95,6 +95,16 @@ describe('Arithmetic', function () { // TODO: Challenge #1 + describe('Subtraction', function () { + it('subtracts a positive integer from a positive integer', function (done) { + request.get('/arithmetic?operation=subtract&operand1=42&operand2=21') + .expect(200) + .end(function (err, res) { + expect(res.body).to.eql({ result: 21 }); + done(); + }); + }); + }); describe('Multiplication', function () { it('multiplies two positive integers', function (done) { @@ -205,4 +215,47 @@ describe('Arithmetic', function () { }); }); }); + + describe('Modulo', function () { + it('computes modulo of two positive integers', function (done) { + request.get('/arithmetic?operation=modulo&operand1=42&operand2=5') + .expect(200) + .end(function (err, res) { + expect(res.body).to.eql({ result: 2 }); + done(); + }); + }); + it('computes modulo with a result of zero', function (done) { + request.get('/arithmetic?operation=modulo&operand1=42&operand2=21') + .expect(200) + .end(function (err, res) { + expect(res.body).to.eql({ result: 0 }); + done(); + }); + }); + it('computes modulo of a negative integer', function (done) { + request.get('/arithmetic?operation=modulo&operand1=-42&operand2=5') + .expect(200) + .end(function (err, res) { + expect(res.body).to.eql({ result: -2 }); + done(); + }); + }); + it('computes modulo with floating point numbers', function (done) { + request.get('/arithmetic?operation=modulo&operand1=5.5&operand2=2') + .expect(200) + .end(function (err, res) { + expect(res.body).to.eql({ result: 1.5 }); + done(); + }); + }); + it('computes modulo where divisor is larger than dividend', function (done) { + request.get('/arithmetic?operation=modulo&operand1=5&operand2=42') + .expect(200) + .end(function (err, res) { + expect(res.body).to.eql({ result: 5 }); + done(); + }); + }); + }); });