Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Third task #3

Merged
merged 4 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ It also includes config linters for `JavaScript` in the `.github` directory.

📌 **Key Features:**
- Each task has its own unit & tester file
- All tasks have separate test suite with description text
- All tasks are in separate test group with description text
- Function `stringLength` returns a number for the input string length
- Any string length outside the range of `(1 - 10)` throws an error `Value out of range!`
- Three test cases are implemented in `stringLength.test.js` for checking valid & invalid input
- Function `reverseString` return the input string with characters in reverse order
- Function `reverseString` returns the input string with characters in reverse order
- One test case was done for `reverseString` function in `reverseString.test.js`
- Object `calculator` contains four functions (`add` / `subtract` / `multiply` / `divide`)
- Each function inside the `calculator` object has three test cases grouped together

<p align="right"><a href="#title">back to top</a></p>

Expand Down
48 changes: 48 additions & 0 deletions testers/calculator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const calculator = require('../units/calculator.js');

describe('Calculator object functions test', () => {
describe('Testing the add function', () => {
test('Adding 3 + 2 should equal 5', () => {
expect(calculator.add(3, 2)).toEqual(5);
});
test('Adding 1000000000 + 1000000000 should equal 2000000000', () => {
expect(calculator.add(1000000000, 1000000000)).toEqual(2000000000);
});
test('Adding (-3) + (-2) should equal -5', () => {
expect(calculator.add(-3, -2)).toEqual(-5);
});
});
describe('Testing the subtract function', () => {
test('Subtracting 3 - 2 should equal 1', () => {
expect(calculator.subtract(3, 2)).toEqual(1);
});
test('Subtracting 1000000000 - 1000000000 should equal 0', () => {
expect(calculator.subtract(1000000000, 1000000000)).toEqual(0);
});
test('Subtracting (-3) - (-2) should equal -5', () => {
expect(calculator.subtract(-3, -2)).toEqual(-1);
});
});
describe('Testing the multiply function', () => {
test('Multiplying 3 * 2 should equal 6', () => {
expect(calculator.multiply(3, 2)).toEqual(6);
});
test('Multiplying 1000000000 * 1000000000 should equal 1000000000000000000', () => {
expect(calculator.multiply(1000000000, 1000000000)).toEqual(1000000000000000000);
});
test('Multiplying (-3) * (-2) should equal 6', () => {
expect(calculator.multiply(-3, -2)).toEqual(6);
});
});
describe('Testing the divide function', () => {
test('Dividing 3 / 2 should equal 1.5', () => {
expect(calculator.divide(3, 2)).toEqual(1.5);
});
test('Dividing 1000000000 / 1000000000 should equal 1', () => {
expect(calculator.divide(1000000000, 1000000000)).toEqual(1);
});
test('Dividing (-3) / (-2) should equal 1.5', () => {
expect(calculator.divide(-3, -2)).toEqual(1.5);
});
});
});
6 changes: 3 additions & 3 deletions testers/stringLength.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const stringLength = require('../units/stringLength.js');

describe('Testing stringLength function', () => {
test('Testing length of "word" string which in range and equals 4', () => {
test('The "word" string is in range and equals 4', () => {
expect(stringLength('word')).toEqual(4);
});
test('Testing length of empty sting "" which is out of range and throws an error', () => {
test('An empty string "" is out of range and throws an error', () => {
expect(() => stringLength('')).toThrow('Value out of range!');
});
test('Testing length of "optimization" string which is out of range and throws an error', () => {
test('Word "optimization" is out of range and throws an error', () => {
expect(() => stringLength('optimization')).toThrow('Value out of range!');
});
});
6 changes: 6 additions & 0 deletions units/calculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
add: (x, y) => x + y,
subtract: (x, y) => x - y,
multiply: (x, y) => x * y,
divide: (x, y) => x / y,
};