generated from skedwards88/template-app
-
Notifications
You must be signed in to change notification settings - Fork 0
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
5c49cb6
commit 64a1270
Showing
3 changed files
with
252 additions
and
12 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,52 +1,102 @@ | ||
import {centerIndexes} from "./centerIndexes"; | ||
|
||
test("Given indexes in a grid, returns the indexes of the centered input indexes", () => { | ||
const indexes = [11,15,17,20,21] | ||
const indexes = [11, 15, 17, 20, 21]; | ||
|
||
const centeredIndexes = centerIndexes(indexes, 5); | ||
|
||
const expectedIndexes = [7,11,13,16,17] | ||
const expectedIndexes = [7, 11, 13, 16, 17]; | ||
|
||
expect(centeredIndexes).toEqual(expectedIndexes); | ||
}); | ||
|
||
|
||
test("If the indexes can't be perfectly centered, errs towards the top left", () => { | ||
const expectedIndexes = [8,13,14,15,20] | ||
const expectedIndexes = [8, 13, 14, 15, 20]; | ||
|
||
const indexesBottomLeft = [19,24,25,26,31] | ||
const indexesBottomLeft = [19, 24, 25, 26, 31]; | ||
|
||
expect(centerIndexes(indexesBottomLeft, 6)).toEqual(expectedIndexes); | ||
|
||
const indexesBottomRight = [22,27,28,29,34] | ||
const indexesBottomRight = [22, 27, 28, 29, 34]; | ||
|
||
expect(centerIndexes(indexesBottomRight, 6)).toEqual(expectedIndexes); | ||
|
||
const indexesTopLeft = [1,6,7,8,13] | ||
const indexesTopLeft = [1, 6, 7, 8, 13]; | ||
|
||
expect(centerIndexes(indexesTopLeft, 6)).toEqual(expectedIndexes); | ||
|
||
const indexesTopRight = [4,9,10,11,16] | ||
const indexesTopRight = [4, 9, 10, 11, 16]; | ||
|
||
expect(centerIndexes(indexesTopRight, 6)).toEqual(expectedIndexes); | ||
}); | ||
|
||
test("If the indexes are already centered up/down, will still center right/left", () => { | ||
const indexes = [6,10,12,15,16] | ||
const indexes = [6, 10, 12, 15, 16]; | ||
|
||
const centeredIndexes = centerIndexes(indexes, 5); | ||
|
||
const expectedIndexes = [7,11,13,16,17] | ||
const expectedIndexes = [7, 11, 13, 16, 17]; | ||
|
||
expect(centeredIndexes).toEqual(expectedIndexes); | ||
}); | ||
|
||
test("If the indexes are already centered right/left, will still center up/down", () => { | ||
const indexes = [12,16,18,21,22] | ||
const indexes = [12, 16, 18, 21, 22]; | ||
|
||
const centeredIndexes = centerIndexes(indexes, 5); | ||
|
||
const expectedIndexes = [7,11,13,16,17] | ||
const expectedIndexes = [7, 11, 13, 16, 17]; | ||
|
||
expect(centeredIndexes).toEqual(expectedIndexes); | ||
}); | ||
|
||
test("Works on empty indexes", () => { | ||
const indexes = []; | ||
|
||
const centeredIndexes = centerIndexes(indexes, 5); | ||
|
||
const expectedIndexes = []; | ||
|
||
expect(centeredIndexes).toEqual(expectedIndexes); | ||
}); | ||
|
||
test("Errors if the indexes input is not a list of ints", () => { | ||
expect(() => centerIndexes(["A", "B", "C"], 5)).toThrow( | ||
"The `indexes` input must be an array of integers", | ||
); | ||
|
||
expect(() => | ||
centerIndexes( | ||
[ | ||
[1, 0, 1], | ||
[0, 1, 1], | ||
[0, 0, 0], | ||
], | ||
5, | ||
), | ||
).toThrow("The `indexes` input must be an array of integers"); | ||
}); | ||
|
||
test("Errors if the gridSize input is not an int > 0", () => { | ||
expect(() => centerIndexes([12, 16, 18, 21, 22], "6")).toThrow( | ||
"The `gridSize` input must be an integer > 0", | ||
); | ||
|
||
expect(() => centerIndexes([12, 16, 18, 21, 22], 0)).toThrow( | ||
"The `gridSize` input must be an integer > 0", | ||
); | ||
}); | ||
|
||
test("Errors if any of the indexes exceed the grid size", () => { | ||
expect(() => centerIndexes([12, 16, 18, 21, 22], 4)).toThrow( | ||
"One of more of the indexes exceeds the grid size", | ||
); | ||
|
||
expect(() => centerIndexes([-2, 12, 16, 18, 21, 22, 24], 6)).toThrow( | ||
"One of more of the indexes exceeds the grid size", | ||
); | ||
|
||
expect(() => centerIndexes([2, 16, 18, 21, 22, 36], 6)).toThrow( | ||
"One of more of the indexes exceeds the grid size", | ||
); | ||
}); |
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,173 @@ | ||
import {shapesMatchQ} from "./shapesMatchQ"; | ||
|
||
test("Returns true if two sets of indexes form the same shape in a grid", () => { | ||
expect( | ||
shapesMatchQ({ | ||
indexes1: [11, 15, 17, 20, 21], | ||
indexes2: [17, 11, 13, 16, 7], | ||
gridSize: 5, | ||
}), | ||
).toBe(true); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [7, 11, 13, 16, 17], | ||
indexes2: [6, 10, 12, 15, 16], | ||
gridSize: 5, | ||
}), | ||
).toBe(true); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [12, 16, 18, 21, 22], | ||
indexes2: [6, 15, 12, 10, 16], | ||
gridSize: 5, | ||
}), | ||
).toBe(true); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [8, 13, 14, 15, 20], | ||
indexes2: [19, 24, 25, 26, 31], | ||
gridSize: 6, | ||
}), | ||
).toBe(true); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [22, 27, 28, 29, 34], | ||
indexes2: [19, 24, 25, 26, 31], | ||
gridSize: 6, | ||
}), | ||
).toBe(true); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [1, 6, 7, 8, 13], | ||
indexes2: [19, 24, 31, 26, 25], | ||
gridSize: 6, | ||
}), | ||
).toBe(true); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [8, 13, 14, 15, 20], | ||
indexes2: [4, 9, 10, 11, 16], | ||
gridSize: 6, | ||
}), | ||
).toBe(true); | ||
}); | ||
|
||
test("Returns false if two sets of indexes do not form the same shape in a grid", () => { | ||
expect( | ||
shapesMatchQ({ | ||
indexes1: [11, 15, 17, 20, 21], | ||
indexes2: [7, 11, 13, 16, 18], | ||
gridSize: 5, | ||
}), | ||
).toBe(false); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [7, 1, 13, 16, 17], | ||
indexes2: [6, 10, 12, 15, 16], | ||
gridSize: 5, | ||
}), | ||
).toBe(false); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [11, 12, 16, 18, 21, 22], | ||
indexes2: [6, 10, 12, 15, 16], | ||
gridSize: 5, | ||
}), | ||
).toBe(false); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [18, 13, 14, 15, 20], | ||
indexes2: [19, 24, 25, 26, 31], | ||
gridSize: 6, | ||
}), | ||
).toBe(false); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [2, 27, 28, 29, 34], | ||
indexes2: [19, 24, 25, 26, 31], | ||
gridSize: 6, | ||
}), | ||
).toBe(false); | ||
}); | ||
|
||
test("Returns works with empty arrays", () => { | ||
expect( | ||
shapesMatchQ({ | ||
indexes1: [], | ||
indexes2: [], | ||
gridSize: 5, | ||
}), | ||
).toBe(true); | ||
|
||
expect( | ||
shapesMatchQ({ | ||
indexes1: [], | ||
indexes2: [5, 6, 3], | ||
gridSize: 5, | ||
}), | ||
).toBe(false); | ||
}); | ||
|
||
test("Errors if the indexes input is not a list of ints", () => { | ||
expect(() => | ||
shapesMatchQ({ | ||
indexes1: ["7", "11", "13", 16, 17], | ||
indexes2: [6, 10, 12, 15, 16], | ||
gridSize: 5, | ||
}), | ||
).toThrow("The `indexes` input must be an array of integers"); | ||
|
||
expect(() => | ||
shapesMatchQ({ | ||
indexes1: [[7, 11, 13, 16, 17]], | ||
indexes2: [6, 10, 12, 15, 16], | ||
gridSize: 5, | ||
}), | ||
).toThrow("The `indexes` input must be an array of integers"); | ||
}); | ||
|
||
test("Errors if the gridSize input is not an int > 0", () => { | ||
expect(() => | ||
shapesMatchQ({ | ||
indexes1: [7, 11, 13, 16, 17], | ||
indexes2: [6, 10, 12, 15, 16], | ||
gridSize: "5", | ||
}), | ||
).toThrow("The `gridSize` input must be an integer > 0"); | ||
|
||
expect(() => | ||
shapesMatchQ({ | ||
indexes1: [7, 11, 13, 16, 17], | ||
indexes2: [6, 10, 12, 15, 16], | ||
gridSize: 0, | ||
}), | ||
).toThrow("The `gridSize` input must be an integer > 0"); | ||
}); | ||
|
||
test("Errors if any of the indexes exceed the grid size", () => { | ||
expect(() => | ||
shapesMatchQ({ | ||
indexes1: [7, 11, 13, 16, 25], | ||
indexes2: [6, 10, 12, 15, 16], | ||
gridSize: 5, | ||
}), | ||
).toThrow("One of more of the indexes exceeds the grid size"); | ||
|
||
expect(() => | ||
shapesMatchQ({ | ||
indexes1: [-1, 11, 13, 16, 17], | ||
indexes2: [6, 10, 12, 15, 16], | ||
gridSize: 5, | ||
}), | ||
).toThrow("One of more of the indexes exceeds the grid size"); | ||
}); |