Skip to content

Commit

Permalink
Migrate to node built-in test runner (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
102 authored Oct 16, 2023
1 parent c268255 commit 44a2355
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 34 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ name: Node.js CI

on:
push:
branches: [ master ]
branches: [main]
pull_request:
branches: [ master ]
branches: [main]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm test
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "MIT",
"type": "module",
"scripts": {
"test": "node test.js"
"test": "node --test"
},
"keywords": [
"function",
Expand Down
37 changes: 15 additions & 22 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
import assert from "node:assert";
import { test } from "node:test";
import { F } from "./index.js";

let cases = [
[0n, 0n, 0n, 0n],
[0n, 1n, 0n, 1n],
[0n, 2n, 0n, 2n],
[0n, 2n, 2n, 4n],
[0n, 5n, 6n, 11n],
[1n, 4n, 7n, 759n],
[1n, 8n, 8n, 2550n],
[1n, 9n, 14n, 180208n],
[0n, 0n, 0n, 0n],
[0n, 1n, 0n, 1n],
[0n, 2n, 0n, 2n],
[0n, 2n, 2n, 4n],
[0n, 5n, 6n, 11n],
[1n, 4n, 7n, 759n],
[1n, 8n, 8n, 2550n],
[1n, 9n, 14n, 180208n],
[1n, 14n, 14n, 262128n],
[2n, 1n, 1n, 8n],
[2n, 5n, 1n, 440n],
[2n, 1n, 2n, 10228n],
[2n, 2n, 2n, 15569256417n],
[2n, 1n, 1n, 8n],
[2n, 5n, 1n, 440n],
[2n, 1n, 2n, 10228n],
[2n, 2n, 2n, 15569256417n],
];

cases.forEach(([n, x, y, expected]) => {
try {
test(`{ n: ${n}, x: ${x}, y: ${y} } ⇒ ${expected}`, () => {
assert.strictEqual(F(n, x, y), expected);
console.log("✓", { n, x, y }, "⇒", expected);
} catch (error) {
if (error instanceof assert.AssertionError) {
console.log("X", { n, x, y }, "⇒", expected, error.message);
process.exitCode = 1;
} else {
throw error;
}
}
});
});

0 comments on commit 44a2355

Please sign in to comment.