Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7cc722c
lab0.js prints hello world!
sa-llo Mar 5, 2025
50fde29
changed print from "Hello World!" --> "Hello world!"
sa-llo Mar 5, 2025
0dac48f
Merge pull request #58 from sa-llo/313704803
YingMuo Mar 5, 2025
b40d0b0
feat: lab1
AxelHowe Mar 5, 2025
e42132d
100% test coverage added to lab1 > main_tests.js
sa-llo Mar 10, 2025
61c8868
Merge pull request #118 from sa-llo/313704803
AxelHowe Mar 12, 2025
a003625
feat: lab2
AxelHowe Mar 12, 2025
dd53f54
100% test cov. in lab2 main_test.js
sa-llo Mar 16, 2025
daa5824
Merge pull request #171 from sa-llo/313704803
AxelHowe Mar 18, 2025
94da6b0
feat: lab3
CTHua Mar 20, 2025
bcfec80
feat: lab4
CTHua Mar 27, 2025
cd0a090
feat: lab5
YingMuo Apr 23, 2025
f513672
fix: autograding
YingMuo Apr 25, 2025
cb8fec6
updated antiasan.c to complete the assigment requirements
sa-llo Apr 27, 2025
a6a96d7
changed file again, validate.sh gives me pass but not autograder in g…
sa-llo Apr 27, 2025
489cd1b
changed file again, validate.sh gives me pass but not autograder in g…
sa-llo Apr 27, 2025
91133b3
changed file again, validate.sh gives me pass but not autograder in g…
sa-llo Apr 27, 2025
e5a07ed
changed file again, validate.sh gives me pass but not autograder in g…
sa-llo Apr 27, 2025
f8a3323
validator.sh and autograder in git do not match - trying to push code…
sa-llo Apr 27, 2025
20f907e
Merge pull request #370 from sa-llo/lab5
YingMuo May 1, 2025
dae9bde
feat: lab6
YingMuo May 1, 2025
c4f0e6c
testing first try of solution - modification of llvm-pass.so.cc. 100%…
sa-llo May 5, 2025
e53593f
testing second try of solution - modification of llvm-pass.so.cc. 100…
sa-llo May 5, 2025
59a6fcc
testing third try of solution - modification of llvm-pass.so.cc. 100%…
sa-llo May 5, 2025
06de040
completed all three requirements. Commented code. All code written in…
sa-llo May 5, 2025
23c1fd3
completed all three requirements. Commented code. All code written in…
sa-llo May 5, 2025
5ce876a
completed all three requirements. Commented code. All code written in…
sa-llo May 5, 2025
4fb7ba9
Merge pull request #452 from sa-llo/lab6
YingMuo May 8, 2025
aa48f94
feat: lab8
YingMuo May 15, 2025
04b26b8
tried solving it, still failed using validate script
sa-llo May 17, 2025
940d398
tried solving it, still failed using validate script
sa-llo May 17, 2025
c16e0ee
tried solving it, still failed using validate script
sa-llo May 17, 2025
be02417
tried solving it, still failed using validate script
sa-llo May 17, 2025
963b399
tried solving it, still failed using validate script
sa-llo May 17, 2025
2f2b6d7
tried solving it, still failed using validate script
sa-llo May 17, 2025
2318013
tried solving it, still failed using validate script
sa-llo May 17, 2025
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
5 changes: 4 additions & 1 deletion .github/workflows/lab-autograding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ jobs:
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number });
const changedFiles = files.data.map((file) => file.filename);
const allowedFileRegex = /^lab\d+\/main_test.js$/;
const specialChangedFiles = ["lab0/lab0.js"];
const specialChangedFiles = ["lab0/lab0.js", "lab5/antiasan.c", "lab6/llvm-pass.so.cc", "lab8/solve.py"];
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file)))) {
core.setFailed('The PR contains changes to files other than the allowed files.');
}
return labNumber;
- name: Grading
run: |
cd lab${{ steps.lab.outputs.result }}
if [ ${{ steps.lab.outputs.result }} -eq 6 ]; then
sudo apt install -y llvm-14
fi
./validate.sh
1 change: 1 addition & 0 deletions lab0/lab0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello world!")
22 changes: 22 additions & 0 deletions lab1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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 it. (But remember don't commit them on GitHub)

## Requirement

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.

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.
55 changes: 55 additions & 0 deletions lab1/main.js
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 };
23 changes: 23 additions & 0 deletions lab1/main_test.js
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");
});
38 changes: 38 additions & 0 deletions lab1/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 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%, should be 100%."
exit 1
else
echo "[V] Coverage is 100%, great job!"
fi
fi

rm -rf $tmp_dir

exit 0

# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2:
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:
29 changes: 29 additions & 0 deletions lab3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Lab3

## 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)

## Preparation (Important!!!)

1. Sync fork on GitHub
2. `git checkout -b lab3` (**NOT** your student ID !!!)

## Requirement

1. (40%) Write test cases in `main_test.js` and achieve 100% code coverage.
2. (30%) For each function, parameterize their testcases to test the error-results.
3. (30%) For each function, use at least 3 parameterized testcases to test the non-error-results.

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. 312XXXXXX, 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.
34 changes: 34 additions & 0 deletions lab3/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Calculator {
exp(x) {
if (!Number.isFinite(x)) {
throw Error('unsupported operand type');
}
const result = Math.exp(x);
if (result === Infinity) {
throw Error('overflow');
}
return result;
}

log(x) {
if (!Number.isFinite(x)) {
throw Error('unsupported operand type');
}
const result = Math.log(x);
if (result === -Infinity) {
throw Error('math domain error (1)');
}
if (Number.isNaN(result)) {
throw Error('math domain error (2)');
}
return result;
}
}

// const calculator = new Calculator();
// console.log(calculator.exp(87));
// console.log(calculator.log(48763));

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

// TODO: write your tests here
Loading
Loading