Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This section presents several test suites for different boundary conditions. This section introduces several test suites for different boundary conditions based on the get_triangle_area() function. It takes two filenames as a parameter, one for the length of the base of the triangle and one for its height. It reads each line and calculates the correct area of the triangle for each line.

  • CheckType 

    At

    first,

    it

    would

    be

    appropriate

    to

    check

    that

    the

    return

    type

    is

    correct.

    In

    a

    given

    project,

    the

    function

    returns

    a

    vector

    of

    floats, and each of its elements is a calculated area

    floats, and each of its elements is a calculated area. Test suite below:

    Code Block
    languagecpp
    titleTEST(GetTriangleArea, CheckType)
    linenumberstrue
    TEST(GetTriangleArea, CheckType) {
        std::string height_file = "triangle_height.txt";
        std::string base_file = "triangle_base.txt";
        EXPECT_EQ(typeid(std::vector<float>), typeid(get_triangle_area(base_file, height_file)));
    }

    The function under test is quite complex and takes up a lot of lines, so there's no room for it here, but it's worth learning how it works. In this test suite, it is important to provide valid file names, use typeid() to determine the argument type, and use the EXPECT_EQ assertion to verify that it is the same as vector<float>.