MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

angles = rightTri(triIso);
assert(angles(1) == 45)
assert(angles(1) == angles(2))


%% Test 3: 30-60-90 triangle
angles = rightTri(tri306090);
assert(abs(angles(1)-30) <= tol)
assert(abs(angles(2)-60) <= tol)
assert(abs(angles(3)-90) <= tol)


%% Test 4: Small angle approximation
angles = rightTri(triSkewed);
smallAngle = (pi/180)*angles(1); % radians
approx = sin(smallAngle);
assert(abs(approx-smallAngle) <= tol, 'Problem with small angle approximation')


Rerun the tests.


result = runtests('rightTriTolTest');


Running rightTriTolTest
....
Done rightTriTolTest




All the tests pass.


Create a table of test results.


rt = table(result)


rt =


4x6 table


Name Passed Failed Incomplete Duration Details




'rightTriTolTest/Test1_SumOfAngles' true false false 0.064251 [1x1 struct]
'rightTriTolTest/Test2_IsoscelesTriangles' true false false 0.01851 [1x1 struct]
'rightTriTolTest/Test3_30_60_90Triangle' true false false 0.017989 [1x1 struct]


Write Script-Based Unit Tests
Free download pdf