Skip to content
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

[LAB7] 311552066 #592

Closed
wants to merge 20 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
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/
Binary file added hw4/311552066.docx
Binary file not shown.
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] = 29;
else
daysIn[2] = 28;

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"
}
49 changes: 49 additions & 0 deletions hw4/tests/calculator_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const assert = require('assert');
const { test } = require('node:test');
const Calculator = require('../src/calculator');

function testError(param, expectedError) {
assert.throws(() => {
Calculator.main(...param);
}, new Error(expectedError));
}
function testOutput(param, expectedOutput) {
assert.strictEqual(Calculator.main(...param),expectedOutput);
}

test('invalid', (t) => {
testError([0, 1, 1, 1, 1],"invalid month1");
testError([13, 1, 1, 1, 1],"invalid month1");

testError([1, 0, 1, 1, 1],"invalid day1");
testError([1, 32, 1, 1, 1],"invalid day1");

testError([1, 1, 0, 1, 1],"invalid month2");
testError([1, 1, 13, 1, 1],"invalid month2");

testError([1, 1, 1, 0, 1],"invalid day2");
testError([1, 1, 1, 32, 1],"invalid day2");

testError([1, 1, 1, 1, 0],"invalid year");
testError([1, 1, 1, 1, 10001],"invalid year");

testError([1, 2, 1, 1, 1],"day1 must be less than day2 if month1 is equal to month2");

testError([2, 1, 1, 1, 1],"month1 must be less than month2");

testOutput([1, 1, 1, 1, 1],0);
testOutput([12, 1, 12, 1, 1],0);
testOutput([1, 31, 1, 31, 1],0);
testOutput([1, 1, 1, 1, 10000],0);
testOutput([1, 31, 3, 31, 1],59);
testOutput([1, 31, 3, 31, 4],60);
testOutput([1, 31, 3, 31, 100],59);
testOutput([1, 31, 3, 31, 400],60);
testOutput([1, 31, 2, 1, 1],1);
testOutput([1, 10, 2, 20, 1],41);





});
1 change: 1 addition & 0 deletions lab4/main_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const puppeteer = require('puppeteer');

(async () => {

// Launch the browser and open a new blank page
const browser = await puppeteer.launch();
const page = await browser.newPage();
Expand Down
2 changes: 2 additions & 0 deletions lab7/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
login
login.o
11 changes: 11 additions & 0 deletions lab7/sol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import angr, sys
proj = angr.Project('./login')
init_state = proj.factory.entry_state()
simulation = proj.factory.simgr(init_state)
def success_condition(state):
return b"Login successful" in state.posix.dumps(sys.stdout.fileno())
def fail_condition(state):
return b"Login failed" in state.posix.dumps(sys.stdout.fileno())
simulation.explore(find=success_condition, avoid=fail_condition)
solution = simulation.found[0]
print(solution.posix.dumps(sys.stdin.fileno()))
Loading