This task puts your unit testing, modules making, and exception handling knowledge to use by writing tests and classes for the Mars rover named Curiosity.
You will create a simulation for issuing commands to Curiosity. The idea is to create a command at mission control, convert that command into a message send it to the rover, then have the rover respond to that message.
We will provide descriptions of the required features you need to implement in three separate classes:
Command: A type of object containing a
commandTypeis one of the given strings in the table below. Some
commandTypesare coupled with a
valueproperty, but not all. Every
Commandobject is a single instruction to be delivered to the rover.
Messageobject has a
nameand contains several
Messageis responsible for bundling the commands from mission control and delivering them to the rover.
Rover: An object representing the mars rover. This class contains information on the rover's
generatorWatts. It also contains a function,
receiveMessagethat handles the various types of commands it receives and updates the rover's properties.
In true TDD form, you will be asked to first write the appropriate units tests for these features, then write the code in the given class to pass those tests.
Recall that in TDD, you write the test for a given behavior before you code the actual function. Feel free to review the Test/Code cycle while you work on this project.
Each numbered item describes a test. You should use the given phrases as the
test descriptions when creating your
it statements. You must create 13
tests for this assignment.
Do NOT try to write all of the tests at once. Doing so will be inefficient and will cause excessive frustration.
We'll follow TDD practices for the creation of
Rover, but for
Command, we've provided the functionality.
Command is already
written for you and you do not need to modify it to write passing tests. Open up and
examine the file
commandTypeis a string that represents the type of command. We will go over the details of the types when we get to the
Roverclass and tests. At this time, note that a command type will be one of the following:
valueis a value related to the type of command.
let modeCommand = new Command('MODE_CHANGE', 'LOW_POWER'); let moveCommand = new Command('MOVE', 12000);
'MOVE' are passed in as the
'LOW_POWER' and 12000 are passed in as the
value. Different command
types require different kinds of values.
'STATUS_CHECK' takes no value.
Don't worry about the mode options for now. To peek ahead, see Rover Modes table.
Now that we've gone over the class, let's check out the tests.
To begin, open and examine
spec/command.spec.js. One test has been created for
you. When a user creates a new
Command object from the class, we want to make
sure they pass a command type as the first argument.
Note that the test description reads, "throws error if a command type is NOT passed into the constructor as the first parameter".
command.js. Click "Run" again to verify that the test fails (the expected error is not thrown when the
Commandclass is called).
throw Error("Command type required.");.
message: 'Oops'. Click "Run" again to verify that the test fails (the error message did not match
"Command type required.").
message: "Command type required.".
Create a second
Command test using, "constructor sets command type" as the
description. This test checks that the
constructor in the
class correctly sets the
commandType property in the new object.
command.jscontains the correct code. Click "Run" to verify that the first and second tests both pass.
Code a third test using, "constructor sets a value passed in as the 2nd
argument" as the description. This test checks that the
correctly sets the
value property in the new object.
valuein order to write this test.
Click "Run" to verify that all 3 command tests pass.
As you move through the remaining instructions, the amount of guidance will decrease. Refer to your earlier, passing tests to help you construct new tests and passing code.
Great job, astronaut! When you are ready to keep going, check out Part 2!
Rover class is completed and you have written 13 passing specs, you are ready to submit.
Make sure that you did not edit either
grading.js, or any file in the
helpers directory inside
Changes to these files could effect your grade.
In Canvas, open the Mars Rover assignment and click the "Submit" button. An input box will appear.
Copy the URL for your repl and paste it into the box, then click "Submit" again.