Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pow #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# INFO909 : Intégration continue - Déploiement continu
## Kubasik Tom
## Bollon Ration

## A faire en amont du cours du 12 janvier

Expand Down
13 changes: 12 additions & 1 deletion app/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@ exports.add = (num1, num2) => {

exports.mul = (num1, num2) => {
return (num1 * num2).toString();
}
}

exports.div = (num1, num2) => {
if(num2 == 0) {
return "NaN"
}
return (num1 / num2).toString();
}

exports.pow = (num1, num2) => {
return (Math.pow(num1, num2)).toString();
}
9 changes: 8 additions & 1 deletion app/server.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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}`);
18 changes: 14 additions & 4 deletions app/test/unit.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
38 changes: 38 additions & 0 deletions app/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@
<span class="h2" id="mulres"></span>
</div>
</div>
<hr>
<div class="row">
<div class="col-3">
<input class="form-control" id="div1">
</div>
<div class="col-1">
<div class="w-100 text-center">
/
</div>
</div>
<div class="col-3">
<input class="form-control" id="div2">
</div>
<div class="col-2">
<button type="button" class="btn btn-primary w-100" onclick="divide()">DIV</button>
</div>
<div class="col-3">
<span class="h2" id="divres"></span>
</div>
</div>

</div>

Expand Down Expand Up @@ -129,6 +149,24 @@
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
xhr.send(JSON.stringify(params))
}
function divide() {
var x = document.getElementById('div1').value
var y = document.getElementById('div2').value
var res = document.getElementById('divres')
var params = {
"num1": x,
"num2": y
}
let xhr = new XMLHttpRequest()
xhr.open('POST', '/div', true)
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
res.innerHTML = xhr.responseText
}
};
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
xhr.send(JSON.stringify(params))
}
</script>
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
Expand Down