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: add hw4
  • Loading branch information
TaiYou-TW committed May 30, 2024
commit bb5fb3d6af8311207b7a8d78a65b8a5133d95780
2 changes: 2 additions & 0 deletions hw4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
reports/
.stryker-tmp/
15 changes: 15 additions & 0 deletions hw4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# HW4

You can install package through:

```shell
npm i
```

After finish your test code in `tests/calculator_test.js`, you can run `Stryker` by:

```shell
npm run mutate
```

to get your mutation testing result.
2,661 changes: 2,661 additions & 0 deletions hw4/package-lock.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions hw4/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "hw4",
"version": "1.0.0",
"description": "software testing hw4",
"main": "src/calculator.js",
"scripts": {
"test": "node --test",
"mutate": "npx stryker run"
},
"dependencies": {},
"devDependencies": {
"@stryker-mutator/core": "^8.2.6"
},
"license": "MIT"
}
54 changes: 54 additions & 0 deletions hw4/src/calculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class Calculator {
static main(month1, day1, month2, day2, year) {
if (month1 < 1 || month1 > 12) {
throw new Error("invalid month1");
}
if (month2 < 1 || month2 > 12) {
throw new Error("invalid month2");
}
if (day1 < 1 || day1 > 31) {
throw new Error("invalid day1");
}
if (day2 < 1 || day2 > 31) {
throw new Error("invalid day2");
}
if (year < 1 || year > 10000) {
throw new Error("invalid year");
}
if (month1 === month2 && day1 > day2) {
throw new Error("day1 must be less than day2 if month1 is equal to month2");
}
if (month1 > month2) {
throw new Error("month1 must be less than month2");
}

return this.#calculate(month1, day1, month2, day2, year);
}

static #calculate(month1, day1, month2, day2, year) {
let numDays;

if (month2 === month1) {
numDays = day2 - day1;
} else {
// ignore 0 index
let daysIn = [0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if (this.#isLeapYear(year))
daysIn[2] = 28;
else
daysIn[2] = 29;

numDays = day2 + (daysIn[month1] - day1);

for (let i = month1 + 1; i <= month2 - 1; i++)
numDays += daysIn[i];
}
return numDays;
}

static #isLeapYear(year) {
return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
}
}

module.exports = Calculator;
13 changes: 13 additions & 0 deletions hw4/stryker.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"_comment": "This config was generated using 'stryker init'. Please take a look at: https://stryker-mutator.io/docs/stryker-js/configuration/ for more information.",
"packageManager": "npm",
"reporters": [
"html",
"clear-text",
"progress"
],
"testRunner": "command",
"testRunner_comment": "Take a look at (missing 'homepage' URL in package.json) for information about the command plugin.",
"coverageAnalysis": "off"
}
6 changes: 6 additions & 0 deletions hw4/tests/calculator_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const assert = require('assert');
const { test } = require('node:test');

const Calculator = require('../src/calculator');

// TODO: write your test cases here to kill mutants