Skip to content

[LAB7] 510558017 #601

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 38 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2233c14
fix: improve workflows
AlaRduTP Mar 13, 2024
e2b8057
fix: scripts/rebase-all.sh will fail due to too frequent remote opera…
AlaRduTP Mar 13, 2024
8336df3
feat: lab2
AlaRduTP Mar 13, 2024
0f5c5dd
feat: merge-all
AlaRduTP Mar 13, 2024
5fa8ffe
remove: create-branches.sh
AlaRduTP Mar 20, 2024
354fae7
feat: auto resolve conflicts when merging
AlaRduTP Mar 20, 2024
e49fa08
feat: improve GitHub workflows
AlaRduTP Mar 20, 2024
c895269
feat: lab3
AlaRduTP Mar 20, 2024
22a9521
feat: an easy check for changed files
AlaRduTP Mar 20, 2024
15ca1a7
doc: detailed steps of syncing fork
AlaRduTP Mar 20, 2024
dd650d8
fix: remove trailing whitespace
AlaRduTP Mar 20, 2024
cee6631
feat: add node_modules into gitignore
AlaRduTP Mar 27, 2024
ffbfbd7
feat: lab4
AlaRduTP Mar 27, 2024
5ee9d55
Add lab5
YingMuo Apr 17, 2024
86b3714
Fix github action
YingMuo Apr 17, 2024
c27f68f
Fix README.md
YingMuo Apr 17, 2024
419ed6d
fix: gh-script syntax error
AlaRduTP Apr 17, 2024
41cc403
add: lab6
YingMuo Apr 24, 2024
9777d36
feat: lab6
YingMuo Apr 24, 2024
110400a
fix: lab6
YingMuo Apr 24, 2024
eae2c35
fix: lab6
YingMuo Apr 24, 2024
2063787
Fix: lab6
YingMuo Apr 24, 2024
a2f55d5
Add: lab7
YingMuo May 1, 2024
56585b1
Fix: lab7
YingMuo May 1, 2024
7a945c9
Fix: lab7, angr not installed
YingMuo May 1, 2024
bb5fb3d
feat: add hw4
TaiYou-TW May 30, 2024
b88ef9e
fix: wrong days for hw4 leap year
TaiYou-TW May 30, 2024
3a9853d
Update lab-autograding.yml
as10968574 Jun 11, 2024
3e3e824
Update sol.py
as10968574 Jun 11, 2024
b1047d3
Merge branch '510558017' into lab7
as10968574 Jun 11, 2024
073a33d
Update lab-autograding.yml
as10968574 Jun 24, 2024
6ae4b02
Delete hw4 directory
as10968574 Jun 24, 2024
2a7f461
Update sol.py
as10968574 Jun 24, 2024
fc665fc
Update sol.py
as10968574 Jun 24, 2024
c89d575
Update sol.py
as10968574 Jun 24, 2024
9c5a2a1
Update sol.py
as10968574 Jun 24, 2024
975b238
Update sol.py
as10968574 Jun 24, 2024
35cb62e
Update sol.py
as10968574 Jun 24, 2024
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
Prev Previous commit
Next Next commit
feat: lab2
  • Loading branch information
AlaRduTP committed Mar 13, 2024
commit 8336df355115175597ef649f2a6a04db8ed64a82
26 changes: 26 additions & 0 deletions .github/workflows/lab2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: lab2 autograding

on:
pull_request:
types: [labeled, synchronize, opened, reopened, ready_for_review]

jobs:
build:
if: contains(github.event.pull_request.labels.*.name, 'lab2')
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: |
cd lab2
./validate.sh
22 changes: 22 additions & 0 deletions lab2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Lab2

## 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 it. (But remember don't commit them on GitHub)

## Requirement

1. Write test cases in `main_test.js` and achieve 100% code coverage. Remember to use Mock, Spy, or Stub when necessary, you need to at least use one of them in your test cases. (100%)

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

1. you modify other files to achieve requirements.
2. you can't pass all CI on your PR.

## 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.
81 changes: 81 additions & 0 deletions lab2/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const fs = require('fs');
const util = require('util');
const readFile = util.promisify(fs.readFile);

class MailSystem {
write(name) {
console.log('--write mail for ' + name + '--');
const context = 'Congrats, ' + name + '!';
return context;
}

send(name, context) {
console.log('--send mail to ' + name + '--');
// Interact with mail system and send mail
// random success or failure
const success = Math.random() > 0.5;
if (success) {
console.log('mail sent');
} else {
console.log('mail failed');
}
return success;
}
}

class Application {
constructor() {
this.people = [];
this.selected = [];
this.mailSystem = new MailSystem();
this.getNames().then(([people, selected]) => {
this.people = people;
this.selected = selected;
});
}

async getNames() {
const data = await readFile('name_list.txt', 'utf8');
const people = data.split('\n');
const selected = [];
return [people, selected];
}

getRandomPerson() {
const i = Math.floor(Math.random() * this.people.length);
return this.people[i];
}

selectNextPerson() {
console.log('--select next person--');
if (this.people.length === this.selected.length) {
console.log('all selected');
return null;
}
let person = this.getRandomPerson();
while (this.selected.includes(person)) {
person = this.getRandomPerson();
}
this.selected.push(person);
return person;
}

notifySelected() {
console.log('--notify selected--');
for (const x of this.selected) {
const context = this.mailSystem.write(x);
this.mailSystem.send(x, context);
}
}
}

// const app = new Application();
// app.selectNextPerson();
// app.selectNextPerson();
// app.selectNextPerson();
// app.notifySelected();

module.exports = {
Application,
MailSystem,
};
6 changes: 6 additions & 0 deletions lab2/main_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const test = require('node:test');
const assert = require('assert');
const { Application, MailSystem } = require('./main');

// TODO: write your tests here
// Remember to use Stub, Mock, and Spy when necessary
38 changes: 38 additions & 0 deletions lab2/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Check for unwanted files
for file in *; do
if [[ $file != "main.js" && $file != "main_test.js" && $file != "README.md" && $file != "validate.sh" ]]; then
echo "[!] Unwanted file detected: $file."
exit 1
fi
done

node=$(which node)
test_path="${BASH_SOURCE[0]}"
solution_path="$(realpath .)"
tmp_dir=$(mktemp -d -t lab2-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: