Skip to content

Commit

Permalink
Resolver test coverage (elastic#70246)
Browse files Browse the repository at this point in the history
* Move AABB, Matrix3, and Vector2 modules from lib to models

* Add tests for AABB

* remove dead code
  • Loading branch information
Robert Austin authored and Bamieh committed Jul 1, 2020
1 parent 57fc0d1 commit 227caa0
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { applyMatrix3 } from './vector2';
import { applyMatrix3 } from '../models/vector2';
import { scalingTransformation } from './transformation';

describe('transforms', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

/**
* Sequences a tree, yielding children returned by the `children` function. Sequencing is done in 'depth first preorder' fashion. See https://en.wikipedia.org/wiki/Tree_traversal#Pre-order_(NLR)
*/
export function* depthFirstPreorder<T>(root: T, children: (parent: T) => T[]): Iterable<T> {
const nodesToVisit = [root];
while (nodesToVisit.length !== 0) {
const currentNode = nodesToVisit.shift();
if (currentNode !== undefined) {
nodesToVisit.unshift(...(children(currentNode) || []));
yield currentNode;
}
}
}

/**
* Sequences a tree, yielding children returned by the `children` function. Sequencing is done in 'level order' fashion.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { isEqual } from './aabb';
import { AABB } from '../types';

describe('AABB', () => {
const minimumX = 0;
const minimumY = 0;
const maximumX = 0;
const maximumY = 0;

let aabb: AABB;

beforeEach(() => {
aabb = { minimum: [minimumX, minimumY], maximum: [maximumX, maximumY] };
});
it('should be equal to an AABB with the same values', () => {
expect(isEqual(aabb, { minimum: [minimumX, minimumY], maximum: [maximumX, maximumY] })).toBe(
true
);
});

it('should not be equal to an AABB with a different minimum X value', () => {
expect(
isEqual(aabb, { minimum: [minimumX + 1, minimumY], maximum: [maximumX, maximumY] })
).toBe(false);
});
it('should not be equal to an AABB with a different minimum Y value', () => {
expect(
isEqual(aabb, { minimum: [minimumX, minimumY + 1], maximum: [maximumX, maximumY] })
).toBe(false);
});
it('should not be equal to an AABB with a different maximum X value', () => {
expect(
isEqual(aabb, { minimum: [minimumX, minimumY], maximum: [maximumX + 1, maximumY] })
).toBe(false);
});
it('should not be equal to an AABB with a different maximum Y value', () => {
expect(
isEqual(aabb, { minimum: [minimumX, minimumY], maximum: [maximumX, maximumY + 1] })
).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import * as vector2 from '../../lib/vector2';
import * as vector2 from '../../models/vector2';
import {
IndexedProcessTree,
Vector2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CameraAction } from './action';
import { CameraState } from '../../types';
import { cameraReducer } from './reducer';
import { inverseProjectionMatrix } from './selectors';
import { applyMatrix3 } from '../../lib/vector2';
import { applyMatrix3 } from '../../models/vector2';
import { scaleToZoom } from './scale_to_zoom';

describe('inverseProjectionMatrix', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { translation } from './selectors';
import { CameraState, Vector2 } from '../../types';
import { distance } from '../../lib/vector2';
import { distance } from '../../models/vector2';

/**
* Return a new `CameraState` with the `animation` property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CameraAction } from './action';
import { CameraState } from '../../types';
import { cameraReducer } from './reducer';
import { projectionMatrix } from './selectors';
import { applyMatrix3 } from '../../lib/vector2';
import { applyMatrix3 } from '../../models/vector2';
import { scaleToZoom } from './scale_to_zoom';

describe('projectionMatrix', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { Reducer } from 'redux';
import { unitsPerNudge, nudgeAnimationDuration } from './scaling_constants';
import { animatePanning } from './methods';
import * as vector2 from '../../lib/vector2';
import * as vector2 from '../../models/vector2';
import * as selectors from './selectors';
import { clamp } from '../../lib/math';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import { createSelector, defaultMemoize } from 'reselect';
import { easing } from 'ts-easing';
import { clamp, lerp } from '../../lib/math';
import * as vector2 from '../../lib/vector2';
import { multiply, add as addMatrix } from '../../lib/matrix3';
import * as vector2 from '../../models/vector2';
import { multiply, add as addMatrix } from '../../models/matrix3';
import {
inverseOrthographicProjection,
scalingTransformation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CameraState, AABB } from '../../types';
import { viewableBoundingBox, inverseProjectionMatrix, scalingFactor } from './selectors';
import { expectVectorsToBeClose } from './test_helpers';
import { scaleToZoom } from './scale_to_zoom';
import { applyMatrix3 } from '../../lib/vector2';
import { applyMatrix3 } from '../../models/vector2';

describe('zooming', () => {
let store: Store<CameraState, CameraAction>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
uniquePidForProcess,
} from '../../models/process_event';
import { factory as indexedProcessTreeFactory } from '../../models/indexed_process_tree';
import { isEqual } from '../../lib/aabb';
import { isEqual } from '../../models/aabb';

import {
ResolverEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import styled from 'styled-components';
import { FormattedMessage } from '@kbn/i18n/react';
import { applyMatrix3, distance, angle } from '../lib/vector2';
import { applyMatrix3, distance, angle } from '../models/vector2';
import { Vector2, Matrix3, EdgeLineMetadata } from '../types';
import { useResolverTheme, calculateResolverFontSize } from './assets';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useHistory } from 'react-router-dom';
// eslint-disable-next-line import/no-nodejs-modules
import querystring from 'querystring';
import { NodeSubMenu, subMenuAssets } from './submenu';
import { applyMatrix3 } from '../lib/vector2';
import { applyMatrix3 } from '../models/vector2';
import { Vector2, Matrix3, AdjacentProcessMap } from '../types';
import { SymbolIds, useResolverTheme, calculateResolverFontSize } from './assets';
import { ResolverEvent, ResolverNodeStats } from '../../../common/endpoint/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { storeFactory } from '../store';
import { Matrix3, ResolverStore, SideEffectSimulator } from '../types';
import { ResolverEvent } from '../../../common/endpoint/types';
import { SideEffectContext } from './side_effect_context';
import { applyMatrix3 } from '../lib/vector2';
import { applyMatrix3 } from '../models/vector2';
import { sideEffectSimulator } from './side_effect_simulator';
import { mockProcessEvent } from '../models/process_event_test_helpers';
import { mock as mockResolverTree } from '../models/resolver_tree';
Expand Down

0 comments on commit 227caa0

Please sign in to comment.