diff --git a/spec/command.spec.js b/spec/command.spec.js index ad709502..79796398 100644 --- a/spec/command.spec.js +++ b/spec/command.spec.js @@ -4,16 +4,16 @@ const Command = require('../command.js'); // However, do NOT edit the grading tests for any reason and make sure to un-comment out your code to get the autograder to pass. describe("Command class", function() { - +//Test 1 it("throws error if command type is NOT passed into constructor as the first parameter", function() { expect( function() { new Command();}).toThrow(new Error('Command type required.')); }); - +//Test 2 it("constructor sets command type", function() { let command = new Command('someType'); expect(command.commandType).toBe('someType'); }); - +//Test 3 it("constructor sets a value passed in as the 2nd argument", function() { let value = 'someValue'; let command = new Command('someType', value); diff --git a/spec/message.spec.js b/spec/message.spec.js index eed5b628..dfe6b942 100644 --- a/spec/message.spec.js +++ b/spec/message.spec.js @@ -1,20 +1,18 @@ const Message = require('../message.js'); const Command = require('../command.js'); -// NOTE: If at any time, you want to focus on the output from a single test, feel free to comment out all the others. -// However, do NOT edit the grading tests for any reason and make sure to un-comment out your code to get the autograder to pass. describe("Message class", function() { - +//Test 4 it("throws error if a name is NOT passed into the constructor as the first parameter", function() { expect( function() { new Message();}).toThrow(new Error('Name required.')); }); - +//Test 5 it("constructor sets name", function() { let name = new Message('someName'); expect(name.name).toBe('someName'); }); - +//Test 6 it("contains a commands array passed into the constructor as the 2nd argument", function() { let commands = [new Command('command1'), new Command('command2')]; let message = new Message('someName', commands); diff --git a/spec/rover.spec.js b/spec/rover.spec.js index 000bd166..2c44d491 100644 --- a/spec/rover.spec.js +++ b/spec/rover.spec.js @@ -2,9 +2,6 @@ const Rover = require('../rover.js'); const Message = require('../message.js'); const Command = require('../command.js'); -// NOTE: If at any time, you want to focus on the output from a single test, feel free to comment out all the others. -// However, do NOT edit the grading tests for any reason and make sure to un-comment out your code to get the autograder to pass. - describe("Rover class", function() { //Test 7 @@ -14,6 +11,55 @@ it("constructor sets position and default values for mode and generatorWatts", f expect(roverTest.mode).toEqual('NORMAL'); expect(roverTest.generatorWatts).toEqual(110); }); - - +//Test 8 +it("response returned by receiveMessage contains the name of the message", function() { + let roverTest = new Rover(87382098); + let commands = [new Command('STATUS_CHECK')]; + let message = new Message('Test message', commands); + let response = roverTest.receiveMessage(message); + expect(response.message).toEqual('Test message'); +}); +//Test 9 +it("response returned by receiveMessage includes two results if two commands are sent in the message", function() { + let roverTest = new Rover(87382098); + let commands = [new Command('STATUS_CHECK'), new Command('MOVE', 123)]; + let message = new Message('Test message', commands); + let response = roverTest.receiveMessage(message); + expect(response.results.length).toEqual(2); +}); +//Test 10 +it("responds correctly to the status check command", function() { + let roverTest = new Rover(87382098); + let commands = [new Command('STATUS_CHECK')]; + let message = new Message('Test message', commands); + let response = roverTest.receiveMessage(message); + expect(response.results[0].roverStatus.mode).toEqual(roverTest.mode); +}); +//Test 11 +it("responds correctly to the mode change command", function() { + let roverTest = new Rover(87382098); + let commands = [new Command('MODE_CHANGE', 'LOW_POWER')]; + let message = new Message('Test message', commands); + let response = roverTest.receiveMessage(message); + expect(response.results[0].completed).toEqual(true); }); +//Test 12 +it("responds with a false completed value when attempting to move in LOW_POWER mode", function() { + let roverTest = new Rover(87382098); + roverTest.mode = 'LOW_POWER'; + let commands = [new Command('MOVE', 123)]; + let message = new Message('Test message', commands); + let response = roverTest.receiveMessage(message); + expect(response.results[0].completed).toEqual(false); +}); +//Test 13 +it("responds with the position for the move command", function() { + let roverTest = new Rover(87382098); + let newPosition = 500; + let commands = [new Command('MOVE', newPosition)]; + let message = new Message('Test message', commands); + let response = roverTest.receiveMessage(message); + expect(roverTest.position).toEqual(newPosition); +}); +}); + diff --git a/spec/studentgrade.specx.js b/spec/studentgrade.spec.js similarity index 100% rename from spec/studentgrade.specx.js rename to spec/studentgrade.spec.js