Skip to content

Commit

Permalink
Merge pull request #66 from YJack0000/main
Browse files Browse the repository at this point in the history
[LAB1] 312551011
  • Loading branch information
TaiYou-TW authored Mar 10, 2024
2 parents 95502c6 + a101512 commit 3e201ed
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions lab1/main_test.js
100644 → 100755
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");
});

0 comments on commit 3e201ed

Please sign in to comment.