diff --git a/README.md b/README.md index daf0a1a..f7da693 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # INFO909 : Intégration continue - Déploiement continu +## Kubasik Tom +## Bollon Ration ## A faire en amont du cours du 12 janvier diff --git a/app/functions.js b/app/functions.js index 46b9fce..1ae689a 100644 --- a/app/functions.js +++ b/app/functions.js @@ -8,4 +8,15 @@ exports.add = (num1, num2) => { exports.mul = (num1, num2) => { return (num1 * num2).toString(); -} \ No newline at end of file +} + +exports.div = (num1, num2) => { + if(num2 == 0) { + return "NaN" + } + return (num1 / num2).toString(); +} + +exports.pow = (num1, num2) => { + return (Math.pow(num1, num2)).toString(); +} diff --git a/app/server.js b/app/server.js index 8ca7202..a64b7a8 100644 --- a/app/server.js +++ b/app/server.js @@ -1,5 +1,5 @@ const express = require('express'); -const { sub, mul, add } = require("./functions"); +const { sub, mul, add, div } = require("./functions"); // Constants const PORT = 8080; @@ -35,5 +35,12 @@ app.post('/mul', (req, res) => { return res.status(200).send(total); }) +app.post('/div', (req, res) => { + var num1 = parseFloat(req.body.num1); + var num2 = parseFloat(req.body.num2); + var total = div(num1, num2); + return res.status(200).send(total); +}) + app.listen(PORT, HOST); console.log(`Running on http://${HOST}:${PORT}`); diff --git a/app/test/unit.test.js b/app/test/unit.test.js index 83cf214..e690bff 100644 --- a/app/test/unit.test.js +++ b/app/test/unit.test.js @@ -1,13 +1,23 @@ const assert = require('assert'); -const { sub, mul, add } = require("../functions"); +const { sub, mul, add, div, pow } = require("../functions"); describe('Tests unitaire', () => { it('should return -3', () => { - assert.equal(sub(2, 5), -3); + assert.equal(sub(2, 5), '-3'); }); it('should return 7', () => { - assert.equal(add(2, 5), 7); + assert.equal(add(2, 5), '7'); }); it('should return 12', () => { - assert.equal(mul(6, 2), 12); + assert.equal(mul(6, 2), '12'); + }); + it('should return 6', () => { + assert.equal(div(12, 2), '6'); + }); + it('should return NaN', () => { + assert.equal(div(6, 0), 'NaN'); + }); + + it('should return 4', () => { + assert.equal(pow(2, 2), '4'); }); }); \ No newline at end of file diff --git a/app/views/index.ejs b/app/views/index.ejs index be5a172..fe50ea2 100644 --- a/app/views/index.ejs +++ b/app/views/index.ejs @@ -70,6 +70,26 @@ +