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] 312551008 #4

Closed
wants to merge 4 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
7 changes: 5 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
## Description

<!-- You can check sample PR here: (remember delete this link when you create your PR) -->
<https://github.com/SQLab/112-spring-software-testing/pull/2>

<!-- Please briefly describe your change here -->

---

<!-- Please make sure you're satisfy and fill the following checkboxes -->
<!-- A good PR should include the following parts: -->

- [ ] A clear title
- [ ] A clear title (name your pr "[LAB{lab_number}] {your_student_id}")
- [ ] A meaningful message for PR, as well as its commits
- [ ] From your specific branch (***not master***) merging to your branch
- [ ] From your specific branch (***not main or other's branch***) merging to your branch
- [ ] Excluding any irrelevant files, such as binaries, text files, or dot files
- [ ] Passing tests/CI
- [ ] Add proper label for this PR
3 changes: 1 addition & 2 deletions lab1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ In this lab, you will write unit tests for functions implemented in `main.js`. Y

## Requirement

1. Write test cases in `main_test.js` and achieve 100% code coverage. (90%)
2. Add a badge and make it show `passing` in `README.md` in the root folder. (10%)
1. Write test cases in `main_test.js` and achieve 100% code coverage. (100%)

You can run `validate.sh` in your local to test if you satisfy the requirements.

Expand Down
48 changes: 40 additions & 8 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,53 @@ 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();
// if student is not an instance of Student, return -1
assert.strictEqual(myClass.addStudent({}), -1);

// normal case
const names = ['John', 'Jane', 'Doe', 'Smith'];
names.forEach(name => {
const student = new Student();
student.setName(name);
const newStudentId = myClass.addStudent(student);
const newStudentName = myClass.getStudentById(newStudentId).getName();
assert.strictEqual(newStudentName, name);
});
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
// if id is less than 0, return null
assert.strictEqual(myClass.getStudentById(-1), null);

// normal case
const names = ['John', 'Jane', 'Doe', 'Smith'];
names.forEach(name => {
const student = new Student();
student.setName(name);
const newStudentId = myClass.addStudent(student);
const newStudent = myClass.getStudentById(newStudentId);
assert.strictEqual(student, newStudent);
});
// if id is greater than or equal to the length of students, return null
assert.strictEqual(myClass.getStudentById(names.length), null);
});

test("Test Student's setName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();
student.setName('John');
assert.strictEqual(student.getName(), 'John');
// Test if setName accepts only string
student.setName(123);
assert.strictEqual(student.getName(), 'John');
});

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();
// Test if getName returns empty string if name is undefined
assert.strictEqual(student.getName(), '');
// Test if getName returns the name set by setName
student.setName('John');
assert.strictEqual(student.getName(), 'John');
});