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
Card.cpp vs Card.h
cpp - how it looks - the declarations
include where?
.h - header - how it works, definitions
include where?
what to use so that you only include a file once
hashsymbol
pragma once
what are the only files that will be included
.h
preprocessor
a tool that scans the file from top to bottom looking for any lines that begin with #
what does “” and <> tell the preprocessor
”” - same folder directory as the including file
<>- look in the system’s standard library folder/directory
header file guards
preprocessor directives that cause the compiler to only include the contents of the header file once
hash ifndef FILENAME_H
hash define FILENAME_H
//contents
hash endif
single step compilation
all source files are compiled at the same time to create the executable
g++ main.cpp filename.cpp
modular compilation
each source file is independently compiled into an object file
g++ main.o filename.o
object file
contains machine instructions for the compiled code along with placeholders, often referred to as references, for calls to functions or accesses to variables or classes defined in other source files
linker
will create the final executable by linking together the object files and libraries
define directive
hash define MACROIDENTIFIER replacement
- instructs the processor to replace any occurrence of MACROIDENTIFEIR in the subsequent program code by the replacement test
name conflict
occurs when 2 or more items like variables, classes, or functions have the same name
namespace
defines a region(or scope) used to prevent name conflicts
in main
fileName :: classname
in .h file
namespace fileName {
class className{
…
};
}
std
standard namespace
look over lecture notes