js-tooling-in-detail/testing/tests/test2library.test.js
2025-04-14 11:31:04 +02:00

65 lines
No EOL
2.1 KiB
JavaScript

import assert from 'assert';
import * as test2library from '../test2library.js';
describe('Testing test2library', () => {
describe("addTwoNumbers", () => {
it("should return 5", () => {
assert.equal(test2library.addTwoNumbers(2, 3), 5);
});
it("should return 0", () => {
assert.equal(test2library.addTwoNumbers(0, 0), 0);
});
it("should return -1", () => {
assert.equal(test2library.addTwoNumbers(-2, 0), -2);
});
});
describe("subtractTwoNumbers", () => {
it("should return 1", () => {
assert.equal(test2library.subtractTwoNumbers(3, 2), 1);
});
it("should return -2", () => {
assert.equal(test2library.subtractTwoNumbers(0, 2), -2);
});
it("should return 1", () => {
assert.equal(test2library.subtractTwoNumbers(-1, -2), 1);
});
});
describe("multiplyTwoNumbers", () => {
it("should return 6", () => {
assert.equal(test2library.multiplyTwoNumbers(2, 3), 6);
});
it("should return 0", () => {
assert.equal(test2library.multiplyTwoNumbers(0, 2), 0);
});
it("should return 2", () => {
assert.equal(test2library.multiplyTwoNumbers(-1, -2), 2);
});
});
describe("divideTwoNumbers", () => {
it("should return 2", () => {
assert.equal(test2library.divideTwoNumbers(6, 3), 2);
});
it("should return 0", () => {
assert.equal(test2library.divideTwoNumbers(0, 2), 0);
});
it("should throw an error", () => {
assert.throws(() => test2library.divideTwoNumbers(1, 0), Error);
});
});
describe("squareNumber", () => {
it("should return 4", () => {
assert.equal(test2library.squareNumber(2), 4);
});
it("should return 0", () => {
assert.equal(test2library.squareNumber(0), 0);
});
it("should return 1", () => {
assert.equal(test2library.squareNumber(-1), 1);
});
});
});