add unit tests
This commit is contained in:
parent
87a42ebc95
commit
116ccc14d8
7 changed files with 3617 additions and 0 deletions
1
testing/.gitignore
vendored
Normal file
1
testing/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
node_modules/
|
3446
testing/package-lock.json
generated
Normal file
3446
testing/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
16
testing/package.json
Normal file
16
testing/package.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "mocha \"./tests/*.test.js\""
|
||||
},
|
||||
"name": "testing",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"devDependencies": {
|
||||
"cypress": "^14.3.0",
|
||||
"mocha": "^11.1.0"
|
||||
}
|
||||
}
|
10
testing/test2library.js
Normal file
10
testing/test2library.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
export const addTwoNumbers = (a, b) => a + b;
|
||||
export const subtractTwoNumbers = (a, b) => a - b;
|
||||
export const multiplyTwoNumbers = (a, b) => a * b;
|
||||
export const divideTwoNumbers = (a, b) => {
|
||||
if (b === 0) {
|
||||
throw new Error("Cannot divide by zero");
|
||||
}
|
||||
return a / b;
|
||||
}
|
||||
export const squareNumber = (a) => a * a;
|
7
testing/testlibrary.js
Normal file
7
testing/testlibrary.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
export const combineStrings = (str1, str2) => str1 + str2;
|
||||
export const reverseString = (str) => str.split('').reverse().join('');
|
||||
export const capitalizeString = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
||||
export const isPalindrome = (str) => {
|
||||
const reversed = str.split('').reverse().join('');
|
||||
return str === reversed;
|
||||
}
|
65
testing/tests/test2library.test.js
Normal file
65
testing/tests/test2library.test.js
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
72
testing/tests/testlibrary.test.js
Normal file
72
testing/tests/testlibrary.test.js
Normal 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);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Add table
Reference in a new issue