Skip to content

Commit

Permalink
pkg: add ci and minimal test.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Jun 13, 2023
1 parent e59329d commit 6658a83
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
},
"rules": {
"max-len": "off",
"prefer-arrow-callback": "off"
"prefer-arrow-callback": "off",
"no-return-assign": "off"
}
}
],
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build

on: [push, pull_request]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install dependencies
run: npm install --location=global bslint

- name: Lint
run: npm run lint

test:
name: Test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install dependencies
run: npm install

- name: Test
run: npm run test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "Christopher Jeffrey <[email protected]>",
"main": "./lib/bheep.js",
"scripts": {
"lint": "eslint lib/ test/ || exit 0",
"lint": "eslint lib/ test/",
"test": "bmocha --reporter spec test/*-test.js"
},
"dependencies": {
Expand Down
23 changes: 23 additions & 0 deletions test/heap-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const assert = require('bsert');
const Heap = require('../lib/bheep');

describe('Heap', function() {
it('should sort items in descending order', () => {
const comparator = (a, b) => b - a;
const N = 100;

const heap = new Heap(comparator);

for (let i = 0; i < N; i++)
heap.insert(i);

for (let i = 0; i < N; i++) {
const item = heap.shift();
assert.strictEqual(item, N - i - 1);
}

assert.strictEqual(heap.size(), 0);
});
});

0 comments on commit 6658a83

Please sign in to comment.