12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { InstructionPointer } from "../dist/pointer";
- test("Initialize a pointer", () => {
- const pointer = new InstructionPointer();
- expect(pointer.X).toBe(0);
- expect(pointer.Y).toBe(0);
- expect(pointer.getDirection()).toBe("EAST");
- expect(pointer.currentVector).toEqual([1,0]);
- expect(pointer.isMovingHorizontally()).toBe(true);
- expect(pointer.isMovingVertically()).toBe(false);
- });
- test("Change the pointer's direction", () => {
- const pointer = new InstructionPointer();
- pointer.changeDirection("NORTH");
- expect(pointer.currentVector).toEqual([0,-1]);
- pointer.changeDirection("WEST");
- expect(pointer.currentVector).toEqual([-1,0]);
- pointer.changeDirection("SOUTH");
- expect(pointer.currentVector).toEqual([0,1]);
- pointer.changeDirection("EAST");
- expect(pointer.currentVector).toEqual([1,0]);
- });
- test("Move the pointer 1 space east", () => {
- const pointer = new InstructionPointer();
- pointer.move();
- expect(pointer.X).toBe(1);
- expect(pointer.Y).toBe(0);
- });
- test("Move the pointer 1 space east, and 2 spaces south", () => {
- const pointer = new InstructionPointer();
- pointer.move();
- pointer.changeDirection("SOUTH");
- pointer.move();
- pointer.move();
- expect(pointer.X).toBe(1);
- expect(pointer.Y).toBe(2);
- });
|