Add lab 9 content

This commit is contained in:
Isaac Shoebottom 2022-10-12 09:04:35 -03:00
parent 585fb2e9e8
commit 76d1fb6c53
7 changed files with 92 additions and 1 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*.bak *.bak
.nyc_output

View File

@ -0,0 +1,8 @@
Title: Lab Nine
Date: 2022-10-12T08:30:00
Tags: cs2163, lab, javascript,
TBD
<!-- more -->
TBD

25
labs/L09/loop-arith.js Normal file
View File

@ -0,0 +1,25 @@
function plus(a,b) {
for (let i=0; i < a; i++){
b++;
}
return b;
}
function mult(a,b) {
sum=0;
for(let i=0; i < a; i++) {
sum = plus(sum, b)
}
return sum;
}
function minus(a,b) {
for (let i=0; i < a; i++){
b--;
}
return b;
}
exports.plus = plus;
exports.mult = mult;
exports.minus = minus;

3
labs/L09/minus.js Normal file
View File

@ -0,0 +1,3 @@
let arith=require("./loop-arith.js");
console.log(arith.minus(10,0));

View File

@ -0,0 +1,11 @@
describe("identity",
function() {
it("1 === 1", function() { expect(1).toBe(1); });
it("null === null", function() { expect(null).toBe(null); })
});
describe("arithmetic",
function() {
it("1 + 1 === 2", function() { expect(1 + 1).toBe(2); });
it("6 * 7 === 42", function() { expect(6*7).toBe(42); });
});

View File

@ -0,0 +1,30 @@
let arith=require ("../loop-arith.js");
describe("add",
function() {
it("1 + 1 = 2",
function() {
expect(arith.add(1, 1)).toBe(2);
});
it("0 + x = x",
function() {
expect(arith.add(0, 1)).toBe(1);
});
});
describe("mult",
function() {
it("0 * 2 = 0",
function() {
expect(arith.mult(0, 2)).toBe(0);
});
it("1 * 2 = 2",
function() {
expect(arith.mult(1,2)).toBe(2);
});
it("2 * 2 = 4",
function() {
expect(arith.mult(2, 2)).toBe(4)
});
});

View File

@ -0,0 +1,13 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.?(m)js"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"env": {
"stopSpecOnExpectationFailure": false,
"random": true
}
}