Skip to content

Commit

Permalink
finished mars rover
Browse files Browse the repository at this point in the history
  • Loading branch information
luciemariec committed Feb 25, 2024
1 parent edd1cef commit 94b9cd3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
6 changes: 3 additions & 3 deletions spec/command.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions spec/message.spec.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
56 changes: 51 additions & 5 deletions spec/rover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
});
});

File renamed without changes.

0 comments on commit 94b9cd3

Please sign in to comment.