fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4. #include <cctype>
  5.  
  6. using namespace std;
  7.  
  8. typedef pair<int,int> out_in;
  9.  
  10. template<typename F>
  11. bool check(F&& f, vector<out_in> const& tests)
  12. {
  13. for(auto const& p : tests){
  14. int result;
  15. if((result = f(p.second)) != p.first){
  16. cout << "Test failed! F(" << p.second << ") = " << result << ". Expected: " << p.first << endl;
  17. return false;
  18. }
  19. }
  20. return true;
  21. }
  22.  
  23. int main()
  24. {
  25. vector<out_in> toUpper = {
  26. {'A','a'},
  27. {'A','A'},
  28. {'0','0'},
  29. {'B','A'}
  30. };
  31.  
  32.  
  33. cout << "testing std::toupper()..." << endl;
  34. if(check(&::toupper,toUpper)) cout << "Passed!" << endl;
  35.  
  36. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
testing std::toupper()...
Test failed! F(65) = 65. Expected: 66