|
| 1 | +Robot = require 'robot_simulator' |
| 2 | + |
| 3 | +describe 'robot-simulator', -> |
| 4 | + describe 'Create robot', -> |
| 5 | + it 'at origin facing north', -> |
| 6 | + robot = Robot x: 0, y: 0, direction: 'north' |
| 7 | + assert.are.equal 0, robot\x! |
| 8 | + assert.are.equal 0, robot\y! |
| 9 | + assert.are.equal 'north', robot\direction! |
| 10 | + |
| 11 | + pending 'at negative position facing south', -> |
| 12 | + robot = Robot x: -1, y: -1, direction: 'south' |
| 13 | + assert.are.equal -1, robot\x! |
| 14 | + assert.are.equal -1, robot\y! |
| 15 | + assert.are.equal 'south', robot\direction! |
| 16 | + |
| 17 | + describe 'Rotating clockwise', -> |
| 18 | + pending 'changes north to east', -> |
| 19 | + robot = Robot x: 0, y: 0, direction: 'north' |
| 20 | + robot\move 'R' |
| 21 | + assert.are.equal 0, robot\x! |
| 22 | + assert.are.equal 0, robot\y! |
| 23 | + assert.are.equal 'east', robot\direction! |
| 24 | + |
| 25 | + pending 'changes east to south', -> |
| 26 | + robot = Robot x: 0, y: 0, direction: 'east' |
| 27 | + robot\move 'R' |
| 28 | + assert.are.equal 0, robot\x! |
| 29 | + assert.are.equal 0, robot\y! |
| 30 | + assert.are.equal 'south', robot\direction! |
| 31 | + |
| 32 | + pending 'changes south to west', -> |
| 33 | + robot = Robot x: 0, y: 0, direction: 'south' |
| 34 | + robot\move 'R' |
| 35 | + assert.are.equal 0, robot\x! |
| 36 | + assert.are.equal 0, robot\y! |
| 37 | + assert.are.equal 'west', robot\direction! |
| 38 | + |
| 39 | + pending 'changes west to north', -> |
| 40 | + robot = Robot x: 0, y: 0, direction: 'west' |
| 41 | + robot\move 'R' |
| 42 | + assert.are.equal 0, robot\x! |
| 43 | + assert.are.equal 0, robot\y! |
| 44 | + assert.are.equal 'north', robot\direction! |
| 45 | + |
| 46 | + describe 'Rotating counter-clockwise', -> |
| 47 | + pending 'changes north to west', -> |
| 48 | + robot = Robot x: 0, y: 0, direction: 'north' |
| 49 | + robot\move 'L' |
| 50 | + assert.are.equal 0, robot\x! |
| 51 | + assert.are.equal 0, robot\y! |
| 52 | + assert.are.equal 'west', robot\direction! |
| 53 | + |
| 54 | + pending 'changes west to south', -> |
| 55 | + robot = Robot x: 0, y: 0, direction: 'west' |
| 56 | + robot\move 'L' |
| 57 | + assert.are.equal 0, robot\x! |
| 58 | + assert.are.equal 0, robot\y! |
| 59 | + assert.are.equal 'south', robot\direction! |
| 60 | + |
| 61 | + pending 'changes south to east', -> |
| 62 | + robot = Robot x: 0, y: 0, direction: 'south' |
| 63 | + robot\move 'L' |
| 64 | + assert.are.equal 0, robot\x! |
| 65 | + assert.are.equal 0, robot\y! |
| 66 | + assert.are.equal 'east', robot\direction! |
| 67 | + |
| 68 | + pending 'changes east to north', -> |
| 69 | + robot = Robot x: 0, y: 0, direction: 'east' |
| 70 | + robot\move 'L' |
| 71 | + assert.are.equal 0, robot\x! |
| 72 | + assert.are.equal 0, robot\y! |
| 73 | + assert.are.equal 'north', robot\direction! |
| 74 | + |
| 75 | + describe 'Moving forward one', -> |
| 76 | + pending 'facing north increments Y', -> |
| 77 | + robot = Robot x: 0, y: 0, direction: 'north' |
| 78 | + robot\move 'A' |
| 79 | + assert.are.equal 0, robot\x! |
| 80 | + assert.are.equal 1, robot\y! |
| 81 | + assert.are.equal 'north', robot\direction! |
| 82 | + |
| 83 | + pending 'facing south decrements Y', -> |
| 84 | + robot = Robot x: 0, y: 0, direction: 'south' |
| 85 | + robot\move 'A' |
| 86 | + assert.are.equal 0, robot\x! |
| 87 | + assert.are.equal -1, robot\y! |
| 88 | + assert.are.equal 'south', robot\direction! |
| 89 | + |
| 90 | + pending 'facing east increments X', -> |
| 91 | + robot = Robot x: 0, y: 0, direction: 'east' |
| 92 | + robot\move 'A' |
| 93 | + assert.are.equal 1, robot\x! |
| 94 | + assert.are.equal 0, robot\y! |
| 95 | + assert.are.equal 'east', robot\direction! |
| 96 | + |
| 97 | + pending 'facing west decrements X', -> |
| 98 | + robot = Robot x: 0, y: 0, direction: 'west' |
| 99 | + robot\move 'A' |
| 100 | + assert.are.equal -1, robot\x! |
| 101 | + assert.are.equal 0, robot\y! |
| 102 | + assert.are.equal 'west', robot\direction! |
| 103 | + |
| 104 | + describe 'Follow series of instructions', -> |
| 105 | + pending 'moving east and north from README', -> |
| 106 | + robot = Robot x: 7, y: 3, direction: 'north' |
| 107 | + robot\move 'RAALAL' |
| 108 | + assert.are.equal 9, robot\x! |
| 109 | + assert.are.equal 4, robot\y! |
| 110 | + assert.are.equal 'west', robot\direction! |
| 111 | + |
| 112 | + pending 'moving west and north', -> |
| 113 | + robot = Robot x: 0, y: 0, direction: 'north' |
| 114 | + robot\move 'LAAARALA' |
| 115 | + assert.are.equal -4, robot\x! |
| 116 | + assert.are.equal 1, robot\y! |
| 117 | + assert.are.equal 'west', robot\direction! |
| 118 | + |
| 119 | + pending 'moving west and south', -> |
| 120 | + robot = Robot x: 2, y: -7, direction: 'east' |
| 121 | + robot\move 'RRAAAAALA' |
| 122 | + assert.are.equal -3, robot\x! |
| 123 | + assert.are.equal -8, robot\y! |
| 124 | + assert.are.equal 'south', robot\direction! |
| 125 | + |
| 126 | + pending 'moving east and north', -> |
| 127 | + robot = Robot x: 8, y: 4, direction: 'south' |
| 128 | + robot\move 'LAAARRRALLLL' |
| 129 | + assert.are.equal 11, robot\x! |
| 130 | + assert.are.equal 5, robot\y! |
| 131 | + assert.are.equal 'north', robot\direction! |
0 commit comments