Skip to content

Commit

Permalink
mocha: add unit tests for formatNum()
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Francis <[email protected]>
Change-Id: I07fb6b479c93789f773857e15041c8c35ee8328a
  • Loading branch information
dennisfrancis committed Jan 27, 2025
1 parent 12d27a8 commit 99223b2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions browser/mocha_tests/Util.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference path="./refs/globals.ts"/>
/// <reference path="./helper/util.ts"/>
/// <reference path="../src/app/Util.ts"/>

var assert = require('assert');
Expand Down Expand Up @@ -31,4 +32,30 @@ describe('Util static members tests', function () {
});

});

describe('formatNum()', function() {
it('integer with no decimal places', function () {
assertFloat(Util.formatNum(5, 0), 5, 1e-5, '');
});

it('integer with 4 decimal places', function () {
assertFloat(Util.formatNum(5, 4), 5, 1e-5, '');
});

it('decimal with 1 decimal places no-round', function () {
assertFloat(Util.formatNum(5.30333333, 1), 5.3, 1e-5, '');
});

it('decimal with 4 decimal places no-round', function () {
assertFloat(Util.formatNum(5.30333333, 4), 5.3033, 1e-5, '');
});

it('decimal with 1 decimal places round', function () {
assertFloat(Util.formatNum(5.35333333, 1), 5.3, 1e-5, '');
});

it('decimal with 4 decimal places no-round', function () {
assertFloat(Util.formatNum(5.30335333, 4), 5.3034, 1e-5, '');
});
});
});

0 comments on commit 99223b2

Please sign in to comment.