1
0
Fork 0

start refactoring tests for speed

This commit is contained in:
Enoch Riese 2022-11-15 14:50:14 -06:00
parent 6c68b33f3e
commit d921cc700d
5 changed files with 251 additions and 403 deletions

View file

@ -631,7 +631,7 @@ export function __asNumber(value, param, method, log) {
value = Number(value) value = Number(value)
return value return value
} catch { } catch {
this.log.error( log.error(
`Called \`${method}(${param})\` but \`${param}\` is not a number nor can it be cast to one` `Called \`${method}(${param})\` but \`${param}\` is not a number nor can it be cast to one`
) )
} }

View file

@ -63,7 +63,6 @@ describe('Part', () => {
const part = { const part = {
name: 'test', name: 'test',
draft: ({ getId, part }) => { draft: ({ getId, part }) => {
console.log(getId)
id = getId() id = getId()
id = getId() id = getId()
id = getId() id = getId()

View file

@ -1,13 +1,13 @@
import chai from 'chai' import chai from 'chai'
import { round, Path, Point, Design } from '../src/index.mjs' import { round, Path, Point, Design } from '../src/index.mjs'
import { pathsProxy } from '../src/path.mjs'
const expect = chai.expect const expect = chai.expect
describe('Path', () => { describe('Path', () => {
describe('smurve', () => {
it('Should draw a smurve', () => { it('Should draw a smurve', () => {
const part = { const points = {}
name: 'test',
draft: ({ Point, points, Path, paths, part }) => {
points.from = new Point(10, 20) points.from = new Point(10, 20)
points.cp1 = new Point(40, 10) points.cp1 = new Point(40, 10)
points.cp2 = new Point(60, 30) points.cp2 = new Point(60, 30)
@ -15,275 +15,159 @@ describe('Path', () => {
points.scp2 = new Point(140, 10) points.scp2 = new Point(140, 10)
points.sto = new Point(170, 20) points.sto = new Point(170, 20)
paths.test = new Path() const test = new Path()
.move(points.from) .move(points.from)
.curve(points.cp1, points.cp2, points.to) .curve(points.cp1, points.cp2, points.to)
.smurve(points.scp2, points.sto) .smurve(points.scp2, points.sto)
return part expect(round(test.ops[2].cp1.x)).to.equal(120)
}, expect(round(test.ops[2].cp1.y)).to.equal(10)
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(round(pattern.parts[0].test.paths.test.ops[2].cp1.x)).to.equal(120)
expect(round(pattern.parts[0].test.paths.test.ops[2].cp1.y)).to.equal(10)
}) })
it('Should draw a smurve_', () => { it('Should draw a smurve_', () => {
const part = { const points = {}
name: 'test',
draft: ({ Point, points, Path, paths, part }) => {
points.from = new Point(10, 20) points.from = new Point(10, 20)
points.cp1 = new Point(40, 10) points.cp1 = new Point(40, 10)
points.cp2 = new Point(60, 30) points.cp2 = new Point(60, 30)
points.to = new Point(90, 20) points.to = new Point(90, 20)
points.sto = new Point(170, 20) points.sto = new Point(170, 20)
paths.test = new Path() const test = new Path()
.move(points.from) .move(points.from)
.curve(points.cp1, points.cp2, points.to) .curve(points.cp1, points.cp2, points.to)
.smurve_(points.sto) .smurve_(points.sto)
return part expect(round(test.ops[2].cp1.x)).to.equal(120)
}, expect(round(test.ops[2].cp1.y)).to.equal(10)
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(round(pattern.parts[0].test.paths.test.ops[2].cp1.x)).to.equal(120)
expect(round(pattern.parts[0].test.paths.test.ops[2].cp1.y)).to.equal(10)
}) })
it('Should log a warning when passing a non-Point to smurve()', () => { it('Should log a warning when passing a non-Point to smurve()', () => {
const part = { const points = {}
name: 'test',
draft: ({ Point, points, Path, paths, part }) => {
points.from = new Point(10, 20) points.from = new Point(10, 20)
points.cp1 = new Point(40, 10) points.cp1 = new Point(40, 10)
points.cp2 = new Point(60, 30) points.cp2 = new Point(60, 30)
points.to = new Point(90, 20) points.to = new Point(90, 20)
paths.test = new Path() let invalid = false
const messages = []
const log = { warning: (msg) => messages.push(msg) }
const test = new Path()
.__withLog(log)
.move(points.from) .move(points.from)
.curve(points.cp1, points.cp2, points.to) .curve(points.cp1, points.cp2, points.to)
.smurve('hi', 'there') .smurve('hi', 'there')
return part expect(messages.length).to.equal(2)
}, expect(messages[0]).to.equal('Called `Path.smurve(cp2, to)` but `to` is not a `Point` object')
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft()
expect(pattern.setStores[0].logs.warning.length).to.equal(2)
expect(pattern.setStores[0].logs.warning[0]).to.equal(
'Called `Path.smurve(cp2, to)` but `to` is not a `Point` object'
)
}) })
it('Should log a warning when passing a non-Point to smurve_()', () => { it('Should log a warning when passing a non-Point to smurve_()', () => {
const part = { let invalid = false
name: 'test', const messages = []
draft: ({ Path, paths, part }) => { const log = { warning: (msg) => messages.push(msg) }
paths.test = new Path().smurve_('hi') try {
const test = new Path().__withLog(log).smurve_('hi')
return part } catch {
}, } finally {
expect(messages.length).to.equal(1)
expect(messages[0]).to.equal('Called `Path.smurve_(to)` but `to` is not a `Point` object')
} }
const design = new Design({ parts: [part] }) })
const pattern = new design()
pattern.draft()
expect(pattern.setStores[0].logs.warning.length).to.equal(1)
expect(pattern.setStores[0].logs.warning[0]).to.equal(
'Called `Path.smurve_(to)` but `to` is not a `Point` object'
)
}) })
it('Should log a warning when passing a non-Path to the paths proxy', () => { it('Should log a warning when passing a non-Path to the paths proxy', () => {
const part = { let invalid = false
name: 'test', const messages = []
draft: ({ paths, part }) => { const log = { warning: (msg) => messages.push(msg) }
paths.test = 'Wriing code can get very lonely sometimes' const pathsObj = {}
const paths = pathsProxy(pathsObj, log)
paths.set(pathsObj, 'test', 'Writing code can get very lonely sometimes')
return part expect(messages.length).to.equal(2)
}, expect(messages[0]).to.equal('`paths.test` was set with a value that is not a `Path` object')
} expect(messages[1]).to.equal('Could not set `name` property on `paths.test`')
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft()
expect(pattern.setStores[0].logs.warning.length).to.equal(2)
expect(pattern.setStores[0].logs.warning[0]).to.equal(
'`paths.test` was set with a value that is not a `Path` object'
)
expect(pattern.setStores[0].logs.warning[1]).to.equal(
'Could not set `name` property on `paths.test`'
)
}) })
describe('offset', () => {
it('Should offset a line', () => { it('Should offset a line', () => {
const part = { const line = new Path().move(new Point(0, 0)).line(new Point(0, 40))
name: 'test', const offLine = line.offset(10)
draft: ({ paths, Path, Point, part }) => { const bbox = offLine.bbox()
paths.line = new Path().move(new Point(0, 0)).line(new Point(0, 40)) expect(bbox.bottomRight.x).to.equal(-10)
paths.offset = paths.line.offset(10) expect(bbox.bottomRight.y).to.equal(40)
return part
},
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(pattern.parts[0].test.paths.offset.bottomRight.x).to.equal(-10)
expect(pattern.parts[0].test.paths.offset.bottomRight.y).to.equal(40)
}) })
it('Should offset a curve', () => { it('Should offset a curve', () => {
const part = { const curve = new Path()
name: 'test',
draft: ({ paths, Path, Point, part }) => {
paths.curve = new Path()
.move(new Point(0, 0)) .move(new Point(0, 0))
.curve(new Point(0, 40), new Point(123, 34), new Point(23, 4)) .curve(new Point(0, 40), new Point(123, 34), new Point(23, 4))
paths.offset = paths.curve.offset(10) const offset = curve.offset(10)
return part const bbox = offset.bbox()
}, expect(round(bbox.bottomRight.x)).to.equal(72.18)
} expect(round(bbox.bottomRight.y)).to.equal(38.26)
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(round(pattern.parts[0].test.paths.offset.bottomRight.x)).to.equal(72.18)
expect(round(pattern.parts[0].test.paths.offset.bottomRight.y)).to.equal(38.26)
}) })
it('Should offset a curve where cp1 = start', () => { it('Should offset a curve where cp1 = start', () => {
const part = { const curve = new Path().move(new Point(0, 0))._curve(new Point(123, 34), new Point(23, 4))
name: 'test', const offset = curve.offset(10)
draft: ({ paths, Path, Point, part }) => { const bbox = offset.bbox()
paths.curve = new Path().move(new Point(0, 0))._curve(new Point(123, 34), new Point(23, 4)) expect(round(bbox.bottomRight.x)).to.equal(72.63)
paths.offset = paths.curve.offset(10) expect(round(bbox.bottomRight.y)).to.equal(26.47)
return part
},
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(round(pattern.parts[0].test.paths.offset.bottomRight.x)).to.equal(72.63)
expect(round(pattern.parts[0].test.paths.offset.bottomRight.y)).to.equal(26.47)
}) })
it('Should offset a curve where cp2 = end', () => { it('Should offset a curve where cp2 = end', () => {
const part = { const curve = new Path().move(new Point(0, 0)).curve_(new Point(40, 0), new Point(123, 34))
name: 'test', const offset = curve.offset(10)
draft: ({ paths, Path, Point, part }) => { const bbox = offset.bbox()
paths.curve = new Path().move(new Point(0, 0)).curve_(new Point(40, 0), new Point(123, 34)) expect(round(bbox.bottomRight.x)).to.equal(119.86)
paths.offset = paths.curve.offset(10) expect(round(bbox.bottomRight.y)).to.equal(43.49)
return part })
},
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(round(pattern.parts[0].test.paths.offset.bottomRight.x)).to.equal(119.86)
expect(round(pattern.parts[0].test.paths.offset.bottomRight.y)).to.equal(43.49)
}) })
describe('length', () => {
it('Should return the length of a line', () => { it('Should return the length of a line', () => {
const part = { const line = new Path().move(new Point(0, 0)).line(new Point(40, 0))
name: 'test', expect(line.length()).to.equal(40)
draft: ({ paths, Path, Point, part }) => {
paths.line = new Path().move(new Point(0, 0)).line(new Point(40, 0))
return part
},
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(pattern.parts[0].test.paths.line.length()).to.equal(40)
}) })
it('Should return the length of a curve', () => { it('Should return the length of a curve', () => {
const part = { const curve = new Path()
name: 'test',
draft: ({ paths, Path, Point, part }) => {
paths.curve = new Path()
.move(new Point(0, 0)) .move(new Point(0, 0))
.curve(new Point(0, 40), new Point(123, 34), new Point(23, 4)) .curve(new Point(0, 40), new Point(123, 34), new Point(23, 4))
.close() .close()
return part expect(round(curve.length())).to.equal(145.11)
}, })
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(round(pattern.parts[0].test.paths.curve.length())).to.equal(145.11)
}) })
it('Should return the rough length of a curve', () => { it('Should return the rough length of a curve', () => {
const part = { const curve = new Path()
name: 'test',
draft: ({ paths, Path, Point, part }) => {
paths.curve = new Path()
.move(new Point(0, 0)) .move(new Point(0, 0))
.curve(new Point(0, 50), new Point(100, 50), new Point(100, 0)) .curve(new Point(0, 50), new Point(100, 50), new Point(100, 0))
.close() .close()
return part expect(round(curve.roughLength())).to.equal(300)
},
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(round(pattern.parts[0].test.paths.curve.roughLength())).to.equal(300)
}) })
it('Should return the rough length of a line', () => { it('Should return the rough length of a line', () => {
const part = { const line = new Path().move(new Point(0, 0)).line(new Point(0, 50))
name: 'test', expect(round(line.roughLength())).to.equal(50)
draft: ({ paths, Path, Point, part }) => {
paths.line = new Path().move(new Point(0, 0)).line(new Point(0, 50))
return part
},
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(round(pattern.parts[0].test.paths.line.roughLength())).to.equal(50)
}) })
it('Should return the path start point', () => { it('Should return the path start point', () => {
const part = { const curve = new Path()
name: 'test',
draft: ({ paths, Path, Point, part }) => {
paths.curve = new Path()
.move(new Point(123, 456)) .move(new Point(123, 456))
.curve(new Point(0, 40), new Point(123, 34), new Point(23, 4)) .curve(new Point(0, 40), new Point(123, 34), new Point(23, 4))
.close() .close()
return part expect(curve.start().x).to.equal(123)
}, expect(curve.start().y).to.equal(456)
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(pattern.parts[0].test.paths.curve.start().x).to.equal(123)
expect(pattern.parts[0].test.paths.curve.start().y).to.equal(456)
}) })
it('Should return the path end point', () => { it('Should return the path end point', () => {
const part = { const curve = new Path()
name: 'test',
draft: ({ paths, Path, Point, part }) => {
paths.curve = new Path()
.move(new Point(123, 456)) .move(new Point(123, 456))
.curve(new Point(0, 40), new Point(123, 34), new Point(23, 4)) .curve(new Point(0, 40), new Point(123, 34), new Point(23, 4))
.close() .close()
return part expect(curve.end().x).to.equal(123)
}, expect(curve.end().y).to.equal(456)
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
expect(pattern.parts[0].test.paths.curve.end().x).to.equal(123)
expect(pattern.parts[0].test.paths.curve.end().y).to.equal(456)
}) })
it('Should calculate that path boundary', () => { it('Should calculate that path boundary', () => {
@ -810,24 +694,17 @@ describe('Path', () => {
}) })
it('Should overwrite a path attribute', () => { it('Should overwrite a path attribute', () => {
const part = { const line = new Path()
name: 'test', line.log = { debug: () => {} }
draft: ({ paths, Path, Point, part }) => { line
paths.line = new Path()
.move(new Point(0, 0)) .move(new Point(0, 0))
.line(new Point(0, 40)) .line(new Point(0, 40))
.attr('class', 'foo') .attr('class', 'foo')
.attr('class', 'bar') .attr('class', 'bar')
.attr('class', 'overwritten', true) .attr('class', 'overwritten', true)
return part
},
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft().render()
// Paths from shorthand have the log method // Paths from shorthand have the log method
expect(pattern.parts[0].test.paths.line.attributes.get('class')).to.equal('overwritten') expect(line.attributes.get('class')).to.equal('overwritten')
}) })
it('Should move along a path even if it lands just on a joint', () => { it('Should move along a path even if it lands just on a joint', () => {
@ -1054,7 +931,6 @@ describe('Path', () => {
it('Should log a warning when setting an attribute without a name', () => { it('Should log a warning when setting an attribute without a name', () => {
let invalid = false let invalid = false
const log = { warning: () => (invalid = true) } const log = { warning: () => (invalid = true) }
expect(invalid).to.equal(false)
new Path().__withLog(log).attr() new Path().__withLog(log).attr()
expect(invalid).to.equal(true) expect(invalid).to.equal(true)
}) })
@ -1062,52 +938,41 @@ describe('Path', () => {
it('Should log a warning when setting an attribute without a value', () => { it('Should log a warning when setting an attribute without a value', () => {
let invalid = false let invalid = false
const log = { warning: () => (invalid = true) } const log = { warning: () => (invalid = true) }
expect(invalid).to.equal(false)
new Path().__withLog(log).attr('test') new Path().__withLog(log).attr('test')
expect(invalid).to.equal(true) expect(invalid).to.equal(true)
}) })
it('Should log a warning when calling offset without a distance', () => { it('Should log an error when calling offset without a distance', () => {
const part = { let invalid = true
name: 'test', const log = { warning: () => {}, error: () => (invalid = true) }
draft: ({ paths, Path, Point, points }) => { const pointLog = { error: () => {} }
paths.line = new Path().move(new Point(0, 0)).line(new Point(0, 40)).attr('class', 'foo') const pointA = new Point(0, 0).__withLog(pointLog)
paths.a = new Path().move(points.a).line(points.b) const pointB = new Point(0, 40).__withLog(pointLog)
paths.b = paths.a.offset() const a = new Path().__withLog(log).move(pointA).line(pointB)
return part const b = a.offset()
}, expect(invalid).to.equal(true)
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft()
expect(pattern.setStores[0].logs.error.length).to.equal(2)
expect(pattern.setStores[0].logs.error[0]).to.equal(
'Called `Path.offset(distance)` but `distance` is not a number'
)
}) })
it('Should log a warning when calling join without a path', () => { it('Should log an error when calling join without a path', () => {
const part = { let invalid = false
name: 'test', const log = { error: () => (invalid = true) }
draft: ({ paths, Path, Point, points }) => { const line = new Path()
paths.line = new Path().move(new Point(0, 0)).line(new Point(0, 40)).attr('class', 'foo') .move(new Point(0, 0))
paths.a = new Path().move(points.a).line(points.b).join() .line(new Point(0, 40))
return part .attr('class', 'foo')
}, .__withLog(log)
try {
line.join()
} catch {
} finally {
expect(invalid).to.equal(true)
} }
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft()
expect(pattern.setStores[0].logs.error.length).to.equal(2)
expect(pattern.setStores[0].logs.error[0]).to.equal(
'Called `Path.join(that)` but `that` is not a `Path` object'
)
}) })
it('Should log a warning when calling start on a path without drawing operations', () => { it('Should log a warning when calling start on a path without drawing operations', () => {
let invalid = false let invalid = false
const log = { error: () => (invalid = true) } const log = { error: () => (invalid = true) }
expect(invalid).to.equal(false)
try { try {
new Path().__withLog(log).start() new Path().__withLog(log).start()
} catch (err) { } catch (err) {
@ -1116,10 +981,9 @@ describe('Path', () => {
expect(invalid).to.equal(true) expect(invalid).to.equal(true)
}) })
it('Should log a warning when calling end on a path without drawing operations', () => { it('Should log an error when calling end on a path without drawing operations', () => {
let invalid = false let invalid = false
const log = { error: () => (invalid = true) } const log = { error: () => (invalid = true) }
expect(invalid).to.equal(false)
try { try {
new Path().__withLog(log).end() new Path().__withLog(log).end()
} catch (err) { } catch (err) {
@ -1128,7 +992,7 @@ describe('Path', () => {
expect(invalid).to.equal(true) expect(invalid).to.equal(true)
}) })
it('Should log a warning when calling shiftAlong but distance is not a number', () => { it('Should log an error when calling shiftAlong but distance is not a number', () => {
let invalid = false let invalid = false
const log = { error: () => (invalid = true) } const log = { error: () => (invalid = true) }
expect(invalid).to.equal(false) expect(invalid).to.equal(false)
@ -1136,53 +1000,32 @@ describe('Path', () => {
expect(invalid).to.equal(true) expect(invalid).to.equal(true)
}) })
it('Should log a warning when calling shiftFractionalong but fraction is not a number', () => { it('Should log an error when calling shiftFractionalong but fraction is not a number', () => {
const part = { let invalid = false
name: 'test', const log = { error: () => (invalid = true) }
draft: ({ Path, Point, points }) => { const a = new Path()
points.a = new Path().move(new Point(0, 0)).line(new Point(0, 40)).shiftFractionAlong() .__withLog(log)
return part .move(new Point(0, 0))
}, .line(new Point(0, 40))
} .shiftFractionAlong()
const design = new Design({ parts: [part] }) expect(invalid).to.equal(true)
const pattern = new design()
pattern.draft()
expect(pattern.setStores[0].logs.error[0]).to.equal(
'Called `Path.shiftFractionAlong(fraction)` but `fraction` is not a number'
)
}) })
it('Should log a warning when splitting a path on a non-point', () => { it('Should log an error when splitting a path on a non-point', () => {
const part = { let invalid = false
name: 'test', const log = { error: () => (invalid = true) }
draft: ({ Path, Point, points, part }) => { try {
points.a = new Path().move(new Point(0, 0)).line(new Point(0, 40)).split() const a = new Path().__withLog(log).move(new Point(0, 0)).line(new Point(0, 40)).split()
return part } catch {
}, } finally {
expect(invalid).to.equal(true)
} }
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft()
expect(pattern.setStores[0].logs.error[0]).to.equal(
'Called `Path.split(point)` but `point` is not a `Point` object'
)
}) })
it('Should add a class', () => { it('Should add a class', () => {
const part = { const line = new Path().move(new Point(0, 0)).line(new Point(10, 10)).addClass('fabric banana')
name: 'test',
draft: ({ Path, paths, Point, part }) => { expect(line.attributes.get('class')).to.equal('fabric banana')
paths.line = new Path()
.move(new Point(0, 0))
.line(new Point(10, 10))
.addClass('fabric banana')
return part
},
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.draft()
expect(pattern.parts[0].test.paths.line.attributes.get('class')).to.equal('fabric banana')
}) })
it('Should (un)hide a path with hide()/unhide()', () => { it('Should (un)hide a path with hide()/unhide()', () => {

View file

@ -132,26 +132,30 @@ describe('Point', () => {
expect(round(ss.shiftTowards(se, 200).y)).to.equal(-18.42) expect(round(ss.shiftTowards(se, 200).y)).to.equal(-18.42)
}) })
describe('shiftFractionTowards', () => {
it('Should shift a point a fraction towards another', () => { it('Should shift a point a fraction towards another', () => {
let origin = new Point(0, 0) let origin = new Point(0, 0)
let n = new Point(0, -10)
let e = new Point(10, 0)
let s = new Point(0, 10) let s = new Point(0, 10)
let w = new Point(-10, 0)
let sn = origin.shiftFractionTowards(n, 1.5)
let se = origin.shiftFractionTowards(e, 1.5)
let ss = origin.shiftFractionTowards(s, 0.5) let ss = origin.shiftFractionTowards(s, 0.5)
let sw = origin.shiftFractionTowards(w, 2.5)
expect(round(sn.x)).to.equal(0)
expect(round(sn.y)).to.equal(-15)
expect(round(se.x)).to.equal(15)
expect(round(se.y)).to.equal(0)
expect(round(ss.x)).to.equal(0) expect(round(ss.x)).to.equal(0)
expect(round(ss.y)).to.equal(5) expect(round(ss.y)).to.equal(5)
expect(round(sw.x)).to.equal(-25) })
expect(round(sw.y)).to.equal(0)
expect(round(sw.shiftFractionTowards(sn, 100).x)).to.equal(2475) it('Should shift a point a fraction beyond another if the fraction is > 1', () => {
expect(round(ss.shiftFractionTowards(se, 200).y)).to.equal(-995) let origin = new Point(0, 0)
let n = new Point(0, -10)
let sn = origin.shiftFractionTowards(n, 1.5)
expect(round(sn.x)).to.equal(0)
expect(round(sn.y)).to.equal(-15)
})
it('Should shift a point a fraction away from another if the fraction is < 0', () => {
let origin = new Point(0, 0)
let n = new Point(0, -10)
let sn = origin.shiftFractionTowards(n, -0.5)
expect(round(sn.x)).to.equal(0)
expect(round(sn.y)).to.equal(5)
})
}) })
it('Should shift a point beyond another', () => { it('Should shift a point beyond another', () => {

View file

@ -154,8 +154,9 @@ describe('Utils', () => {
expect(hits.length).to.equal(3) expect(hits.length).to.equal(3)
}) })
it('Should find 9 intersections between two curves', () => { describe('curvesIntersect', function () {
this.timeout(15000) this.timeout(15000)
it('Should find 9 intersections between two curves', () => {
let A = new Point(10, 10) let A = new Point(10, 10)
let Acp = new Point(310, 40) let Acp = new Point(310, 40)
let B = new Point(110, 70) let B = new Point(110, 70)
@ -197,6 +198,7 @@ describe('Utils', () => {
let hit = curvesIntersect(A, Acp, Bcp, B, C, Ccp, Dcp, D) let hit = curvesIntersect(A, Acp, Bcp, B, C, Ccp, Dcp, D)
expect(hit).to.equal(false) expect(hit).to.equal(false)
}) })
})
it('Should correctly format units', () => { it('Should correctly format units', () => {
expect(units(123.456)).to.equal('12.35cm') expect(units(123.456)).to.equal('12.35cm')