From 6c30f05ae3b5ce2f9a6a28fe260464612502a7d2 Mon Sep 17 00:00:00 2001 From: plouc Date: Sun, 13 Dec 2020 11:59:30 +0900 Subject: [PATCH] feat(core): move arc bounding box unit tests to the arcs package --- packages/arcs/tests/.eslintrc.yml | 2 + packages/arcs/tests/boundingBox.test.ts | 52 ++++++++++++++++++ packages/core/tests/lib/polar/utils.test.js | 61 +-------------------- 3 files changed, 55 insertions(+), 60 deletions(-) create mode 100644 packages/arcs/tests/.eslintrc.yml create mode 100644 packages/arcs/tests/boundingBox.test.ts diff --git a/packages/arcs/tests/.eslintrc.yml b/packages/arcs/tests/.eslintrc.yml new file mode 100644 index 0000000000..2f8de9aea2 --- /dev/null +++ b/packages/arcs/tests/.eslintrc.yml @@ -0,0 +1,2 @@ +env: + jest: true diff --git a/packages/arcs/tests/boundingBox.test.ts b/packages/arcs/tests/boundingBox.test.ts new file mode 100644 index 0000000000..821e0f108c --- /dev/null +++ b/packages/arcs/tests/boundingBox.test.ts @@ -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]) + } + }) +} diff --git a/packages/core/tests/lib/polar/utils.test.js b/packages/core/tests/lib/polar/utils.test.js index fd20604fdf..654fc97a92 100644 --- a/packages/core/tests/lib/polar/utils.test.js +++ b/packages/core/tests/lib/polar/utils.test.js @@ -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,