-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(step-generation): h-S collision warning for Flex protocols (#15144)
closes RQA-2596
- Loading branch information
1 parent
e9ef396
commit 7e2409c
Showing
13 changed files
with
151 additions
and
43 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
shared-data/js/helpers/__tests__/getAreFlexSlotsAdjacent.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { getAreFlexSlotsAdjacent } from '../getAreFlexSlotsAdjacent' | ||
|
||
describe('getAreFlexSlotsAdjacent', () => { | ||
it('returns false when slots are apart', () => { | ||
const results = getAreFlexSlotsAdjacent('A1', 'A3') | ||
expect(results).toStrictEqual(false) | ||
}) | ||
it('returns true when slots are left/right', () => { | ||
const results = getAreFlexSlotsAdjacent('A1', 'A2') | ||
expect(results).toStrictEqual(true) | ||
}) | ||
it('returns true when slots are north/south', () => { | ||
const results = getAreFlexSlotsAdjacent('A1', 'B1') | ||
expect(results).toStrictEqual(true) | ||
}) | ||
it('returns true when slots are diagonal', () => { | ||
const results = getAreFlexSlotsAdjacent('A1', 'B2') | ||
expect(results).toStrictEqual(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { FLEX_GRID } from './getFlexSurroundingSlots' | ||
import type { DeckSlotId } from '../types' | ||
|
||
export const getAreFlexSlotsAdjacent = ( | ||
slot1: DeckSlotId, | ||
slot2: DeckSlotId | ||
): boolean => { | ||
const findSlotPosition = (slot: DeckSlotId): [number, number] | null => { | ||
for (let row = 0; row < FLEX_GRID.length; row++) { | ||
const col = FLEX_GRID[row].indexOf(slot) | ||
if (col !== -1) { | ||
return [row, col] | ||
} | ||
} | ||
return null | ||
} | ||
|
||
const pos1 = findSlotPosition(slot1) | ||
const pos2 = findSlotPosition(slot2) | ||
|
||
if (pos1 === null || pos2 === null) { | ||
return false | ||
} | ||
|
||
const [row1, col1] = pos1 | ||
const [row2, col2] = pos2 | ||
|
||
const rowDiff = Math.abs(row1 - row2) | ||
const colDiff = Math.abs(col1 - col2) | ||
|
||
if ((rowDiff === 1 && colDiff <= 1) || (rowDiff === 0 && colDiff === 1)) { | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters