Add lab 9 content
This commit is contained in:
parent
585fb2e9e8
commit
76d1fb6c53
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
*.bak
|
||||
.nyc_output
|
8
journal/_src/posts/2022-09-28-lab-nine.md
Normal file
8
journal/_src/posts/2022-09-28-lab-nine.md
Normal 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
25
labs/L09/loop-arith.js
Normal 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
3
labs/L09/minus.js
Normal file
@ -0,0 +1,3 @@
|
||||
let arith=require("./loop-arith.js");
|
||||
|
||||
console.log(arith.minus(10,0));
|
11
labs/L09/spec/builtins.spec.js
Normal file
11
labs/L09/spec/builtins.spec.js
Normal 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); });
|
||||
});
|
30
labs/L09/spec/loop-arith.spec.js
Normal file
30
labs/L09/spec/loop-arith.spec.js
Normal 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)
|
||||
});
|
||||
});
|
13
labs/L09/spec/support/jasmine.json
Normal file
13
labs/L09/spec/support/jasmine.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"spec_dir": "spec",
|
||||
"spec_files": [
|
||||
"**/*[sS]pec.?(m)js"
|
||||
],
|
||||
"helpers": [
|
||||
"helpers/**/*.?(m)js"
|
||||
],
|
||||
"env": {
|
||||
"stopSpecOnExpectationFailure": false,
|
||||
"random": true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user