#include "lab6.h"
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
string concat(string s1, string s2)
{
return s1+s2;
}
int smallInt(int x, int y)
{
if (x < y) return x;
else return y;
}
string smallStr(string s1, string s2)
{
if (s1 < s2) return s1;
else return s2;
}
int main()
{
// testing our variadic sumDiffs with different types and numbers of arguments
int res1 = sumDiffs(5, 3, 8, 2, 1, -6);
cout << "(5-3) + (8-2) + (1--6) should be 15, actually got: " << res1 << endl;
double res2 = sumDiffs(1.0, 2.5, 3.6);
cout << "(1-2.5) + 3.6 should be 2.1, actually got: " << res2 << endl;
// testing our higher order apply with different function/parameter combos
double res3 = apply(sqrt, 0.81);
cout << "sqrt(0.81) should give 0.9, actually got: " << res3 << endl;
string str1 = "foo";
string str2 = "blah";
string res4 = apply(concat, str1, str2);
cout << "concat(foo, blah) should give fooblah, actually got: " << res4 << endl;
// testing our variadic higher order function with different functions and numbers of args
string res5 = chosenMin(smallStr, str1, str2);
cout << "smaller of foo and blah should be blah, actually got: " << res5 << endl;
int res6 = chosenMin(smallInt, 10, 5, 17, -3, 11);
cout << "smaller of 10, 5, 17, -3, 11 should be -3, actually got: " << res6 << endl;
}
|