TEST_NOT_EQUAL

Test if two double arrays are NOT equal up to a desired number of decimal places.

Back to Simple Unit Testing Toolbox Documentation.

Contents

Syntax

TEST_NOT_EQUAL(X1,X2)
TEST_NOT_EQUAL(X1,X2,n)
TEST_NOT_EQUAL(__,name,print,color)
outputs = TEST_NOT_EQUAL(__)

Description

TEST_NOT_EQUAL(X1,X2) tests if X1 and X2 are not equal to 16 decimal places. The results of the test are printed to the Command Window.

TEST_NOT_EQUAL(X1,X2,n) tests if X1 and X2 are not equal to n decimal places. The results of the test are printed to the Command Window.

TEST_NOT_EQUAL(...,name,print,color) does the same as the syntaxes above, but also allows the user to specify a test name, whether or not to print the test results to the Command Window, and whether or not to print those test results in color. This syntax is primarily used when defining unit test classes.

outputs = TEST_NOT_EQUAL(...) also returns the test outputs. Again, this syntax is primarily used when defining unit test classes.

Inputs

Variable Description Format
X1 double array #1 double array
X2 double array #2 double array
n (OPTIONAL) decimal places of precision (defaults to 16) 1×1
double
name (OPTIONAL) test name (defaults to empty string) char array
print (OPTIONAL) true if test result should be printed to Command Window, false otherwise (defaults to true) 1×1
logical
color (OPTIONAL) true if test result should be printed in color, false otherwise (defaults to true) 1×1
logical

Outputs

Variable Description Format
output test outputs

Field Description Format
passed true if test passed, false otherwise 1×1
logical
result string storing result of test char array
message string storing additional diagnostic message char array
1×1
struct

Example #1: Passed test.

Let's define two nearly (but NOT) identical arrays.

X1 = [1  1;
      1  1];
X2 = [1  1;
      1  1.00001];

Testing for inequality,

TEST_NOT_EQUAL(X1,X2);
Passed.
    >>>> WARNING: This test tested for inequality, but the arrays ARE equal to 4 decimal places.

Example #2: Failed test.

Let's define two identical arrays.

X1 = [1  1;
      1  1];
X2 = [1  1;
      1  1];

Testing for equality between these arrays should result in a failed test because they are equal to an infinite amount of decimal places.

TEST_NOT_EQUAL(X1,X2);
FAILED.
    >>>> Arrays are equal to at least 100 decimal places.

Example #3: Testing to a specified precision.

Let's define two nearly (but NOT) identical arrays.

X1 = [1  1;
      1  1];
X2 = [1  1;
      1  1.00001];

While not identical, these arrays are equal to 4 decimal places. If we test for array inequality up to 3 decimal places of precision, we should get a failed test result because the arrays are equal to 4 decimal places.

TEST_NOT_EQUAL(X1,X2,3);
FAILED.
    >>>> Arrays are equal to 4 decimal places.

Example #4: Testing with arrays of different sizes.

Let's define two arrays with elements that all have the same value but have different sizes.

X1 = [1  1];
X2 = [1  1;
      1  1];

If we test for inequality, we should get a passed test because arrays that have different dimensions cannot be equal.

TEST_NOT_EQUAL(X1,X2);
Passed.

See also

TEST_EQUAL