diff --git a/lab3/main_test.js b/lab3/main_test.js index 096fd421..7c5e9bae 100644 --- a/lab3/main_test.js +++ b/lab3/main_test.js @@ -2,4 +2,63 @@ const { describe, it } = require('node:test'); const assert = require('assert'); const { Calculator } = require('./main'); -// TODO: write your tests here +describe("Calculator Test", () => { + const calculator = new Calculator(); + + const logTestSuites = [ + { + operation: "log", + cases: [ + { data: 6, expected: Math.log(6) }, + { data: 5, expected: Math.log(5) }, + { data: 2, expected: Math.log(2) }, + { data: 'guava', expected: Error, message: "unsupported operand type" }, + { data: true, expected: Error, message: "unsupported operand type" }, + { data: Infinity, expected: Error, message: "unsupported operand type" }, + { data: 0, expected: Error, message: "math domain error (1)" }, + { data: -1, expected: Error, message: "math domain error (2)" }, + ] + } + ]; + + logTestSuites.forEach(({ operation, cases }) => { + it(`Calculator.${operation}() Test`, () => { + cases.forEach(({ data: param, expected: expectedOutput, message: msg }) => { + if (expectedOutput === Error) { + assert.throws(() => calculator[operation](param), expectedOutput, msg); + } else { + const result = calculator[operation](param); + assert.strictEqual(result, expectedOutput, msg); + } + }); + }); + }); + + const expTestSuites = [ + { + operation: "exp", + cases: [ + { data: 4, expected: Math.exp(4) }, + { data: 0, expected: Math.exp(0) }, + { data: -2, expected: Math.exp(-2) }, + { data: 'guava666', expected: Error, message: "unsupported operand type" }, + { data: true, expected: Error, message: "unsupported operand type" }, + { data: Infinity, expected: Error, message: "unsupported operand type" }, + { data: Number.MAX_VALUE, expected: Error, message: "overflow" }, + ] + } + ]; + + expTestSuites.forEach(({ operation, cases }) => { + it(`Calculator.${operation}() Test`, () => { + cases.forEach(({ data: param, expected: expectedOutput, message: msg }) => { + if (expectedOutput === Error) { + assert.throws(() => calculator[operation](param), expectedOutput, msg); + } else { + const result = calculator[operation](param); + assert.strictEqual(result, expectedOutput, msg); + } + }); + }); + }); +}); diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a5..706f01d2 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -7,16 +7,28 @@ const puppeteer = require('puppeteer'); // Navigate the page to a URL await page.goto('https://pptr.dev/'); - + // Hints: // Click search button + await page.click('button.DocSearch.DocSearch-Button'); //點擊指定按鈕 + // Type into search box // Wait for search result + await page.waitForSelector('#docsearch-input.DocSearch-Input'); //等待 id 為 docsearch-input 且具有 DocSearch-Input 類的元素出現在頁面上 + await page.type('#docsearch-input.DocSearch-Input', 'chipi chipi chapa chapa',{delay: 2000}); //將指定的文字 'chipi chipi chapa chapa' 輸入到 id 為 docsearch-input 且具有 DocSearch-Input 類的元素中 + // Get the `Docs` result section + await page.waitForSelector('#docsearch-item-5.DocSearch-Hit'); //等待 id 為 docsearch-item-5 且具有 DocSearch-Hit 類的元素出現在頁面上 // Click on first result in `Docs` section + await page.click('#docsearch-item-5.DocSearch-Hit'); //點擊指定按鈕 + // Locate the title + let titletext = await page.waitForSelector('#__docusaurus_skipToContent_fallback > div > div > main > div > div > div > div > article > div.theme-doc-markdown.markdown > h1'); //等待指定的元素出現在當前頁面上,並將內容存儲在變數 titletext 中 + let flag = await titletext.evaluate(element=> element.textContent); //使用 textContent 屬性來獲取指定文字內容 + // Print the title - + console.log(flag); //呈現指定內容 + // Close the browser await browser.close(); -})(); \ No newline at end of file +})(); diff --git a/lab7/sol.py b/lab7/sol.py index e69de29b..55c4a6b5 100644 --- a/lab7/sol.py +++ b/lab7/sol.py @@ -0,0 +1,16 @@ +import angr +import sys + +proj = angr.Project('./login') +init_state = proj.factory.entry_state() +simulation = proj.factory.simgr(init_state) + +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()) + +simulation.explore(find=success_condition, avoid=fail_condition) +solution = simulation.found[0] +print(solution.posix.dumps(sys.stdin.fileno()))