%% Test a Class That Represents Polynomials
% Use verifications to test the DocPolynom class, which represents polynomials in MATLAB®. For more information about the class, see Representing Polynomials with Classes.
% In a file in your current folder, create the DocPolynomTest class, which tests different methods of the DocPolynom class. To access DocPolynom in your tests, define the addDocPolynomClassToPath method within a TestClassSetup methods block. The method uses a PathFixture instance to add the examples folder, including the DocPolynom class definition file, to the search path. Once the tests run to completion, the testing framework tears down the fixture and restores the path to its previous state.
% classdef DocPolynomTest < matlab.unittest.TestCase
%     properties
%         TextToDisplay = "Equation under test: "
%     end
%
%     methods (TestClassSetup)
%         function addDocPolynomClassToPath(testCase)
%             import matlab.unittest.fixtures.PathFixture
%             folder = fullfile(matlabroot, ...
%                 "help","techdoc","matlab_oop","examples");
%             testCase.applyFixture(PathFixture(folder))
%         end
%     end
% end
% Now, add your tests to a methods block with the Test attribute. To test the DocPolynom class, use verifications within three Test methods:
% testConstructor method — Use verifyClass to test the DocPolynom class constructor.
% testAddition method — Use verifyEqual to test the addition of DocPolynom objects.
% testMultiplication method — Use verifyEqual to test the multiplication of DocPolynom objects.
% classdef DocPolynomTest < matlab.unittest.TestCase
%     properties
%         TextToDisplay = "Equation under test: "
%     end
%
%     methods (TestClassSetup)
%         function addDocPolynomClassToPath(testCase)
%             import matlab.unittest.fixtures.PathFixture
%             folder = fullfile(matlabroot, ...
%                 "help","techdoc","matlab_oop","examples");
%             testCase.applyFixture(PathFixture(folder))
%         end
%     end
%
%     methods (Test)
%         function testConstructor(testCase)
%             p = DocPolynom([1 0 1]);
%             testCase.verifyClass(p,?DocPolynom)
%         end
%
%         function testAddition(testCase)
%             p1 = DocPolynom([1 0 1]);
%             p2 = DocPolynom([5 2]);
%             actual = p1 + p2;
%             expected = DocPolynom([1 5 3]);
%             diagnostic = [testCase.TextToDisplay ...
%                 "(x^2 + 1) + (5*x + 2) = x^2 + 5*x + 3"];
%             testCase.verifyEqual(actual,expected,diagnostic)
%         end
%
%         function testMultiplication(testCase)
%             p1 = DocPolynom([1 0 3]);
%             p2 = DocPolynom([5 2]);
%             actual = p1 * p2;
%             expected = DocPolynom([5 2 15 6]);
%             diagnostic = [testCase.TextToDisplay ...
%                 "(x^2 + 3) * (5*x + 2) = 5*x^3 + 2*x^2 + 15*x + 6"];
%             testCase.verifyEqual(actual,expected,diagnostic)
%         end
%     end
% end
% Run the tests in the DocPolynomTest class. In this example, all the tests pass.

runtests("DocPolynomTest")

% Copyright 2021 The MathWorks, Inc.