Skip to content

[LAB3] 510558017 #565

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 1 commit into from
Closed
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
57 changes: 56 additions & 1 deletion lab3/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,59 @@ const { describe, it } = require('node:test');
const assert = require('assert');
const { Calculator } = require('./main');

// TODO: write your tests here
describe('Calculator', () => {
const calculator = new Calculator();

describe('exp function', () => {
it('calculates the exponential of a number', async () => {
assert.strictEqual(calculator.exp(1), Math.exp(1));
});

it('throws error on non-finite input', async () => {
assert.throws(() => calculator.exp('a'), {
name: 'Error',
message: 'unsupported operand type'
});
assert.throws(() => calculator.exp(Infinity), {
name: 'Error',
message: 'unsupported operand type'
});
});

it('handles overflow', async () => {
assert.throws(() => calculator.exp(1000), {
name: 'Error',
message: 'overflow'
});
});
});

describe('log function', () => {
it('calculates the logarithm of a number', async () => {
assert.strictEqual(calculator.log(Math.E), Math.log(Math.E));
});

it('throws error on non-finite input', async () => {
assert.throws(() => calculator.log('a'), {
name: 'Error',
message: 'unsupported operand type'
});
assert.throws(() => calculator.log(-1), {
name: 'Error',
message: 'math domain error (1)'
});
});

it('handles domain errors', async () => {
assert.throws(() => calculator.log(0), {
name: 'Error',
message: 'math domain error (1)'
});
assert.throws(() => calculator.log(null), {
name: 'Error',
message: 'unsupported operand type'
});
});
});
});

Loading