Skip to content

Commit

Permalink
feat(core): move arc bounding box unit tests to the arcs package
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Dec 18, 2020
1 parent 1562576 commit 6c30f05
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 60 deletions.
2 changes: 2 additions & 0 deletions packages/arcs/tests/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env:
jest: true
52 changes: 52 additions & 0 deletions packages/arcs/tests/boundingBox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { computeArcBoundingBox } from '../src/boundingBox'

const boundingBoxCases = [
{
args: [0, 0, 100, 0, 360],
expected: {
x: -100,
y: -100,
width: 200,
height: 200,
},
},
{
args: [0, 0, 100, 0, 90],
expected: {
x: 0,
y: 0,
width: 100,
height: 100,
},
},
{
args: [0, 0, 100, -90, 0],
expected: {
x: 0,
y: -100,
width: 100,
height: 100,
},
},
{
args: [0, 0, 100, 90, 180],
expected: {
x: -100,
y: 0,
width: 100,
height: 100,
},
},
]

for (const boundingBoxCase of boundingBoxCases) {
const { args, expected } = boundingBoxCase

test(`computeArcBoundingBox() for position ${args[0]}, ${args[1]} with radius ${args[2]}, starting at ${args[3]}°, ending at ${args[4]}°`, () => {
const box = computeArcBoundingBox(...args)

for (const prop in expected) {
expect(box).toHaveProperty(prop, expected[prop])
}
})
}
61 changes: 1 addition & 60 deletions packages/core/tests/lib/polar/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,9 @@
/*
* This file is part of the nivo project.
*
* Copyright 2016-present, Raphaël Benitte.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { absoluteAngleDegrees, midAngle, computeArcBoundingBox } from '../../../src/lib/polar/utils'
import { absoluteAngleDegrees, midAngle } from '../../../src/lib/polar/utils'

test('midAngle() should compute center of given angles', () => {
expect(midAngle({ startAngle: 0, endAngle: 90 })).toBe(45)
})

const boundingBoxCases = [
{
args: [0, 0, 100, 0, 360],
expected: {
x: -100,
y: -100,
width: 200,
height: 200,
},
},
{
args: [0, 0, 100, 0, 90],
expected: {
x: 0,
y: 0,
width: 100,
height: 100,
},
},
{
args: [0, 0, 100, -90, 0],
expected: {
x: 0,
y: -100,
width: 100,
height: 100,
},
},
{
args: [0, 0, 100, 90, 180],
expected: {
x: -100,
y: 0,
width: 100,
height: 100,
},
},
]

for (let boundingBoxCase of boundingBoxCases) {
const { args, expected } = boundingBoxCase

test(`computeArcBoundingBox() for position ${args[0]}, ${args[1]} with radius ${args[2]}, starting at ${args[3]}°, ending at ${args[4]}°`, () => {
const box = computeArcBoundingBox(...args)

for (let prop in expected) {
expect(box).toHaveProperty(prop, expected[prop])
}
})
}

const absAngleDegUseCases = [
{
input: 0,
Expand Down

0 comments on commit 6c30f05

Please sign in to comment.