Skip to content

[LAB1] 511558023 #24

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 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion lab1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Introduction

In this lab, you will write unit tests for functions implemented in `main.js`. You can learn how to use classes and functions in it by uncommenting the code in `main.js.` (But remember don't commit them on GitHub)
In this lab, you will write unit tests for functions implemented in `main.js`. You can learn how to use classes and functions in it by uncommenting the code in it. (But remember don't commit them on GitHub)

## Requirement

Expand Down
32 changes: 23 additions & 9 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,35 @@ 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();
assert.strictEqual(myclass.addStudent(""), -1);
assert.strictEqual(myclass.addStudent(student), 0);
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myclass = new MyClass();
const student1 = new Student();
myclass.addStudent(student1);
assert.strictEqual(myclass.getStudentById(-1), null);
assert.strictEqual(myclass.getStudentById(100), null);
assert.strictEqual(myclass.getStudentById(0), student1);
});

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

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