Skip to content

Commit 5510977

Browse files
committed
done
1 parent e477a66 commit 5510977

File tree

6 files changed

+132
-0
lines changed

6 files changed

+132
-0
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Test Code
2+
on:
3+
push:
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- run: npm i jsverify
11+
- run: node code.test.js

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ this.
2020

2121
What is the time complexity of your implementation (worst-case $\Theta$)? Add
2222
your answer, including your reasoning, to this markdown file.
23+
24+
### Analysis
25+
26+
Since comparisons take constant time and we consider n elements of the array the complexity is $\Theta(n)$

code.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var async = require("async");
2+
3+
//sources: queried chat gpt what function in the async library would
4+
//be useful for counting matches in an array and it suggested "each". Then I read the docs for the rest.
5+
function count(a, k) {
6+
var m = 0;
7+
8+
async.each(
9+
a,
10+
(v, callback) => {
11+
if (v == k) { m++; }
12+
callback();
13+
}
14+
);
15+
16+
return m;
17+
}

code.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fs = require('fs');
2+
const jsc = require('jsverify');
3+
4+
eval(fs.readFileSync('code.js')+'');
5+
6+
const testSum =
7+
jsc.forall("array nat","nat", function(arr, key) {
8+
return JSON.stringify(count(arr, key)) == JSON.stringify(syncCount(arr, key));
9+
});
10+
11+
jsc.assert(testSum);
12+
13+
function syncCount(a, k) {
14+
var m = 0;
15+
for (var i = 0; i < a.length; i++) {
16+
if (a[i] == k) { m++; }
17+
}
18+
return m;
19+
}

package-lock.json

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"dependencies": {
3+
"async": "^3.2.6",
4+
"fs": "^0.0.1-security",
5+
"jsverify": "^0.8.4"
6+
}
7+
}

0 commit comments

Comments
 (0)