Testing the Rust program
One important part of programming is testing the application. There are many kinds of tests, such as unit tests (to test a single function or method), functional tests (to test the function of an application), and integration testing (to test various units and functions as a single combined entity). Various tests should be conducted in order to make the application as correct as intended.
In the Rust standard library, there are three macros to use in testing: assert!
, assert_eq!
, and assert_ne!
. The assert!
macro accepts one or more parameters. The first parameter is any statement that evaluates to Boolean, and the rest is for debugging if the result is not what is expected.
The assert_eq!
macro compares equality between the first parameter and second parameter, and the rest is for debugging if the result is not what is expected. The assert_ne!
macro is the opposite of assert_eq!
; this macro tests the inequality between the first and the second parameters...