forked from SQLab/112-spring-software-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Description | ||
|
||
<!-- 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 meaningful message for PR, as well as its commits | ||
- [ ] From your specific branch (***not master***) 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: lab1 | ||
|
||
on: | ||
pull_request: | ||
types: [labeled] | ||
|
||
jobs: | ||
build: | ||
if: ${{ github.event.label.name == 'lab1' }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-22.04] | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v1 | ||
with: | ||
fetch-depth: 1 | ||
- name: dependency (ubuntu) | ||
run: | | ||
curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash - &&\ | ||
sudo apt-get install -y nodejs | ||
- name: grading | ||
run: | | ||
echo "cd lab1" | ||
cd lab1 | ||
./validate.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# 112-spring-software-testing | ||
|
||
Labs for NYCU software testing course in 112 spring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Lab1 | ||
|
||
## 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.` | ||
|
||
## 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%) | ||
|
||
You can run `validate.sh` in your local to test if you satisfy the requirements. | ||
|
||
Please note that you must not alter files other than `main_test.js`. You will get 0 points if you modify other files to achieve requirements. | ||
|
||
## Submission | ||
|
||
You need to open a pull request to your branch (e.g. 311XXXXXX, your student number) and contain the code that satisfies the abovementioned requirements. | ||
|
||
Moreover, please submit the URL of your PR to E3. Your submission will only be accepted when you present at both places. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// NOTICE: DO NOT MODIFY THE CODE IN THIS FILE | ||
// But you can uncomment code below and run this file to understand how to use the classes | ||
|
||
class MyClass { | ||
constructor() { | ||
this.students = []; | ||
} | ||
|
||
addStudent(student) { | ||
if (!(student instanceof Student)) { | ||
return -1; | ||
} | ||
this.students.push(student); | ||
return this.students.length - 1; | ||
} | ||
|
||
getStudentById(id) { | ||
if (id < 0 || id >= this.students.length) { | ||
return null; | ||
} | ||
return this.students[id]; | ||
} | ||
} | ||
|
||
class Student { | ||
constructor() { | ||
this.name = undefined; | ||
} | ||
|
||
setName(userName) { | ||
if (typeof userName !== 'string') { | ||
return; | ||
} | ||
this.name = userName; | ||
} | ||
|
||
getName() { | ||
if (this.name === undefined) { | ||
return ''; | ||
} | ||
return this.name; | ||
} | ||
} | ||
|
||
// const myClass = new MyClass(); | ||
// 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(); | ||
// console.log('[+] Added student with id: %d, name: %s', newStudentId, newStudentName); | ||
// }); | ||
|
||
module.exports = { MyClass, Student }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
node=$(which node) | ||
test_path="${BASH_SOURCE[0]}" | ||
solution_path="$(realpath .)" | ||
tmp_dir=$(mktemp -d -t lab1-XXXXXXXXXX) | ||
|
||
cd $tmp_dir | ||
|
||
rm -rf * | ||
cp $solution_path/*.js . | ||
result=$($node --test --experimental-test-coverage) ; ret=$? | ||
if [ $ret -ne 0 ] ; then | ||
echo "[!] testing fails" | ||
exit 1 | ||
else | ||
coverage=$(echo "$result" | grep 'all files' | awk -F '|' '{print $2}' | sed 's/ //g') | ||
if (( $(echo "$coverage < 100" | bc -l) )); then | ||
echo "[!] Coverage is only $coverage%" | ||
exit 1 | ||
else | ||
echo "[V] Coverage is 100%" | ||
fi | ||
fi | ||
|
||
rm -rf $tmp_dir | ||
|
||
exit 0 | ||
|
||
# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2: |