Challenge: Using Appropriate Assertions
Apply what you have learned about the theory behind assertions by completing a project in this lesson.
Introduction
In this project, you’ll write a unit test that tests the behavior of a class that models a planet and its host star. To frame your state of thinking in designing the unit tests, an assessment rubric is included to indicate whether the principles taught in this section have been considered and applied.
Self-assessment rubric
I have… | Emergent | Satisfactory | Excellent |
---|---|---|---|
Used the correct assertions | Incorrect assertions are used. | Partially correct assertions are used. | Correct assertions used. |
Understood the difference between value and reference types | There is incorrect usage of reference types. | There is partially correct usage of reference types. | There is correct usage of reference types. |
Understood string, value category, enumerable/list and type assertions | There is incorrect usage. | There is partially correct usage. | There is correct usage. |
Asserted floating-point numeric types correctly | No floating-point related assertions are used. | The floating-point range checking is used. | The floating-point range checking and/or percentage and/or ulp checking is used. |
Tested all exceptions | Exceptions are not tested. | Exceptions are partially tested. | All the defined exceptions are tested. |
Quick dive into physics before unit testing
Keep in mind the following facts before attempting the project below.
Large and small numbers with scientific notation
What if you wanted to write down a really large number, like one million? You could write out all the zeros . You could also specify how many zeros there are after the last non-zero digits on the right (the least significant digit). In mathematical terms, this is written as . This is called exponential notation. can also be written as or . It can even be written as .
What if you wanted to represent small numbers? The same principle applies, except that the exponent is negative this time. is . It can also be written as .
The best exponential notation is one where you minimize the number of zeros (usually practiced in scientific notation). Scientific notation is an exponential notation that is standardized to minimize the number of trailing zeros. Following are a few examples of numbers expressed in scientific notation:
- :
- :
- :
- :
With floating-point literals in a C# program, you can initialize a value with scientific notation by using the letter . For example, is written .
Keeping standard units of measure
Calculations must be kept according to a standard unit of measure. Two main measurement systems are used—imperial and S.I. systems. The S.I. units of measure are as follows:
- Distance: Meter (m)
- Time: Second (s)
- Mass: Kilogram (kg)
Gravitational equation
The equation for gravitational force is given as follows:
where is a constant with the value of . The units of measure for seem intimidating but are rather simply derived if you make the subject of the equation and all the other terms and their units of measure are moved to the other side of the equation.
Orbital terminology
When two bodies orbit one another, their closest point is called periapsis and their furthest distance is called apoapsis. This is shown below:
Get hands-on with 1400+ tech skills courses.