Skip to content
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

[LAB1] 312555003 #12

Merged
merged 4 commits into from
Mar 7, 2024
Merged
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
54 changes: 46 additions & 8 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,60 @@ const test = require('node:test');
const assert = require('assert');
const { MyClass, Student } = require('./main');

const names = ['John', 'Jane', 'Doe', 'Smith'];

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
let myClass = new MyClass();
assert.strictEqual(myClass.students.length, 0);

let stdid = myClass.addStudent([]);
assert.strictEqual(stdid, -1);

for(let i=0; i<100; i++){
let stdid = myClass.addStudent(new Student());
assert.strictEqual(myClass.students.length, i+1);
assert.strictEqual(stdid, i);
}
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
let myClass = new MyClass();
let stdids = [];
for(let i=0; i<names.length; i++){
let student = new Student();
student.setName(names[i]);
stdids.push(myClass.addStudent(student));
}

for(let i=0; i<names.length; i++){
let student = myClass.getStudentById(stdids[i]);
assert.strictEqual(student.getName(), names[i]);
}

let student = myClass.getStudentById(-1);
assert.strictEqual(student, null);
let student2 = myClass.getStudentById(100);
assert.strictEqual(student2, null);
});

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

student.setName(123);
assert.strictEqual(student.getName(), '');

for(let name in names){
student.setName(name);
assert.strictEqual(student.getName(), name);
}
});

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

for(let name in names){
student.setName(name);
assert.strictEqual(student.getName(), name);
}
});