Skip to content

[LAB3] 510558017 #597

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

Merged
merged 43 commits into from
Jun 26, 2024
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2233c14
fix: improve workflows
AlaRduTP Mar 13, 2024
e2b8057
fix: scripts/rebase-all.sh will fail due to too frequent remote opera…
AlaRduTP Mar 13, 2024
8336df3
feat: lab2
AlaRduTP Mar 13, 2024
0f5c5dd
feat: merge-all
AlaRduTP Mar 13, 2024
5fa8ffe
remove: create-branches.sh
AlaRduTP Mar 20, 2024
354fae7
feat: auto resolve conflicts when merging
AlaRduTP Mar 20, 2024
e49fa08
feat: improve GitHub workflows
AlaRduTP Mar 20, 2024
c895269
feat: lab3
AlaRduTP Mar 20, 2024
22a9521
feat: an easy check for changed files
AlaRduTP Mar 20, 2024
15ca1a7
doc: detailed steps of syncing fork
AlaRduTP Mar 20, 2024
dd650d8
fix: remove trailing whitespace
AlaRduTP Mar 20, 2024
cee6631
feat: add node_modules into gitignore
AlaRduTP Mar 27, 2024
ffbfbd7
feat: lab4
AlaRduTP Mar 27, 2024
5ee9d55
Add lab5
YingMuo Apr 17, 2024
86b3714
Fix github action
YingMuo Apr 17, 2024
c27f68f
Fix README.md
YingMuo Apr 17, 2024
419ed6d
fix: gh-script syntax error
AlaRduTP Apr 17, 2024
41cc403
add: lab6
YingMuo Apr 24, 2024
9777d36
feat: lab6
YingMuo Apr 24, 2024
110400a
fix: lab6
YingMuo Apr 24, 2024
eae2c35
fix: lab6
YingMuo Apr 24, 2024
2063787
Fix: lab6
YingMuo Apr 24, 2024
a2f55d5
Add: lab7
YingMuo May 1, 2024
56585b1
Fix: lab7
YingMuo May 1, 2024
7a945c9
Fix: lab7, angr not installed
YingMuo May 1, 2024
bb5fb3d
feat: add hw4
TaiYou-TW May 30, 2024
b88ef9e
fix: wrong days for hw4 leap year
TaiYou-TW May 30, 2024
27a4b8c
Update main_test.js
as10968574 Jun 5, 2024
4c9b71f
Merge branch '510558017' into lab3
as10968574 Jun 11, 2024
62aad06
Update lab-autograding.yml
as10968574 Jun 11, 2024
13e2ddf
Delete hw4/README.md
as10968574 Jun 24, 2024
846010a
Update package.json
as10968574 Jun 24, 2024
5b90bb8
Update package.json
as10968574 Jun 24, 2024
8109080
Delete hw4/tests/calculator_test.js
as10968574 Jun 24, 2024
4fc5edc
Delete hw4/stryker.config.json
as10968574 Jun 24, 2024
a16b1a1
Delete hw4/.gitignore
as10968574 Jun 24, 2024
399e0f3
Delete hw4/package.json
as10968574 Jun 24, 2024
ef644e0
Delete hw4/src/calculator.js
as10968574 Jun 24, 2024
e6ff9e2
Delete hw4/package-lock.json
as10968574 Jun 24, 2024
257b6c1
Update lab-autograding.yml
as10968574 Jun 24, 2024
ba57332
Update main_test.js
as10968574 Jun 24, 2024
4dd47b4
Update main_test.js
as10968574 Jun 24, 2024
d44a17c
Update main_test.js
as10968574 Jun 24, 2024
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
68 changes: 67 additions & 1 deletion lab3/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,70 @@ const { describe, it } = require('node:test');
const assert = require('assert');
const { Calculator } = require('./main');

// TODO: write your tests here
describe('Calculator', () => {
describe('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));
});

it('should throw an error for unsupported operand type', () => {
const calculator = new Calculator();
assert.throws(() => calculator.exp(NaN), {
name: 'Error',
message: 'unsupported operand type'
});
assert.throws(() => calculator.exp(Infinity), {
name: 'Error',
message: 'unsupported operand type'
});
});

it('should throw an error for overflow', () => {
const calculator = new Calculator();
assert.throws(() => calculator.exp(1000), {
name: 'Error',
message: 'overflow'
});
});
});

describe('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);
});

it('should throw an error for unsupported operand type', () => {
const calculator = new Calculator();
assert.throws(() => calculator.log(NaN), {
name: 'Error',
message: 'unsupported operand type'
});
assert.throws(() => calculator.log(Infinity), {
name: 'Error',
message: 'unsupported operand type'
});
});

it('should throw an error for math domain error (1)', () => {
const calculator = new Calculator();
assert.throws(() => calculator.log(0), {
name: 'Error',
message: 'math domain error (1)'
});
});

it('should throw an error for math domain error (2)', () => {
const calculator = new Calculator();
assert.throws(() => calculator.log(-1), {
name: 'Error',
message: 'math domain error (2)'
});
});
});
});
Loading