Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
linhengpei committed Feb 29, 2024
1 parent 033f080 commit 08566e4
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,36 @@ const assert = require('assert');
const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();
const myClass = new MyClass();

assert.strictEqual(myClass.addStudent(student), 0); // first student
assert.strictEqual(myClass.addStudent(myClass), -1); // return -1
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();
const myClass = new MyClass();

const newStudentId = myClass.addStudent(student);
assert.strictEqual(myClass.getStudentById(newStudentId), student);
assert.strictEqual(myClass.getStudentById(100), null); // over length
});

test("Test Student's setName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();

student.setName("John"); // 使用assert.strictEqual来断言student的name属性是否被正确设置
assert.strictEqual(student.name, "John");

student.setName(123); // 尝试使用非字符串值设置
assert.strictEqual(student.name, "John");
});

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student(); // undefined
assert.strictEqual(student.getName(), '');

student.setName("Jane");
assert.strictEqual(student.getName(), "Jane");
});

0 comments on commit 08566e4

Please sign in to comment.