Skip to content

Commit

Permalink
fix(tests): cover math results formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Oct 15, 2019
1 parent e85b1b2 commit a9e56dc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/tslint.cc.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"no-irregular-whitespace": true,
"no-magic-numbers": [
true,
-1, 0,
-3, -2, -1, 0,
1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 20, 30, 40, 50, 60, 70, 80, 90,
100
Expand Down
7 changes: 6 additions & 1 deletion test/entity/base/TestDataEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { DataEntity } from '../../../src/entity/base/DataEntity';
import { describeLeaks, itLeaks } from '../../helpers/async';

class TestEntity extends DataEntity<string> {
public getDataStr() {
return this.dataStr;
}

public setDataStr(str: string) {
this.dataStr = str;
this.labelStr = str;
Expand Down Expand Up @@ -34,7 +38,8 @@ describeLeaks('base data entity', async () => {
labels: {},
});
entity.syncStr();
expect(entity.get('foo')).to.equal('bar');
expect(entity.getDataStr()).to.include('foo');
expect(entity.getDataStr()).to.include('bar');
});

itLeaks('should check for key existence');
Expand Down
22 changes: 19 additions & 3 deletions test/utils/TestMath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import { bignumber, complex, evaluate, fraction, matrix, range, unit } from 'mathjs';

import { clamp, formatResult, ResultFormatOptions } from '../../src/utils/Math';

Expand Down Expand Up @@ -59,7 +60,11 @@ describe('math utils', () => {
}
});

it('should format date results');
it('should format date results', () => {
const d = new Date();
expect(formatResult(d, TEST_SCOPE, TEST_OPTIONS)).to.include(d.getFullYear());
});

it('should recursive over array results', () => {
expect(formatResult([], TEST_SCOPE, TEST_OPTIONS)).to.equal('');
expect(formatResult([true, false], TEST_SCOPE, TEST_OPTIONS)).to.equal('true,false');
Expand All @@ -77,8 +82,19 @@ describe('math utils', () => {
expect(formatResult(/foo/, TEST_SCOPE, TEST_OPTIONS)).to.equal('regexp');
});

it('should format math results');
it('should format math result sets');
it('should format math results', () => {
expect(formatResult(bignumber(3), TEST_SCOPE, TEST_OPTIONS)).to.equal('3');
expect(formatResult(complex(3, -2), TEST_SCOPE, TEST_OPTIONS)).to.equal('3 - 2i');
expect(formatResult(fraction(1, 3), TEST_SCOPE, TEST_OPTIONS)).to.equal('1/3');
expect(formatResult(matrix([[1, 2], [3, 4]]), TEST_SCOPE, TEST_OPTIONS)).to.equal('[[1, 2], [3, 4]]');
expect(formatResult(range(1, 4), TEST_SCOPE, TEST_OPTIONS)).to.equal('[1, 2, 3]');
expect(formatResult(unit(10, 'm'), TEST_SCOPE, TEST_OPTIONS)).to.equal('10 m');
});

it('should format math result sets', () => {
expect(formatResult(evaluate('1+1 \n 2+2'), TEST_SCOPE, TEST_OPTIONS)).to.equal('2,4');
});

it('should format math nodes');
});
});

0 comments on commit a9e56dc

Please sign in to comment.