|
| 1 | +;;; robot-simulator-test.el --- Tests for robot-simulator (exercism) -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;;; Commentary: |
| 4 | + |
| 5 | +;;; Code: |
| 6 | + |
| 7 | + |
| 8 | +(load-file "robot-simulator.el") |
| 9 | +(declare-function create-robot "robot-simulator.el" (x y direction)) |
| 10 | +(declare-function move "robot-simulator.el" (robot instructions)) |
| 11 | + |
| 12 | + |
| 13 | +(ert-deftest create-robot-at-origin-facing-north () |
| 14 | + (should (equal #s(robot 0 0 north) |
| 15 | + (create-robot 0 0 'north)))) |
| 16 | + |
| 17 | + |
| 18 | +(ert-deftest create-robot-at-negative-position-facing-south () |
| 19 | + (should (equal #s(robot -1 -1 south) |
| 20 | + (create-robot -1 -1 'south)))) |
| 21 | + |
| 22 | + |
| 23 | +(ert-deftest rotating-clockwise-changes-north-to-east () |
| 24 | + (should (equal #s(robot 0 0 east) |
| 25 | + (move (create-robot 0 0 'north) "R")))) |
| 26 | + |
| 27 | + |
| 28 | +(ert-deftest rotating-clockwise-changes-east-to-south () |
| 29 | + (should (equal #s(robot 0 0 south) |
| 30 | + (move (create-robot 0 0 'east) "R")))) |
| 31 | + |
| 32 | + |
| 33 | +(ert-deftest rotating-clockwise-changes-south-to-west () |
| 34 | + (should (equal #s(robot 0 0 west) |
| 35 | + (move (create-robot 0 0 'south) "R")))) |
| 36 | + |
| 37 | + |
| 38 | +(ert-deftest rotating-clockwise-changes-west-to-north () |
| 39 | + (should (equal #s(robot 0 0 north) |
| 40 | + (move (create-robot 0 0 'west) "R")))) |
| 41 | + |
| 42 | + |
| 43 | +(ert-deftest rotating-counter-clockwise-changes-north-to-west () |
| 44 | + (should (equal #s(robot 0 0 west) |
| 45 | + (move (create-robot 0 0 'north) "L")))) |
| 46 | + |
| 47 | + |
| 48 | +(ert-deftest rotating-counter-clockwise-changes-west-to-south () |
| 49 | + (should (equal #s(robot 0 0 south) |
| 50 | + (move (create-robot 0 0 'west) "L")))) |
| 51 | + |
| 52 | + |
| 53 | +(ert-deftest rotating-counter-clockwise-changes-south-to-east () |
| 54 | + (should (equal #s(robot 0 0 east) |
| 55 | + (move (create-robot 0 0 'south) "L")))) |
| 56 | + |
| 57 | + |
| 58 | +(ert-deftest rotating-counter-clockwise-changes-east-to-north () |
| 59 | + (should (equal #s(robot 0 0 north) |
| 60 | + (move (create-robot 0 0 'east) "L")))) |
| 61 | + |
| 62 | + |
| 63 | +(ert-deftest moving-forward-one-facing-north-increments-y () |
| 64 | + (should (equal #s(robot 0 1 north) |
| 65 | + (move (create-robot 0 0 'north) "A")))) |
| 66 | + |
| 67 | + |
| 68 | +(ert-deftest moving-forward-one-facing-south-decrements-y () |
| 69 | + (should (equal #s(robot 0 -1 south) |
| 70 | + (move (create-robot 0 0 'south) "A")))) |
| 71 | + |
| 72 | + |
| 73 | +(ert-deftest moving-forward-one-facing-east-increments-x () |
| 74 | + (should (equal #s(robot 1 0 east) |
| 75 | + (move (create-robot 0 0 'east) "A")))) |
| 76 | + |
| 77 | + |
| 78 | +(ert-deftest moving-forward-one-facing-west-decrements-x () |
| 79 | + (should (equal #s(robot -1 0 west) |
| 80 | + (move (create-robot 0 0 'west) "A")))) |
| 81 | + |
| 82 | + |
| 83 | +(ert-deftest follow-series-of-instructions-moving-east-and-north-from-README () |
| 84 | + (should (equal #s(robot 9 4 west) |
| 85 | + (move (create-robot 7 3 'north) "RAALAL")))) |
| 86 | + |
| 87 | + |
| 88 | +(ert-deftest follow-series-of-instructions-moving-west-and-north () |
| 89 | + (should (equal #s(robot -4 1 west) |
| 90 | + (move (create-robot 0 0 'north) "LAAARALA")))) |
| 91 | + |
| 92 | + |
| 93 | +(ert-deftest follow-series-of-instructions-moving-west-and-south () |
| 94 | + (should (equal #s(robot -3 -8 south) |
| 95 | + (move (create-robot 2 -7 'east) "RRAAAAALA")))) |
| 96 | + |
| 97 | + |
| 98 | +(ert-deftest follow-series-of-instructions-moving-east-and-north () |
| 99 | + (should (equal #s(robot 11 5 north) |
| 100 | + (move (create-robot 8 4 'south) "LAAARRRALLLL")))) |
| 101 | + |
| 102 | + |
| 103 | +(provide 'robot-simulator-test) |
| 104 | +;;; robot-simulator-test.el ends here |
0 commit comments