Skip to content

[LAB1] 312555001 #25

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 10 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
8 changes: 5 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
## 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
24 changes: 24 additions & 0 deletions .github/workflows/label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Automatic PR Labeler
on:
pull_request_target:
types: [opened, reopened, edited]

jobs:
labeler:
runs-on: ubuntu-latest
steps:
- name: Label PR
uses: actions/github-script@v5
with:
github-token: ${{ secrets.PAT }}
script: |
const { owner, repo, number: issue_number } = context.issue;
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number });
const title = pr.data.title;
const labRegex = /\[LAB(\d+)\]/i;

const match = title.match(labRegex);
if (match) {
const labelToAdd = 'lab' + match[1];
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [labelToAdd] });
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# 112-spring-software-testing

Labs for NYCU software testing course in 112 spring
![](https://github.com/YingMuo/112-spring-software-testing/actions/workflows/lab1.yml/badge.svg?branch=312555001)
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
53 changes: 45 additions & 8 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 names = ['John', 'Jane', 'Doe', 'Smith'];
var ctr = 0;
const clseeList = [];
names.forEach(name => {
const student = new Student();
student.setName(name);
const newStudentId = myClass.addStudent(student);
assert.strictEqual(newStudentId, ctr++);
clseeList.push(student);
});
assert.deepStrictEqual(myClass.students, clseeList);
const newStudentId = myClass.addStudent('Failed');
assert.strictEqual(newStudentId, -1);
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const names = ['John', 'Jane', 'Doe', 'Smith'];
var ctr = 0;
const clseeList = [];
names.forEach(name => {
const student = new Student();
student.setName(name);
const newStudentId = myClass.addStudent(student);
clseeList.push(student);
});
for (var i = 0; i < 4; ++i) {
assert.strictEqual(myClass.getStudentById(i), clseeList[i]);
}
const newStudentId = myClass.getStudentById(4);
assert.strictEqual(newStudentId, null);
const newStudentId2 = myClass.getStudentById(-1);
assert.strictEqual(newStudentId2, null);
const newStudentId3 = myClass.getStudentById("A");
assert.strictEqual(newStudentId3, undefined);
});

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

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();
const stduentName = student.getName();
assert.strictEqual(stduentName, '');
student.setName('Test');
const stduentName2 = student.getName();
assert.strictEqual(stduentName2, 'Test');
});
2 changes: 1 addition & 1 deletion lab1/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cd $tmp_dir

rm -rf *
cp $solution_path/*.js .
result=$($node --test --experimental-test-coverage) ; ret=$?
result=$($"node" --test --experimental-test-coverage) ; ret=$?
if [ $ret -ne 0 ] ; then
echo "[!] testing fails"
exit 1
Expand Down