-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.js
39 lines (37 loc) · 1.15 KB
/
spec_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {
binaryStringToHex,
hexToBinaryString
} from '../../src/pixel_pic'
function normalizeCells (cells) {
cells.map((row) => {
return row.map((cell) => {
return { filled: cell.filled }
})
})
}
expect.extend({
fromBinaryStringToHexToBe (binaryString, expected) {
const hex = binaryStringToHex(binaryString.padStart(128, '0'))
const expectedPadded = expected.padStart(32, '0')
return {
message: () => `expected ${expectedPadded} but was ${hex}`,
pass: hex === expectedPadded
}
},
fromHexToBinaryStringToBe (hex, expected) {
const binaryString = hexToBinaryString(hex.padStart(32, '0'))
const expectedPadded = expected.padStart(128, '0')
return {
message: () => `expected ${expectedPadded} but was ${binaryString}`,
pass: binaryString === expectedPadded
}
},
toEqualFilledCells (cells, expectedCells) {
const normalizedCells = normalizeCells(cells)
const normalizedExpectedCells = normalizeCells(expectedCells)
return {
message: () => `expected ${normalizedExpectedCells} but was ${normalizedCells}`,
pass: normalizedCells === normalizedExpectedCells
}
}
})