diff --git a/lab3/main_test.js b/lab3/main_test.js index e6d6414..4f4dbd7 100644 --- a/lab3/main_test.js +++ b/lab3/main_test.js @@ -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}); + } + }); +}); diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a..5da7fd8 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -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 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(); })(); \ No newline at end of file