Skip to content

Commit 06e65e3

Browse files
fix(graphing): point labels scoring PIE-523
1 parent abbec3a commit 06e65e3

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

packages/graphing/controller/src/__tests__/utils.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ describe('equalPoint', () => {
5858
[p2_3, p1_10, false],
5959
[p0_0, p1_0, false],
6060
[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],
6169
])('%j, %j => %s', (pointA, pointB, expected) => {
6270
const result = equalPoint(pointA, pointB);
6371

packages/graphing/controller/src/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88

99
export const equalPoint = (A, B) => {
1010
// 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.
1114
let equalLabel = true;
1215

1316
A = { ...A };
@@ -17,7 +20,7 @@ export const equalPoint = (A, B) => {
1720
equalLabel = isEqual(A.label, B.label);
1821
}
1922

20-
return isEqual(A.x, B.x) && isEqual(A.y, B.y);
23+
return isEqual(A.x, B.x) && isEqual(A.y, B.y) && equalLabel;
2124
};
2225

2326
export const equalSegment = (segment1, segment2) => {

0 commit comments

Comments
 (0)