Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CSE3150_Project/Test.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
101 lines (82 sloc)
1.93 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Test.h" | |
UnitTest :: UnitTest() | |
: passed(true) | |
{ | |
} | |
UnitTest :: ~UnitTest() | |
{ | |
} | |
void UnitTest :: TestIntro() | |
{ | |
std::cout << "UNIT TEST ===> " << testName << std::endl; | |
} | |
void UnitTest :: TestConclusion() | |
{ | |
std::cout << "TEST: " << testName << " " << (passed ? "PASSED" : "FAILED") << std::endl << std::endl; | |
} | |
bool UnitTest :: Passed() | |
{ | |
return passed; | |
} | |
// UnitTest protected Methods | |
void UnitTest :: Fail() | |
{ | |
passed = false; | |
} | |
void UnitTest :: AssertTrue(bool expression) | |
{ | |
if (!expression) { Fail(); } | |
} | |
void UnitTest :: AssertFalse(bool expression) | |
{ | |
if (expression) { Fail(); } | |
} | |
// ComponentTest class | |
ComponentTest :: ComponentTest() | |
: run(0), failed(0), passed(0) | |
{ | |
} | |
ComponentTest :: ~ComponentTest() | |
{ | |
for (UnitTest *test : tests) { | |
delete test; | |
} | |
tests.clear(); | |
} | |
void ComponentTest :: PrintIntro() | |
{ | |
std::cout << "========================================================================" << std::endl; | |
std::cout << "Testing: " << testName << std::endl; | |
std::cout << "========================================================================" << std::endl << std::endl; | |
} | |
void ComponentTest :: PrintConclusion() | |
{ | |
std::cout << "========================================================================" << std::endl; | |
std::cout << "Completed Testing: " << testName << std::endl; | |
std::cout << "========================================================================" << std::endl << std::endl; | |
} | |
bool ComponentTest :: TestComponent() | |
{ | |
PrintIntro(); | |
for (UnitTest *test : tests) { | |
++run; | |
test->TestIntro(); | |
test->PerformTest(); | |
test->Passed() ? ++passed : ++failed; | |
test->TestConclusion(); | |
} | |
PrintConclusion(); | |
return GetTestsFailed() == 0; | |
} | |
unsigned long long ComponentTest :: GetTestCount() | |
{ | |
return run; | |
} | |
unsigned long long ComponentTest :: GetTestsFailed() | |
{ | |
return failed; | |
} | |
unsigned long long ComponentTest :: GetTestsPassed() | |
{ | |
return passed; | |
} |