Skip to content

[LAB7] 512558013 #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion lab3/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
});
});
18 changes: 15 additions & 3 deletions lab4/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})();
})();
16 changes: 16 additions & 0 deletions lab7/sol.py
Original file line number Diff line number Diff line change
@@ -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()))
Loading