Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions exercises/robot-simulator/example.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export class InvalidInputError extends Error {
constructor(message) {
super();
this.message = message || 'Invalid Input';
}
}

class Robot {
constructor() {
this.coordinates = [0, 0];
Expand All @@ -9,6 +16,11 @@ class Robot {
}

orient(direction) {
const validDirections = ['north', 'south', 'east', 'west'];
if (!validDirections.includes(direction)) {
throw new InvalidInputError('Invalid Robot Bearing');
}

this.bearing = direction;
return `The robot is pointed ${direction}`;
}
Expand Down
8 changes: 3 additions & 5 deletions exercises/robot-simulator/robot-simulator.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Robot from './robot-simulator';
import { InvalidInputError } from './robot-simulator';

describe('Robot', () => {
const robot = new Robot();
Expand All @@ -13,11 +14,8 @@ describe('Robot', () => {
});

xtest('invalid robot bearing', () => {
try {
robot.orient('crood');
} catch (exception) {
expect(exception).toEqual('Invalid Robot Bearing');
}
expect(InvalidInputError.prototype).toBeInstanceOf(Error);
expect(() => robot.orient('crood')).toThrow(InvalidInputError);
});

xtest('turn right from north', () => {
Expand Down