%% Test 2: isosceles triangles
angles = rightTri(triIso);
assert(angles(1) == 45)
assert(angles(1) == angles(2))
%% Test 3: 30-60-90 triangle
angles = rightTri(tri306090);
assert(angles(1) == 30)
assert(angles(2) == 60)
assert(angles(3) == 90)
%% Test 4: Small angle approximation
angles = rightTri(triSkewed);
smallAngle = (pi/180)*angles(1); % radians
approx = sin(smallAngle);
assert(approx == smallAngle, 'Problem with small angle approximation')
Test 1 tests the summation of the triangle angles. If the summation is not equal to 180
degrees, assert throws an error.
Test 2 tests that if two sides are equal, the corresponding angles are equal. If the non-
right angles are not both equal to 45 degrees, the assert function throws an error.
Test 3 tests that if the triangle sides are 1 and sqrt(3), the angles are 30, 60, and 90
degrees. If this condition is not true, assert throws an error.
Test 4 tests the small-angle approximation. The small-angle approximation states that for
small angles the sine of the angle in radians is approximately equal to the angle. If it is
not true, assert throws an error.
Run Tests
Execute the runtests function to run the four tests in rightTriTest.m. The runtests
function executes each test in each code section individually. If Test 1 fails, MATLAB still
runs the remaining tests. If you execute rightTriTest as a script instead of by using
runtests, MATLAB halts execution of the entire script if it encounters a failed assertion.
Additionally, when you run tests using the runtests function, MATLAB provides
informative test diagnostics.
result = runtests('rightTriTest');
Running rightTriTest
..
33 Unit Testing