Commit ab6b5e4f authored by Stefanie Hasler's avatar Stefanie Hasler

tcr

parent a9b20860
......@@ -10,19 +10,28 @@ class MarsRover {
}
forward(): MarsRover {
this.y++
if (this.dir === 'E') {
this.x++
}
else {
this.y++
}
return this
}
right(): MarsRover {
switch(this.dir) {
case 'N': this.dir = 'E'
switch (this.dir) {
case 'N':
this.dir = 'E'
break
case 'E': this.dir = 'S'
case 'E':
this.dir = 'S'
break
case 'S': this.dir = 'W'
case 'S':
this.dir = 'W'
break
case 'W': this.dir = 'N'
case 'W':
this.dir = 'N'
}
return this
}
......@@ -49,8 +58,11 @@ describe("MarsRover", () => {
expect(new MarsRover().right().right().right().pos()).to.equal('0,0,W')
})
it('should turn right four times, then point forward', () => {
it('should turn right four times, then point north', () => {
expect(new MarsRover().right().right().right().right().pos()).to.equal('0,0,N')
})
it('should turn right, move forward, and have moved east', () => {
expect(new MarsRover().right().forward().pos()).to.equal('1,0,E')
})
})
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment