Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/graphing/controller/src/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ describe('equalPoint', () => {
[p2_3, p1_10, false],
[p0_0, p1_0, false],
[pNull, pUndefined, true],
// label tests: a point is only correct if position AND label both match
[{ x: 1, y: 1, label: 'A' }, { x: 1, y: 1, label: 'A' }, true],
[{ x: 1, y: 1, label: 'A' }, { x: 1, y: 1, label: 'B' }, false],
[{ x: 1, y: 1, label: 'A' }, { x: 1, y: 1 }, false],
[{ x: 1, y: 1 }, { x: 1, y: 1, label: 'A' }, false],
[{ x: 1, y: 1 }, { x: 1, y: 1 }, true],
// wrong position, label irrelevant
[{ x: 1, y: 1, label: 'A' }, { x: 2, y: 2, label: 'A' }, false],
])('%j, %j => %s', (pointA, pointB, expected) => {
const result = equalPoint(pointA, pointB);

Expand Down
5 changes: 4 additions & 1 deletion packages/graphing/controller/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {

export const equalPoint = (A, B) => {
// x1 = x2 & y1 = y2
// A point is only correct if both its position AND its label match.
// Labels are not scored independently; a point in the correct position
// with the wrong label is considered incorrect as a whole.
let equalLabel = true;

A = { ...A };
Expand All @@ -17,7 +20,7 @@ export const equalPoint = (A, B) => {
equalLabel = isEqual(A.label, B.label);
}

return isEqual(A.x, B.x) && isEqual(A.y, B.y);
return isEqual(A.x, B.x) && isEqual(A.y, B.y) && equalLabel;
};

export const equalSegment = (segment1, segment2) => {
Expand Down
Loading