Skip to content

[LAB1] 312555001 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,58 @@ const assert = require('assert');
const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const names = ['John', 'Jane', 'Doe', 'Smith'];
var ctr = 0;
const clseeList = [];
names.forEach(name => {
const student = new Student();
student.setName(name);
const newStudentId = myClass.addStudent(student);
assert.strictEqual(newStudentId, ctr++);
clseeList.push(student);
});
assert.deepStrictEqual(myClass.students, clseeList);
const newStudentId = myClass.addStudent('Failed');
assert.strictEqual(newStudentId, -1);
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const names = ['John', 'Jane', 'Doe', 'Smith'];
var ctr = 0;
const clseeList = [];
names.forEach(name => {
const student = new Student();
student.setName(name);
const newStudentId = myClass.addStudent(student);
clseeList.push(student);
});
for (var i = 0; i < 4; ++i) {
assert.strictEqual(myClass.getStudentById(i), clseeList[i]);
}
const newStudentId = myClass.getStudentById(4);
assert.strictEqual(newStudentId, null);
const newStudentId2 = myClass.getStudentById(-1);
assert.strictEqual(newStudentId2, null);
const newStudentId3 = myClass.getStudentById("A");
assert.strictEqual(newStudentId3, undefined);
});

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

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