-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba65795
commit 52139ea
Showing
4 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { testProp, fc } from 'ava-fast-check' | ||
import { neighborhoods } from '../../src/lib/pixelmanipulator' | ||
const { rect } = neighborhoods | ||
|
||
testProp( | ||
'rect\'s size output is the area', | ||
// Maximums provided to ensure reasonable time and memory is spent | ||
[fc.integer(), fc.integer(), fc.nat({ max: 25 }), fc.nat({ max: 25 })], | ||
(t, x, y, w, h) => { | ||
const topLeft = { | ||
x, | ||
y | ||
} | ||
const bottomRight = { | ||
x: x + w, | ||
y: y + h | ||
} | ||
const expectedArea = (w + 1) * (h + 1) // (0,0) to (1,1) is area of 4 | ||
const list = rect(topLeft, bottomRight) | ||
t.is(list.length, expectedArea) | ||
} | ||
) | ||
testProp( | ||
'return from rect has no duplicates', | ||
[fc.integer(), fc.integer(), fc.nat({ max: 25 }), fc.nat({ max: 25 })], | ||
(t, x, y, w, h) => { | ||
const topLeft = { | ||
x, | ||
y | ||
} | ||
const bottomRight = { | ||
x: x + w, | ||
y: y + h | ||
} | ||
const list = rect(topLeft, bottomRight).map(pos => JSON.stringify(pos)) | ||
const set = new Set(list) | ||
t.is(list.length, set.size) | ||
} | ||
) | ||
testProp( | ||
'return from rect keeps all values within bounds', | ||
[fc.integer(), fc.integer(), fc.nat({ max: 25 }), fc.nat({ max: 25 })], | ||
(t, x, y, w, h) => { | ||
const topLeft = { | ||
x, | ||
y | ||
} | ||
const bottomRight = { | ||
x: x + w, | ||
y: y + h | ||
} | ||
const list = rect(topLeft, bottomRight) | ||
t.plan(list.length * 2) | ||
list.forEach(pos => { | ||
t.true(topLeft.x <= pos.x && pos.x <= bottomRight.x) | ||
t.true(topLeft.y <= pos.y && pos.y <= bottomRight.y) | ||
}) | ||
} | ||
) |