Skip to content

[LAB1] 312552050 #35

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

Merged
merged 2 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
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
});