Code covered by the BSD License  

Highlights from
MATLAB xUnit Test Framework

image thumbnail

MATLAB xUnit Test Framework


Steve Eddins (view profile)


31 Jan 2009 (Updated )

MATLAB xUnit is a unit test framework for MATLAB code.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

function test_suite = testAssertAlmostEqual
%testAssertAlmostEqual Unit tests for assertAlmostEqual

%   Steven L. Eddins
%   Copyright 2008 The MathWorks, Inc.


function testEqual
assertAlmostEqual(1, 1);

function testEqualWithThreeInputs
assertAlmostEqual(1, 1.1, 0.2);

function testEqualWithFourInputs
assertExceptionThrown(@() assertAlmostEqual(1, 2, 0.1, 'checkmate'), ...

function testEmptyRelTol
assertAlmostEqual(1, 1+10*eps, [], 'checkmate');

function testNotEqual
assertExceptionThrown(@() assertAlmostEqual(1, 1+1000*eps), ...

function testSingleEqual
assertAlmostEqual(single(1), single(1 + 10*eps('single')));

function testSingleNotEqual
assertExceptionThrown(@() assertAlmostEqual(single(1), ...
    single(1 + 1000*eps('single'))), 'assertAlmostEqual:tolExceeded');

function testZeros
assertAlmostEqual(0, 0);

function testSingleZeros
assertAlmostEqual(single(0), single(0));

function testSparse
assertAlmostEqual(sparse(1), sparse(1 + 10*eps));

Contact us