Skip to content

[LAB4] 313552023 #318

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

Open
wants to merge 2 commits into
base: 313552023
Choose a base branch
from
Open
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
48 changes: 47 additions & 1 deletion lab3/main_test.js
Original file line number Diff line number Diff line change
@@ -2,4 +2,50 @@ const {describe, it} = require('node:test');
const assert = require('assert');
const { Calculator } = require('./main');

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

// ---- exp(x) tests ----
it('exp(0) should return 1', () => {
assert.strictEqual(calc.exp(0), 1);
});

it('exp(1) should return ~2.718', () => {
assert.ok(Math.abs(calc.exp(1) - Math.E) < 1e-10);
});

it('exp(Infinity) should throw unsupported operand type', () => {
assert.throws(() => calc.exp(Infinity), {
message: 'unsupported operand type'
});
});

it('exp(1000) should throw overflow', () => {
assert.throws(() => calc.exp(1000), {
message: 'overflow'
});
});

// ---- log(x) tests ----
it('log(1) should return 0', () => {
assert.strictEqual(calc.log(1), 0);
});

it('log(0) should throw math domain error (1)', () => {
assert.throws(() => calc.log(0), {
message: 'math domain error (1)'
});
});

it('log(-5) should throw math domain error (2)', () => {
assert.throws(() => calc.log(-5), {
message: 'math domain error (2)'
});
});

it('log(NaN) should throw unsupported operand type', () => {
assert.throws(() => calc.log(NaN), {
message: 'unsupported operand type'
});
});
});
16 changes: 15 additions & 1 deletion lab4/main_test.js
Original file line number Diff line number Diff line change
@@ -17,6 +17,20 @@ const puppeteer = require('puppeteer');
// Locate the title
// Print the title

await page.click('.DocSearch-Button');
const searchBoxSelector = '.DocSearch-Input';
await page.waitForSelector(searchBoxSelector);
await page.type(searchBoxSelector, 'andy popoo');

await page.locator('#docsearch-hits1-item-4 > a:nth-child(1) > div:nth-child(1)').click();
// await page.waitForSelector(`.theme-doc-markdown > header:nth-child(1) > h1:nth-child(1)').innerText`);
await new Promise(r => setTimeout(r, 1000));
title = await page.evaluate(`document.querySelector('.theme-doc-markdown > header:nth-child(1) > h1:nth-child(1)').innerText `);
console.log(title);

await page.screenshot({path: 'screenshot.png'});


// Close the browser
await browser.close();
})();
})();