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?
4003CEM-templates_orig/lab_template_iterators.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
51 lines (43 sloc)
1.43 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 <iostream> | |
#include <algorithm> | |
#include <string> | |
#include <vector> | |
#include <limits> | |
#include <list> | |
#include <array> | |
#include <iterator> | |
using namespace std; | |
#include "lab_template_iterators.h" | |
int main() | |
{ | |
int errors = 0; | |
vector<int> intItems { 1, 2, 3, 4, 5 }; | |
array<float,6> floatItems { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 }; | |
list<unsigned int> uintItems { 858993455, 858993456, 858993457, 858993458, 858993459 }; | |
int intAnswer = how_long( intItems.begin(), intItems.end() ); | |
int intExpected = 5; | |
if( intAnswer != intExpected ) | |
{ | |
cerr << "how_long() did not work correctly when tested with ints or vectors" << endl | |
<< " Expected " << "" << " but recieved " << intAnswer << " instead" << endl; | |
errors += 1; | |
} | |
int floatAnswer = how_long( floatItems.begin(), floatItems.end() ); | |
int floatExpected = 6; | |
if( floatAnswer != floatExpected ) | |
{ | |
cerr << "how_long() did not work correctly when tested with floats or arrays" << endl | |
<< " Expected " << "" << " but recieved " << floatAnswer << " instead" << endl; | |
errors += 1; | |
} | |
int uintAnswer = how_long( uintItems.begin(), prev(uintItems.end()) ); | |
int uintExpected = 4; | |
if( uintAnswer != uintExpected ) | |
{ | |
cerr << "how_long() did not work correctly when tested with uints or lists" << endl | |
<< " Expected " << uintExpected << " but recieved " << uintAnswer << " instead" << endl; | |
errors += 1; | |
} | |
cout << "There were " << errors << " errors." << endl; | |
return errors; | |
} |