diff --git a/lab3/main_test.js b/lab3/main_test.js index e6d6414..30f3d9b 100644 --- a/lab3/main_test.js +++ b/lab3/main_test.js @@ -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' + }); + }); +}); diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a..0778c25 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -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(); -})(); \ No newline at end of file +})();