pointer.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { InstructionPointer } from "../dist/pointer";
  2. test("Initialize a pointer", () => {
  3. const pointer = new InstructionPointer();
  4. expect(pointer.X).toBe(0);
  5. expect(pointer.Y).toBe(0);
  6. expect(pointer.getDirection()).toBe("EAST");
  7. expect(pointer.currentVector).toEqual([1,0]);
  8. expect(pointer.isMovingHorizontally()).toBe(true);
  9. expect(pointer.isMovingVertically()).toBe(false);
  10. });
  11. test("Change the pointer's direction", () => {
  12. const pointer = new InstructionPointer();
  13. pointer.changeDirection("NORTH");
  14. expect(pointer.currentVector).toEqual([0,-1]);
  15. pointer.changeDirection("WEST");
  16. expect(pointer.currentVector).toEqual([-1,0]);
  17. pointer.changeDirection("SOUTH");
  18. expect(pointer.currentVector).toEqual([0,1]);
  19. pointer.changeDirection("EAST");
  20. expect(pointer.currentVector).toEqual([1,0]);
  21. });
  22. test("Move the pointer 1 space east", () => {
  23. const pointer = new InstructionPointer();
  24. pointer.move();
  25. expect(pointer.X).toBe(1);
  26. expect(pointer.Y).toBe(0);
  27. });
  28. test("Move the pointer 1 space east, and 2 spaces south", () => {
  29. const pointer = new InstructionPointer();
  30. pointer.move();
  31. pointer.changeDirection("SOUTH");
  32. pointer.move();
  33. pointer.move();
  34. expect(pointer.X).toBe(1);
  35. expect(pointer.Y).toBe(2);
  36. });