Skip to content

[LAB5] 511558025 #586

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

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Update main_test.js
  • Loading branch information
Highwaist authored Apr 13, 2024
commit 665b52366bc78e5cf6835c2bf3e5dc743ed4026e
44 changes: 43 additions & 1 deletion lab3/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,46 @@ const { describe, it } = require('node:test');
const assert = require('assert');
const { Calculator } = require('./main');

// TODO: write your tests here
describe('Calculator', () => {
describe('exp', () => {
it('should return the exponential value of a number', () => {
const calculator = new Calculator();
assert.strictEqual(calculator.exp(0), 1);
assert.strictEqual(calculator.exp(1), Math.exp(1));
assert.strictEqual(calculator.exp(2), Math.exp(2));
});

it('should throw error for unsupported operand type', () => {
const calculator = new Calculator();
assert.throws(() => calculator.exp('abc'), Error);
assert.throws(() => calculator.exp(null), Error);
});

it('should throw error for overflow', () => {
const calculator = new Calculator();
assert.throws(() => calculator.exp(1000), Error);
});
});

describe('log', () => {
it('should return the natural logarithm of a number', () => {
const calculator = new Calculator();
assert.strictEqual(calculator.log(1), 0);
assert.strictEqual(calculator.log(Math.exp(1)), 1);
assert.strictEqual(calculator.log(10), Math.log(10));
});

it('should throw error for unsupported operand type', () => {
const calculator = new Calculator();
assert.throws(() => calculator.log('abc'), Error);
assert.throws(() => calculator.log(null), Error);
assert.throws(() => calculator.log(-1), Error);
});

it('should throw error for math domain errors', () => {
const calculator = new Calculator();
assert.throws(() => calculator.log(0), Error);
assert.throws(() => calculator.log(-100), Error);
});
});
});