Skip to content

Commit

Permalink
test : lab1 main testing
Browse files Browse the repository at this point in the history
1. test all MyClass member functions
2. test all Student member functions
3. coverage of main up to 100%
  • Loading branch information
Mushroom-MSL1L committed Mar 1, 2024
1 parent 033f080 commit 20ca92f
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,47 @@ const { MyClass, Student } = require('./main');

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

assert.strictEqual(myClass.addStudent("variable that is not Student"), -1);
assert.strictEqual(myClass.addStudent(student), myClass.students.length-1);

// throw new Error("Test not implemented");
});

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

assert.strictEqual(myClass.getStudentById(myClass.students.length), null);
assert.strictEqual(myClass.getStudentById(myClass.students.length - 1), student);
assert.strictEqual(myClass.getStudentById(0), student);
assert.strictEqual(myClass.getStudentById(-1), null);

// throw new Error("Test not implemented");
});

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

// throw new Error("Test not implemented");
});

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

const student2 = new Student();
student2.setName(123);
assert.strictEqual(student2.getName(), '');

// throw new Error("Test not implemented");
});

0 comments on commit 20ca92f

Please sign in to comment.