add unit tests

This commit is contained in:
Yannick 2025-04-14 11:31:04 +02:00
commit 116ccc14d8
7 changed files with 3617 additions and 0 deletions

View file

@ -0,0 +1,65 @@
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);
});
});
});

View file

@ -0,0 +1,72 @@
import assert from 'assert';
import * as test2library from '../testlibrary.js';
describe('Testing test2library', () => {
describe("combineStrings", () => {
it("should return 'HelloWorld'", () => {
assert.equal(test2library.combineStrings("Hello", "World"), "HelloWorld");
});
it("should return 'Hello'", () => {
assert.equal(test2library.combineStrings("Hello", ""), "Hello");
});
it("should return 'World'", () => {
assert.equal(test2library.combineStrings("", "World"), "World");
});
it("should return ''", () => {
assert.equal(test2library.combineStrings("", ""), "");
});
it("should return '喵喵'", () => {
assert.equal(test2library.combineStrings("喵", "汪汪"), "喵汪汪");
});
});
describe("reverseString", () => {
it("should return 'olleH'", () => {
assert.equal(test2library.reverseString("Hello"), "olleH");
});
it("should return ''", () => {
assert.equal(test2library.reverseString(""), "");
});
it("should return '喵喵'", () => {
assert.equal(test2library.reverseString("喵汪汪"), "汪汪喵");
});
it("should return 'aibohphobia'", () => {
assert.equal(test2library.reverseString("aibohphobia"), "aibohphobia");
});
});
describe("capitalizeString", () => {
it("should return 'Hello'", () => {
assert.equal(test2library.capitalizeString("hello"), "Hello");
});
it("should return 'Hello'", () => {
assert.equal(test2library.capitalizeString("Hello"), "Hello");
});
it("should return ''", () => {
assert.equal(test2library.capitalizeString(""), "");
});
it("should return '喵'", () => {
assert.equal(test2library.capitalizeString("喵"), "喵");
});
});
describe("isPalindrome", () => {
it("should return true", () => {
assert.equal(test2library.isPalindrome("madam"), true);
});
it("should return false", () => {
assert.equal(test2library.isPalindrome("hello"), false);
});
it("should return true", () => {
assert.equal(test2library.isPalindrome(""), true);
});
it("should return true", () => {
assert.equal(test2library.isPalindrome("喵"), true);
});
it("should return true", () => {
assert.equal(test2library.isPalindrome("a"), true);
});
it("should return true", () => {
assert.equal(test2library.isPalindrome("aibohphobia"), true);
});
});
});