Question: Welcome to the Interplanetary Science Fair! In this assignment, you will be creating a module that calculates the distance between two planets in our solar
Welcome to the Interplanetary Science Fair! In this assignment, you will be creating a module that calculates the distance between two planets in our solar system. You will be using Test Driven Development TDD principles and the Node.js assert library to guide your development process. For this assignment, we will be using Astronomical Units AU to measure distances. AU is the average distance between the Sun to the Earth. You will need to research and find the approximate distance of the planets from the Sun in AU Remember, these are average values, as the actual distances vary as the planets orbit the Sun. Instructions:
Create a new folder for your project following this structure:
distancecalculator
src
distancecalculator.js
test
distancecalculator.spec.js
package.json
In your package.json file, add a test script. Remember to use strict mode. Your distancecalculator.js module should include a function that calculates the distance between two planets in AU given their distances from the sun in AU
For the function in your module, write three diKerent unit tests in the distancecalculator.spec.js using the Node.js assert library. Each test should set up a scenario, call the function with specific inputs, and then assert that the functions output is correct.
Each test should be wrapped in a function named testFunctionDescription, where functionDescription is a brief description of what the test does. For example, a test that checks if the function correctly calculates the distance between Earth and Mars could be named testEarthToMars.
Inside each test function, use a trycatch block to run the test and catch any errors. If the test passes, print a message indicating it passed and return true. If the test fails, print a message indicating the test failed and return false. Below is an example to get you started:
function testEarthToMars
try
assert.strictEqualcalculateDistanceEarth 'Mars' expectedValue;
return true;
catch error
console.errorFailed testEarthToMars: $errormessage;
return false;
Use TDD principles to guide your development process. Write your tests first, then write the code to make the tests pass.
Grading: You will be awarded points for each passing unit test, for a total of points. If a test does not pass, you will not receive points for that test. Use the provide starter files to complete the assignment.
JS distancecalculator.js
JS distancecalculator.js calculateDistance
function calculateDistanceplanet planet
TODO: Implement this function
module.exports calculateDistance;
JS distancecalculator.spec.js
JS distancecalculator.spec.js
const assert requireassert;
const calculateDistance requiresrcdistancecalculator';
function testFunctionDescription
TODOF Implement this function
Call your test functions here
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
