refactor: reduce code duplication in FloodFill (#1645)

* tests: add tests checking if floodFill funtions throw when location is outside

* refactor: reduce code duplication by adding `checkLocation` to `FloodFill`

* refactor: add and use `isInside`

Co-authored-by: appgurueu <34514239+appgurueu@users.noreply.github.com>

* Deduplicate further

---------

Co-authored-by: appgurueu <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
Piotr Idzik
2024-04-03 17:24:06 +02:00
committed by GitHub
parent d02e402972
commit d920e7f427
2 changed files with 41 additions and 31 deletions

View File

@@ -21,6 +21,19 @@ describe('FloodFill', () => {
})
})
describe.each([breadthFirstSearch, depthFirstSearch])('%o', (floodFillFun) => {
it.each([
[1, -1],
[-1, 1],
[0, 7],
[7, 0]
])('throws for start position [%i, %i]', (location) => {
expect(() =>
floodFillFun(generateTestRgbData(), location, green, orange)
).toThrowError()
})
})
/**
* Utility-function to test the function "breadthFirstSearch".
*