Skip to content

[LAB1] 313551150 #64

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 4 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lab0/lab0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello world!");
55 changes: 46 additions & 9 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 student = new Student();

// Valid student case
const studentId = myClass.addStudent(student);
assert.strictEqual(studentId, 0);

// Invalid input case
const invalidId = myClass.addStudent({});
assert.strictEqual(invalidId, -1);
});

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

const studentId = myClass.addStudent(student);

// Valid retrieval
const retrievedStudent = myClass.getStudentById(studentId);
assert.ok(retrievedStudent instanceof Student);
assert.strictEqual(retrievedStudent.getName(), "John");

// Invalid ID cases
assert.strictEqual(myClass.getStudentById(-1), null);
assert.strictEqual(myClass.getStudentById(101), null);
});


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

// Valid name setting
student.setName("Jane");
assert.strictEqual(student.getName(), "Jane");

// Invalid input cases
student.setName(123);
assert.strictEqual(student.getName(), "Jane"); // Should not change

student.setName(null);
assert.strictEqual(student.getName(), "Jane"); // Should not change
});

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

// Default value case
assert.strictEqual(student.getName(), '');

// After setting a valid name
student.setName("Alice");
assert.strictEqual(student.getName(), "Alice");
});