Skip to content

[LAB4] 111550083 #333

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 11 commits into from
Jun 5, 2025
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
56 changes: 55 additions & 1 deletion lab3/main_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
const {describe, it} = require('node:test');
const assert = require('assert');
const { Calculator } = require('./main');
const { normalize } = require('path');

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

describe('exp(x)', () =>{
const normalCases = [
{x: 0, expected: 1},
{x: 1, expected: Math.E},
{x: -1, expected: 1/Math.E}
];

for(const nc of normalCases)
{
assert.strictEqual(calculator.exp(nc.x), nc.expected);
}

const errorCases = [
{x: Infinity, error: 'unsupported operand type'},
{x: NaN, error: 'unsupported operand type'},
{x: 10000, error: 'overflow'},

];

for(const ec of errorCases)
{
assert.throws(() => {calculator.exp(ec.x);}, { message: ec.error});
}
});

describe('log(x)', () =>{
const normalCases = [
{x: 1, expected: 0},
{x: Math.E, expected: 1},
{x: 1/Math.E, expected: -1}
];

for(const nc of normalCases)
{
assert.strictEqual(calculator.log(nc.x), nc.expected);
}

const errorCases = [
{x: Infinity, error: 'unsupported operand type'},
{x: NaN, error: 'unsupported operand type'},
{x: 0, error: 'math domain error (1)'},
{x: -1, error: 'math domain error (2)'}

];

for(const ec of errorCases)
{
assert.throws(() => {calculator.log(ec.x);}, { message: ec.error});
}
});
});
18 changes: 15 additions & 3 deletions lab4/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ const puppeteer = require('puppeteer');

// Hints:
// Click search button
await page.waitForSelector('.DocSearch-Button-Placeholder'); //select by class(.)
await page.click('.DocSearch-Search-Icon');

// Type into search box
// Wait for search result
await page.waitForSelector('#docsearch-input'); //select by id(#)
await page.type('#docsearch-input', 'andy popoo');

// Wait for search result
// Get the `Docs` result section
// Click on first result in `Docs` section
await page.waitForSelector('#docsearch-hits1-item-4 a'); //find first <a> element in child
const resultHref = await page.$eval('#docsearch-hits1-item-4 a', el => el.href);
await page.goto(resultHref, { waitUntil: 'domcontentloaded' });

// Locate the title
// Print the title

await page.waitForSelector('.theme-doc-markdown h1');
const resultTitle = await page.$eval('.theme-doc-markdown h1', el => el.textContent);
// Print the title
console.log(`${resultTitle}`);
// Close the browser
await browser.close();
})();