Created
January 31, 2015 18:57
-
-
Save mrwonko/5428d5a73accfca47129 to your computer and use it in GitHub Desktop.
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 your class here | |
#include <iostream> | |
#include <sstream> | |
#include <string> | |
void unless( const bool condition, const std::string& error ) | |
{ | |
if( !condition ) | |
{ | |
std::cerr << error << std::endl; | |
} | |
} | |
template< typename T > | |
const bool operator==( const List< T >& lhs, const std::string& rhs ) | |
{ | |
std::stringstream ss; | |
lhs.display( ss ); // or ss << lhs; if that's implemented | |
return ss.str() == rhs; | |
} | |
int main( int argc, char** argv ) | |
{ | |
List< int > l; | |
unless( l.isEmpty(), "List must be initially empty!" ); | |
unless( l == "", "Empty list must print as nothing!" ); | |
unless( l.getSize() == 0, "Size of empty list must be 0!" ); | |
unless( l.remove( 0 ), "Must not be able to remove from empty list!" ); | |
unless( !l.insert( 42, 1 ), "Must not be able to insert at position 1 in empty list!" ); | |
unless( l.isEmpty(), "Must still be empty after invalid insertion!" ); | |
unless( l.insert( 42, 0 ), "Must be able to insert at position 0 in empty list!" ); | |
unless( !l.isEmpty(), "Must not be empty after valid insertion!" ); | |
unless( l.getSize() == 1, "Size must be 1 after single valid insertion!" ); | |
unless( l == "42 ", "List must contain only 42 after inserting that into empty list!" ); // The trailing space here is due to your implementation - decide whether it's desired. | |
// check more invalid insertions | |
// check more valid and invalid removals | |
// especially of interest in both cases are first and last elements | |
// check Josephus Algorithm | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment