Instantly share code, notes, and snippets.
Created
June 27, 2020 16:42
-
Save flagrede/72d64e3db9634d5b4cc10f37a9f220ee to your computer and use it in GitHub Desktop.
Zelda BOTW Part 1: keyboardNavigation tests
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
import { | |
getMatrixPositionFromIndex, | |
getIndexFromMaxtrixPosition, | |
goUp, | |
goDown, | |
goRight, | |
goLeft, | |
} from "./keyboardNavigation"; | |
describe("getMatrixPositionFromIndex", () => { | |
it("should convert 6 to x:1, y:1 position", () => { | |
// Given | |
const index = 6; | |
// When | |
const result = getMatrixPositionFromIndex(index); | |
// Then | |
expect(result).toEqual({ x: 1, y: 1 }); | |
}); | |
it("should convert 15 to x:1, y:1 position", () => { | |
// Given | |
const index = 14; | |
// When | |
const result = getMatrixPositionFromIndex(index); | |
// Then | |
expect(result).toEqual({ x: 2, y: 4 }); | |
}); | |
}); | |
describe("getIndexFromMaxtrixPosition", () => { | |
it("should convert x:1, y:1 position to 6", () => { | |
// Given | |
const position = { x: 1, y: 1 }; | |
// When | |
const result = getIndexFromMaxtrixPosition(position); | |
// Then | |
expect(result).toEqual(6); | |
}); | |
it("should convert x:1, y:1 position to 14", () => { | |
// Given | |
const position = { x: 2, y: 4 }; | |
// When | |
const result = getIndexFromMaxtrixPosition(position); | |
// Then | |
expect(result).toEqual(14); | |
}); | |
}); | |
describe("goUp", () => { | |
it("should move to x:0, y:1", () => { | |
// Given | |
const position = { x: 1, y: 1 }; | |
// When | |
const result = goUp(position); | |
// Then | |
expect(result).toEqual({ x: 0, y: 1 }); | |
}); | |
it("should move to x:1, y:1", () => { | |
// Given | |
const position = { x: 2, y: 1 }; | |
// When | |
const result = goUp(position); | |
// Then | |
expect(result).toEqual({ x: 1, y: 1 }); | |
}); | |
}); | |
describe("goDown", () => { | |
it("should move to x:2, y:1", () => { | |
// Given | |
const position = { x: 1, y: 1 }; | |
// When | |
const result = goDown(position); | |
// Then | |
expect(result).toEqual({ x: 2, y: 1 }); | |
}); | |
it("should move to x:1, y:1", () => { | |
// Given | |
const position = { x: 0, y: 1 }; | |
// When | |
const result = goDown(position); | |
// Then | |
expect(result).toEqual({ x: 1, y: 1 }); | |
}); | |
}); | |
describe("goRight", () => { | |
it("should move to x:1, y:1", () => { | |
// Given | |
const position = { x: 1, y: 0 }; | |
// When | |
const result = goRight(position); | |
// Then | |
expect(result).toEqual({ x: 1, y: 1 }); | |
}); | |
it("should move to x:1, y:1", () => { | |
// Given | |
const position = { x: 1, y: 0 }; | |
// When | |
const result = goRight(position); | |
// Then | |
expect(result).toEqual({ x: 1, y: 1 }); | |
}); | |
}); | |
describe("goLeft", () => { | |
it("should move to x:1, y:0", () => { | |
// Given | |
const position = { x: 1, y: 1 }; | |
// When | |
const result = goLeft(position); | |
// Then | |
expect(result).toEqual({ x: 1, y: 0 }); | |
}); | |
it("should move to x:1, y:1", () => { | |
// Given | |
const position = { x: 1, y: 2 }; | |
// When | |
const result = goLeft(position); | |
// Then | |
expect(result).toEqual({ x: 1, y: 1 }); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment