Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skedwards88 committed Mar 24, 2024
1 parent f72bcb3 commit 5c49cb6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ jobs:
- name: Install requirements
run: npm install

# todo uncomment once tests are added
# - name: Run tests
# run: npm test
- name: Run tests
run: npm test

- name: Setup git config
run: |
Expand Down
52 changes: 52 additions & 0 deletions src/logic/centerIndexes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 centeredIndexes = centerIndexes(indexes, 5);

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 indexesBottomLeft = [19,24,25,26,31]

expect(centerIndexes(indexesBottomLeft, 6)).toEqual(expectedIndexes);

const indexesBottomRight = [22,27,28,29,34]

expect(centerIndexes(indexesBottomRight, 6)).toEqual(expectedIndexes);

const indexesTopLeft = [1,6,7,8,13]

expect(centerIndexes(indexesTopLeft, 6)).toEqual(expectedIndexes);

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 centeredIndexes = centerIndexes(indexes, 5);

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 centeredIndexes = centerIndexes(indexes, 5);

const expectedIndexes = [7,11,13,16,17]

expect(centeredIndexes).toEqual(expectedIndexes);
});

0 comments on commit 5c49cb6

Please sign in to comment.