CS Week 4- Classes ll Flashcards
test bench
a program whose job is to thoroughly test another program (or portion) via a series of input/output checks (test cases)
test cases
a series of input/output checks
unit testing
to create and run a rest bench for a specific item like a function or a class
some features of a good test bench
–Automatically checks(only fails printed → test.GetNum() != 100)
–Independent test cases
–100% coverage - every line of code is excited
—Include border cases
Regression testing
to retest an item like a class anytime that item is changed
regressed
If previous passed cases fail
why should a test bench be maintained along with the item
to be usable for regression testing
erroneous unit tests
may fail even if the code being tested is correct
operator overloading
built-in operators to operate on programmer-defined objects
overload +
Create a member function named operator+
pass in an argument (literally anything but better an object)
create a new objects
add the sub items
return the object
overload the + multiple times
as long as each involves different types of parameters
overload ==
create a member function named operator==
return a bool
take in 2 const reference parameters
compare the corresponding items in the return statement
overload the < operator
return a bool
pass in 2 const reference parameters
if the lhs is < the rhs
overloading all equality and relational operators
1st overload the == and < and use these for the rest of the
overload the !
return a bool
pass in 2 const reference parameters
return !(lhs==rhs)
overload >
return a bool
pass in 2 const reference parameters
return rhs < lhs
overload <=
return a bool
pass in 2 const reference parameters
return !(lhs>rhs)
overload >=
return a bool
pass in 2 const reference parameters
return !(lhs<rhs)
using sort() function
include <algorithm></algorithm>
overload the < operator for the defined class
call sort()
sort(v.begin(), v.end());
overload the «
into a buffer of wanting to output all the subitems of a class
overload the»_space;
into a buffer of wanting to input into all the subitems of a class
why use “friend”
can see the sub items of the class
only use the friend in the declaration not definition
in what order to include files in main
alphabetical order
<> then “”
in what order to include files in implementation file
”” first