-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from YJack0000/main
[LAB1] 312551011
- Loading branch information
Showing
1 changed file
with
37 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
const test = require('node:test'); | ||
const assert = require('assert'); | ||
const { MyClass, Student } = require('./main'); | ||
const test = require("node:test"); | ||
const assert = require("assert"); | ||
const { MyClass, Student } = require("./main"); | ||
|
||
test("Test MyClass's addStudent", () => { | ||
// TODO | ||
throw new Error("Test not implemented"); | ||
let myClass = new MyClass(); | ||
// test if the type of the student is not Student | ||
assert.strictEqual(myClass.addStudent("not a student"), -1); | ||
|
||
// test if there is no student in MyClass | ||
assert.strictEqual(myClass.students.length, 0); | ||
|
||
// test if there is one student in MyClass | ||
let student = new Student(); | ||
student.setName("John"); | ||
myClass.addStudent(student); | ||
assert.strictEqual(myClass.students.length, 1); | ||
}); | ||
|
||
test("Test MyClass's getStudentById", () => { | ||
// TODO | ||
throw new Error("Test not implemented"); | ||
let myClass = new MyClass(); | ||
// test if the search id is not a number | ||
assert.strictEqual(myClass.getStudentById("not a number"), undefined); | ||
|
||
// test if student id is out of range | ||
assert.strictEqual(myClass.getStudentById(-1), null); | ||
assert.strictEqual(myClass.getStudentById(0), null); | ||
|
||
// test if the student is found | ||
let student = new Student(); | ||
student.setName("John"); | ||
myClass.addStudent(student); | ||
assert.strictEqual(myClass.getStudentById(0), student); | ||
}); | ||
|
||
test("Test Student's setName", () => { | ||
// TODO | ||
throw new Error("Test not implemented"); | ||
let student = new Student(); | ||
assert.strictEqual(student.setName(123), undefined); | ||
student.setName("John"); | ||
assert.strictEqual(student.name, "John"); | ||
}); | ||
|
||
test("Test Student's getName", () => { | ||
// TODO | ||
throw new Error("Test not implemented"); | ||
}); | ||
let student = new Student(); | ||
assert.strictEqual(student.getName(), ""); | ||
student.setName("John"); | ||
assert.strictEqual(student.getName(), "John"); | ||
}); |