We can also use T6 to run comparisons on numeric values. The following example shows a few equivalents to using the math tests (e.g. gt) as compared to the standard isTrue() and isFalse() tests. Using the math tests are preferred for 2 reasons.
isTrue() and isFalse() only require a single boolean input)Follow these steps to create a new project workspace and install the t6 dependency to run this example.
# Create and open project folder
mkdir Numeric_Comparisons_demo
cd Numeric_Comparisons_demo
# Initialize project and install dependencies
npm init -y
npm i t6@1.2.1
# Create and open source file
touch "Numeric Comparisons.mjs"
open "Numeric Comparisons.mjs"
Copy and paste this source code into Numeric Comparisons.mjs.
import * as T6 from 't6';
// 5 is greater than 4
T6.gt(5, 4);
T6.isTrue(5 > 4);
// 2 is less than or equal to 2
T6.le(2, 2);
T6.isTrue(2 <= 2);
// 3 is not equal to 0
T6.ne(3, 0)
T6.isTrue(3 !== 0);
T6.isFalse(3 === 0);
// Show that all tests passed.
console.log('All tests passed!');
In Numeric_Comparisons_demo/, execute Numeric Comparisons.mjs with NodeJS to generate an output.
node "Numeric Comparisons.mjs"
You should expect to see an output similar to the one below.
All tests passed!