Эх сурвалжийг харах

Add tests for InstructionPointer class

ApisNecros 1 жил өмнө
parent
commit
2859685137
1 өөрчлөгдсөн 40 нэмэгдсэн , 0 устгасан
  1. 40 0
      tests/pointer.test.js

+ 40 - 0
tests/pointer.test.js

@@ -0,0 +1,40 @@
+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);
+});