Skip to content
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
69 changes: 46 additions & 23 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
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");
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
});

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

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
});
const test = require('node:test');
const assert = require('assert');
const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
const mc = new MyClass();
const st = new Student();
assert.strictEqual(mc.addStudent(mc), -1); // not Student class
assert.strictEqual(mc.addStudent(st), 0); // 1 students
assert.strictEqual(mc.addStudent(st), 1); // 2 students
});

test("Test MyClass's getStudentById", () => {
const mc = new MyClass();

const st1 = new Student();
st1.setName("st1");
const st2 = new Student();
st2.setName("st2");
mc.addStudent(st1);
mc.addStudent(st2);

assert.strictEqual(mc.getStudentById(-1), null); // id < 0
assert.strictEqual(mc.getStudentById(2), null); // id >= length
assert.strictEqual(mc.getStudentById(0), st1); // st1
assert.strictEqual(mc.getStudentById(1), st2); // st2
});

test("Test Student's setName", () => {
const st1 = new Student();
st1.setName("st1");
const st2 = new Student();
st2.setName(1);

assert.strictEqual(st1.name, "st1"); // st1
assert.strictEqual(st2.name, undefined); // st2 not a string
});

test("Test Student's getName", () => {
const st1 = new Student();
st1.setName("st1");
const st2 = new Student();

assert.strictEqual(st1.getName(), "st1"); // st1
assert.strictEqual(st2.getName(), ''); // st2
});