-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |