# 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 $1000000$. 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 $1 \times 10^6$. This is called **exponential notation**. $1000000$ can also be written as $1000 \times 10^3$ or $100000 \times 10^1$. It can even be written as $0.01 \times 10^8$.

What if you wanted to represent small numbers? The same principle applies, except that the exponent is negative this time. $0.000001$ is $1 \times 10^{-6}$. It can also be written as $0.01 \times 10^{-4}$.

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:

- $0.000456$: $4.56 \times 10^-4$
- $0.01451$: $1.451 \times 10^-2$
- $1023322$: $1.023322 \times 10^6$
- $344555.353$: $3.44555353 \times 10^5$

With floating-point literals in a C# program, you can initialize a value with scientific notation by using the letter $e$. For example, $4.56 \times 10^-4$ is written $4.56e-4$.

### 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:

$F = \frac{G M_1 M_2}{r^2}$ where $G$ is a constant with the value of $6.674 \times 10^{-11}N \space m^{2} \space kg^{-2}$. The units of measure for $G$ seem intimidating but are rather simply derived if you make $G$ 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 1200+ tech skills courses.