From 6658a836390998d3b0705f825d60e12d7ed25e21 Mon Sep 17 00:00:00 2001 From: Nodari Chkuaselidze Date: Tue, 13 Jun 2023 14:24:14 +0400 Subject: [PATCH] pkg: add ci and minimal test. --- .eslintrc.json | 3 ++- .github/workflows/build.yml | 40 +++++++++++++++++++++++++++++++++++++ package.json | 2 +- test/heap-test.js | 23 +++++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 test/heap-test.js diff --git a/.eslintrc.json b/.eslintrc.json index 4db51ca..3de38b4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -39,7 +39,8 @@ }, "rules": { "max-len": "off", - "prefer-arrow-callback": "off" + "prefer-arrow-callback": "off", + "no-return-assign": "off" } } ], diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..bb13805 --- /dev/null +++ b/.github/workflows/build.yml @@ -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 diff --git a/package.json b/package.json index 7caaf2e..1f7187e 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "author": "Christopher Jeffrey ", "main": "./lib/bheep.js", "scripts": { - "lint": "eslint lib/ test/ || exit 0", + "lint": "eslint lib/ test/", "test": "bmocha --reporter spec test/*-test.js" }, "dependencies": { diff --git a/test/heap-test.js b/test/heap-test.js new file mode 100644 index 0000000..26fe20d --- /dev/null +++ b/test/heap-test.js @@ -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); + }); +});