Skip to content

Commit db4cec9

Browse files
authored
Merge branch '512559005' into lab7
2 parents a979046 + 163110c commit db4cec9

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

lab1/main_test.js

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,63 @@ const test = require('node:test');
22
const assert = require('assert');
33
const { MyClass, Student } = require('./main');
44

5+
6+
7+
58
test("Test MyClass's addStudent", () => {
6-
// TODO
7-
throw new Error("Test not implemented");
9+
10+
const myClass = new MyClass();
11+
const sam = new Student();
12+
sam.setName('Sam')
13+
const result = myClass.addStudent(sam)
14+
assert.strictEqual(result,0)
15+
16+
const emptyStudent = myClass.addStudent(100.12)
17+
assert.strictEqual(emptyStudent,-1)
18+
819
});
920

1021
test("Test MyClass's getStudentById", () => {
11-
// TODO
12-
throw new Error("Test not implemented");
22+
23+
24+
const myClass = new MyClass();
25+
const sam = new Student();
26+
sam.setName("sam")
27+
myClass.addStudent(sam)
28+
const retrieveStudent = myClass.getStudentById(0)
29+
assert.strictEqual(retrieveStudent,sam)
30+
31+
const retrieveEmpty1 = myClass.getStudentById(-1)
32+
assert.strictEqual(retrieveEmpty1,null)
33+
34+
const retrieveEmpty2 = myClass.getStudentById(1)
35+
assert.strictEqual(retrieveEmpty2,null)
36+
1337
});
1438

1539
test("Test Student's setName", () => {
16-
// TODO
17-
throw new Error("Test not implemented");
40+
41+
42+
const student = new Student();
43+
44+
student.setName(123)
45+
assert.strictEqual(student.name,undefined)
46+
47+
48+
student.setName("Sam")
49+
assert.strictEqual(student.name,"Sam")
50+
1851
});
1952

2053
test("Test Student's getName", () => {
21-
// TODO
22-
throw new Error("Test not implemented");
23-
});
54+
55+
56+
const student = new Student();
57+
assert.strictEqual(student.getName(),'')
58+
59+
60+
student.setName("Sam")
61+
assert.strictEqual(student.getName(),"Sam")
62+
63+
64+
});

lab3/main_test.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
const { describe, test } = require('node:test');
1+
const { describe, it } = require('node:test');
22
const assert = require('assert');
33
const { Calculator } = require('./main');
44

5-
describe('Calculator', () => {
6-
const calc = new Calculator();
7-
test('exp', () => {
8-
assert.strictEqual(calc.exp(0),1);
9-
assert.throws(() => calc.exp('hello'), Error, 'unsupported operand type');
10-
assert.throws(() => calc.exp(10000), Error, 'overflow');
11-
});
12-
13-
test('exp', () => {
14-
assert.strictEqual(calc.log(1),0);
15-
assert.throws(() => calc.log(-1), Error, 'math domain error (2)');
16-
assert.throws(() => calc.log(0), Error, 'math domain error (1)');
17-
assert.throws(() => calc.log('a'), Error, 'unsupported operand type');
18-
});
19-
});

0 commit comments

Comments
 (0)