Add lab 10 content

This commit is contained in:
Isaac Shoebottom
2022-10-17 10:24:22 -03:00
parent 5fe9b2c913
commit 29dd89f729
9 changed files with 244 additions and 0 deletions

View File

@ -0,0 +1,31 @@
let array=require("../arrays.js");
describe("range", function () {
it("empty", function () {
expect(array.range(2,1)).toEqual([]);
});
it("single", function () {
expect(array.range(2,2)).toEqual([2]);
});
it("multiple", function () {
expect(array.range(42,50)).toEqual([42,43,44,45,46,47,48,49,50]);
});
it("step", function() {
expect(array.range(2,10,2)).toEqual([2,4,6,8,10]);
})
});
describe("sum", function () {
it("empty", function () {
expect(array.sum([])).toBe(0);
});
it("single", function () {
expect(array.sum([2])).toBe(2);
});
it("multiple", function () {
expect(array.sum(array.range(1,10))).toBe(55);
})
it("stepped", function() {
expect(array.sum(array.range(2,10,2))).toBe(30)
});
});

View File

@ -0,0 +1,30 @@
let arith=require ("../rec-arith.js");
describe("plus",
function() {
it("1 + 1 = 2",
function() {
expect(arith.plus(1, 1)).toBe(2);
});
it("0 + x = x",
function() {
expect(arith.plus(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,31 @@
let loop_arith=require ("../loop-arith.js");
let rec_arith=require ("../rec-arith.js");
describe("plus",
function() {
it("1 + 1 = 2",
function() {
expect(loop_arith.plus(1, 1)).toBe(rec_arith.plus(1, 1));
});
it("0 + x = x",
function() {
expect(loop_arith.plus(0, 1)).toBe(rec_arith.plus(0, 1));
});
});
describe("mult",
function() {
it("0 * 2 = 0",
function() {
expect(loop_arith.mult(0, 2)).toBe(rec_arith.mult(0, 2));
});
it("1 * 2 = 2",
function() {
expect(loop_arith.mult(1, 2)).toBe(rec_arith.mult(1, 2));
});
it("2 * 2 = 4",
function() {
expect(loop_arith.mult(2, 2)).toBe(rec_arith.mult(2, 2));
});
});

View File

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