Skip to content

Commit 6aa9823

Browse files
authored
Merge pull request #318 from cfmc30/lab4
[LAB4] 313552023
2 parents 8886979 + 9c6ffd8 commit 6aa9823

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

lab3/main_test.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,50 @@ const {describe, it} = require('node:test');
22
const assert = require('assert');
33
const { Calculator } = require('./main');
44

5-
// TODO: write your tests here
5+
describe('Calculator', () => {
6+
const calc = new Calculator();
7+
8+
// ---- exp(x) tests ----
9+
it('exp(0) should return 1', () => {
10+
assert.strictEqual(calc.exp(0), 1);
11+
});
12+
13+
it('exp(1) should return ~2.718', () => {
14+
assert.ok(Math.abs(calc.exp(1) - Math.E) < 1e-10);
15+
});
16+
17+
it('exp(Infinity) should throw unsupported operand type', () => {
18+
assert.throws(() => calc.exp(Infinity), {
19+
message: 'unsupported operand type'
20+
});
21+
});
22+
23+
it('exp(1000) should throw overflow', () => {
24+
assert.throws(() => calc.exp(1000), {
25+
message: 'overflow'
26+
});
27+
});
28+
29+
// ---- log(x) tests ----
30+
it('log(1) should return 0', () => {
31+
assert.strictEqual(calc.log(1), 0);
32+
});
33+
34+
it('log(0) should throw math domain error (1)', () => {
35+
assert.throws(() => calc.log(0), {
36+
message: 'math domain error (1)'
37+
});
38+
});
39+
40+
it('log(-5) should throw math domain error (2)', () => {
41+
assert.throws(() => calc.log(-5), {
42+
message: 'math domain error (2)'
43+
});
44+
});
45+
46+
it('log(NaN) should throw unsupported operand type', () => {
47+
assert.throws(() => calc.log(NaN), {
48+
message: 'unsupported operand type'
49+
});
50+
});
51+
});

lab4/main_test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ const puppeteer = require('puppeteer');
1717
// Locate the title
1818
// Print the title
1919

20+
await page.click('.DocSearch-Button');
21+
const searchBoxSelector = '.DocSearch-Input';
22+
await page.waitForSelector(searchBoxSelector);
23+
await page.type(searchBoxSelector, 'andy popoo');
24+
25+
await page.locator('#docsearch-hits1-item-4 > a:nth-child(1) > div:nth-child(1)').click();
26+
// await page.waitForSelector(`.theme-doc-markdown > header:nth-child(1) > h1:nth-child(1)').innerText`);
27+
await new Promise(r => setTimeout(r, 1000));
28+
title = await page.evaluate(`document.querySelector('.theme-doc-markdown > header:nth-child(1) > h1:nth-child(1)').innerText `);
29+
console.log(title);
30+
31+
await page.screenshot({path: 'screenshot.png'});
32+
33+
2034
// Close the browser
2135
await browser.close();
22-
})();
36+
})();

0 commit comments

Comments
 (0)