Units separated to their own block, and properly tested
This commit is contained in:
parent
71efdbe020
commit
452d7c155b
7 changed files with 100 additions and 19 deletions
48
test/unit/units.js
Normal file
48
test/unit/units.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
const u = require('../../src/units')
|
||||
|
||||
describe('Units', function() {
|
||||
|
||||
it('defaults', function() {
|
||||
// check that an empty config has the default units (and nothing more)
|
||||
const def = u.parse({})
|
||||
Object.keys(def).length.should.equal(3)
|
||||
def.u.should.equal(19)
|
||||
def.cx.should.equal(18)
|
||||
def.cy.should.equal(17)
|
||||
})
|
||||
|
||||
it('units', function() {
|
||||
// check that units can contain formulas, and reference each other
|
||||
const res = u.parse({
|
||||
units: {
|
||||
a: 'cx / 2',
|
||||
b: 'a + 1'
|
||||
}
|
||||
})
|
||||
Object.keys(res).length.should.equal(5)
|
||||
res.a.should.equal(9)
|
||||
res.b.should.equal(10)
|
||||
// also check that order matters, which it should
|
||||
u.parse.bind(this, {
|
||||
units: {
|
||||
a: 'b + 1',
|
||||
b: 'cx / 2'
|
||||
}
|
||||
}).should.throw()
|
||||
})
|
||||
|
||||
it('variables', function() {
|
||||
// check that variables work, and can override units
|
||||
const res = u.parse({
|
||||
units: {
|
||||
a: 'cx / 2',
|
||||
},
|
||||
variables: {
|
||||
a: 'u + 1'
|
||||
}
|
||||
})
|
||||
Object.keys(res).length.should.equal(4)
|
||||
res.a.should.equal(20)
|
||||
})
|
||||
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue