From 81d774d60494a90d35abfed2e32437bb5e85b39f Mon Sep 17 00:00:00 2001 From: MingTing1114 <91309913+MingTing1114@users.noreply.github.com> Date: Sun, 14 Apr 2024 17:01:25 +0800 Subject: [PATCH 1/2] Update main_test.js --- lab3/main_test.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/lab3/main_test.js b/lab3/main_test.js index 096fd421..127ea998 100644 --- a/lab3/main_test.js +++ b/lab3/main_test.js @@ -2,4 +2,52 @@ const { describe, it } = require('node:test'); const assert = require('assert'); const { Calculator } = require('./main'); -// TODO: write your tests here +describe('Calculator', () => { + describe('exp', () => { + // 測試 exp 方法正確計算指數函數 + it('should calculate the exponential function correctly', () => { + const calculator = new Calculator(); + assert.strictEqual(calculator.exp(0), 1); + assert.strictEqual(calculator.exp(1), Math.exp(1)); + assert.strictEqual(calculator.exp(2), Math.exp(2)); + }); +// 測試 exp 方法當傳入不支援的操作數類型時是否拋出錯誤 + it('should throw an error for unsupported operand type', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.exp(NaN), Error); + assert.throws(() => calculator.exp(Infinity), Error); + }); +// 測試 exp 方法當計算結果溢出時是否拋出溢出錯誤 + it('should throw an error for overflow', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.exp(1000), Error); + }); + }); + + describe('log', () => { + // 測試 log 方法正確計算自然對數 + it('should calculate the natural logarithm correctly', () => { + const calculator = new Calculator(); + assert.strictEqual(calculator.log(1), 0); + assert.strictEqual(calculator.log(Math.E), 1); + }); +// 測試 log 方法當傳入不支援的操作數類型時是否拋出錯誤 + it('should throw an error for unsupported operand type', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.log(NaN), Error); + assert.throws(() => calculator.log(Infinity), Error); + assert.throws(() => calculator.log(0), Error); + assert.throws(() => calculator.log(-1), Error); + }); +// 測試 log 方法當計算結果為負無窮大或非數字時是否拋出相應錯誤 + it('should throw an error for math domain error (1)', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.log(0), Error); + }); + + it('should throw an error for math domain error (2)', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.log(-1), Error); + }); + }); +}); From 681b73e6af4aadfe8f71a1942234214321d54cca Mon Sep 17 00:00:00 2001 From: MingTing1114 <91309913+MingTing1114@users.noreply.github.com> Date: Mon, 27 May 2024 11:07:05 +0800 Subject: [PATCH 2/2] Update sol.py --- lab7/sol.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lab7/sol.py b/lab7/sol.py index e69de29b..1c5e923a 100644 --- a/lab7/sol.py +++ b/lab7/sol.py @@ -0,0 +1,22 @@ +import angr, 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())) + + +