We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents abbec3a + 06e65e3 commit 3adecaeCopy full SHA for 3adecae
2 files changed
packages/graphing/controller/src/__tests__/utils.test.js
@@ -58,6 +58,14 @@ describe('equalPoint', () => {
58
[p2_3, p1_10, false],
59
[p0_0, p1_0, false],
60
[pNull, pUndefined, true],
61
+ // label tests: a point is only correct if position AND label both match
62
+ [{ x: 1, y: 1, label: 'A' }, { x: 1, y: 1, label: 'A' }, true],
63
+ [{ x: 1, y: 1, label: 'A' }, { x: 1, y: 1, label: 'B' }, false],
64
+ [{ x: 1, y: 1, label: 'A' }, { x: 1, y: 1 }, false],
65
+ [{ x: 1, y: 1 }, { x: 1, y: 1, label: 'A' }, false],
66
+ [{ x: 1, y: 1 }, { x: 1, y: 1 }, true],
67
+ // wrong position, label irrelevant
68
+ [{ x: 1, y: 1, label: 'A' }, { x: 2, y: 2, label: 'A' }, false],
69
])('%j, %j => %s', (pointA, pointB, expected) => {
70
const result = equalPoint(pointA, pointB);
71
packages/graphing/controller/src/utils.js
@@ -8,6 +8,9 @@ import {
8
9
export const equalPoint = (A, B) => {
10
// x1 = x2 & y1 = y2
11
+ // A point is only correct if both its position AND its label match.
12
+ // Labels are not scored independently; a point in the correct position
13
+ // with the wrong label is considered incorrect as a whole.
14
let equalLabel = true;
15
16
A = { ...A };
@@ -17,7 +20,7 @@ export const equalPoint = (A, B) => {
17
20
equalLabel = isEqual(A.label, B.label);
18
21
}
19
22
- return isEqual(A.x, B.x) && isEqual(A.y, B.y);
23
+ return isEqual(A.x, B.x) && isEqual(A.y, B.y) && equalLabel;
24
};
25
26
export const equalSegment = (segment1, segment2) => {
0 commit comments