Skip to content

Commit a9e56dc

Browse files
committed
fix(tests): cover math results formatting
1 parent e85b1b2 commit a9e56dc

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

config/tslint.cc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"no-irregular-whitespace": true,
8787
"no-magic-numbers": [
8888
true,
89-
-1, 0,
89+
-3, -2, -1, 0,
9090
1, 2, 3, 4, 5, 6, 7, 8, 9,
9191
10, 20, 30, 40, 50, 60, 70, 80, 90,
9292
100

test/entity/base/TestDataEntity.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { DataEntity } from '../../../src/entity/base/DataEntity';
44
import { describeLeaks, itLeaks } from '../../helpers/async';
55

66
class TestEntity extends DataEntity<string> {
7+
public getDataStr() {
8+
return this.dataStr;
9+
}
10+
711
public setDataStr(str: string) {
812
this.dataStr = str;
913
this.labelStr = str;
@@ -34,7 +38,8 @@ describeLeaks('base data entity', async () => {
3438
labels: {},
3539
});
3640
entity.syncStr();
37-
expect(entity.get('foo')).to.equal('bar');
41+
expect(entity.getDataStr()).to.include('foo');
42+
expect(entity.getDataStr()).to.include('bar');
3843
});
3944

4045
itLeaks('should check for key existence');

test/utils/TestMath.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from 'chai';
2+
import { bignumber, complex, evaluate, fraction, matrix, range, unit } from 'mathjs';
23

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

@@ -59,7 +60,11 @@ describe('math utils', () => {
5960
}
6061
});
6162

62-
it('should format date results');
63+
it('should format date results', () => {
64+
const d = new Date();
65+
expect(formatResult(d, TEST_SCOPE, TEST_OPTIONS)).to.include(d.getFullYear());
66+
});
67+
6368
it('should recursive over array results', () => {
6469
expect(formatResult([], TEST_SCOPE, TEST_OPTIONS)).to.equal('');
6570
expect(formatResult([true, false], TEST_SCOPE, TEST_OPTIONS)).to.equal('true,false');
@@ -77,8 +82,19 @@ describe('math utils', () => {
7782
expect(formatResult(/foo/, TEST_SCOPE, TEST_OPTIONS)).to.equal('regexp');
7883
});
7984

80-
it('should format math results');
81-
it('should format math result sets');
85+
it('should format math results', () => {
86+
expect(formatResult(bignumber(3), TEST_SCOPE, TEST_OPTIONS)).to.equal('3');
87+
expect(formatResult(complex(3, -2), TEST_SCOPE, TEST_OPTIONS)).to.equal('3 - 2i');
88+
expect(formatResult(fraction(1, 3), TEST_SCOPE, TEST_OPTIONS)).to.equal('1/3');
89+
expect(formatResult(matrix([[1, 2], [3, 4]]), TEST_SCOPE, TEST_OPTIONS)).to.equal('[[1, 2], [3, 4]]');
90+
expect(formatResult(range(1, 4), TEST_SCOPE, TEST_OPTIONS)).to.equal('[1, 2, 3]');
91+
expect(formatResult(unit(10, 'm'), TEST_SCOPE, TEST_OPTIONS)).to.equal('10 m');
92+
});
93+
94+
it('should format math result sets', () => {
95+
expect(formatResult(evaluate('1+1 \n 2+2'), TEST_SCOPE, TEST_OPTIONS)).to.equal('2,4');
96+
});
97+
8298
it('should format math nodes');
8399
});
84100
});

0 commit comments

Comments
 (0)