Skip to content

[Lab3] 512558012 #2

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

Merged
merged 1 commit into from
Jun 26, 2024
Merged
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
52 changes: 49 additions & 3 deletions lab3/main_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
const { describe, it } = require('node:test');
const assert = require('assert');
const { Calculator } = require('./main');
const Jasmine = require('jasmine');
const jasmine = new Jasmine();

describe('Calculator', () => {
let calculator;

beforeEach(() => {
calculator = new Calculator();
});

describe('exp function', () => {
it('should correctly calculate the exponential of valid numbers', () => {
expect(calculator.exp(1)).toBeCloseTo(Math.exp(1));
expect(calculator.exp(0)).toBeCloseTo(1);
expect(calculator.exp(-1)).toBeCloseTo(Math.exp(-1));
});

it('should throw an error for non-finite inputs', () => {
expect(() => calculator.exp(Infinity)).toThrowError('unsupported operand type');
expect(() => calculator.exp(-Infinity)).toThrowError('unsupported operand type');
expect(() => calculator.exp(NaN)).toThrowError('unsupported operand type');
});

it('should throw an overflow error for large inputs', () => {
expect(() => calculator.exp(1000)).toThrowError('overflow');
});
});

describe('log function', () => {
it('should correctly calculate the logarithm of valid numbers', () => {
expect(calculator.log(1)).toBeCloseTo(Math.log(1));
expect(calculator.log(Math.E)).toBeCloseTo(1);
expect(calculator.log(10)).toBeCloseTo(Math.log(10));
});

it('should throw an error for non-finite inputs', () => {
expect(() => calculator.log(Infinity)).toThrowError('unsupported operand type');
expect(() => calculator.log(-Infinity)).toThrowError('unsupported operand type');
expect(() => calculator.log(NaN)).toThrowError('unsupported operand type');
});

it('should throw a math domain error for invalid domain inputs', () => {
expect(() => calculator.log(-1)).toThrowError('math domain error (2)');
expect(() => calculator.log(0)).toThrowError('math domain error (1)');
});
});
});

jasmine.execute();

// TODO: write your tests here