diff --git a/lab3/main_test.js b/lab3/main_test.js index 096fd421..3b22f558 100644 --- a/lab3/main_test.js +++ b/lab3/main_test.js @@ -3,3 +3,50 @@ const assert = require('assert'); const { Calculator } = require('./main'); // TODO: write your tests here + +describe('Calculator', () => { + + describe('exp', () => { + // 檢查 exp 方法在輸入 0、1 和 -1 時。 + it('Calculate correctly', () => { + const calculator = new Calculator(); + assert.strictEqual(calculator.exp(0), 1); + assert.strictEqual(calculator.exp(1), Math.exp(1)); + assert.strictEqual(calculator.exp(-1), 1 / Math.exp(1)); + }); + // 檢查 exp 方法在Infinity(-) 時。 + it('Calculate error', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.exp(NaN), Error); + assert.throws(() => calculator.exp(Infinity), Error); + assert.throws(() => calculator.exp(-Infinity), Error); + }); + // 檢查 exp 方法在 overflow 時。 + it('overflows', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.exp(9999), Error); + }); + }); + + describe('log', () => { + // 檢查 log 方法在輸入 1 和 Math.E 時 + it('calculate orrectly', () => { + const calculator = new Calculator(); + assert.strictEqual(calculator.log(1), 0); + assert.strictEqual(calculator.log(Math.E), 1); + }); + //檢查 log 方法在輸入 NaN、Infinity時 + it('Calculate error', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.log(NaN), Error); + assert.throws(() => calculator.log(Infinity), Error); + assert.throws(() => calculator.log(-Infinity), Error); + }); + // 檢查 log 方法在輸入 0 和 -1 時 + it('negative infinity or NaN', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.log(0), Error); + assert.throws(() => calculator.log(-1), Error); + }); + }); +}); diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a5..491f0b83 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -1,22 +1,43 @@ const puppeteer = require('puppeteer'); (async () => { - // Launch the browser and open a new blank page + // 啟動瀏覽器並打開一個新的空白頁面 const browser = await puppeteer.launch(); const page = await browser.newPage(); + try{ + // 導航至指定網址 + await page.goto('https://pptr.dev/'); + - // Navigate the page to a URL - await page.goto('https://pptr.dev/'); + // 點擊搜尋按鈕 + await page.click('button.DocSearch.DocSearch-Button'); + - // Hints: - // Click search button - // Type into search box - // Wait for search result - // Get the `Docs` result section - // Click on first result in `Docs` section - // Locate the title - // Print the title + // 在搜尋框中輸入文字 + await page.waitForSelector('#docsearch-input'); + await page.type('#docsearch-input', 'chipi chipi chapa chapa', { delay: 1000 }); + - // Close the browser - await browser.close(); -})(); \ No newline at end of file + // 等待搜尋結果 + await page.waitForSelector('#docsearch-item-5'); + + + // 點擊「Docs」部分的第一個結果 + await page.click('#docsearch-item-5'); + + + // 定位標題 + await page.waitForSelector('h1'); + + // 獲取標題元素的文字內容 + const title = await page.evaluate(() => { + const titleElement = document.querySelector('h1'); + return titleElement.textContent; + }); + console.log(title); + }catch(error){ + console.error('An error occurred:', error); + }finally{ + // 最後都會關閉瀏覽器 + await browser.close();} +})(); diff --git a/lab7/sol.py b/lab7/sol.py index e69de29b..18083edf 100644 --- a/lab7/sol.py +++ b/lab7/sol.py @@ -0,0 +1,14 @@ +import angr, sys + +def success_condition(state): + return b"Login successful" in state.posix.dumps(sys.stdout.fileno()) +def fail_condition(state): + return b"Login failed" in state.posix.dumps(sys.stdout.fileno()) + +proj = angr.Project('./login') +init_state = proj.factory.entry_state() +simulation = proj.factory.simgr(init_state) +simulation.explore(find = success_condition, avoid = fail_condition) +solution = simulation.found[0] + +print(solution.posix.dumps(sys.stdin.fileno()))