1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
#include <assert.h>
#include "functions.h"
using namespace std;
#define ARRLEN 6
int main(int argc, char *argv[])
{
int x, y;
double a, b;
int iarr[] = {42, 42, 42, 56, 65, 99};
float farr[] = {3.14, 3.14, 3.2, 4.5, 7.8, 0.0};
x = 6;
y = 42;
a = 3.14159;
b = 3.14160;
assert(min(x,y) == x);
assert(min(a,b) == a);
assert(count(iarr, y, ARRLEN) == 3);
assert(count(farr, 3.14f, ARRLEN) == 2);
assert(sum(iarr, ARRLEN) == 346);
assert(sum(farr, ARRLEN) == 21.78f);
// Can't use *swap* because it's part of the STL
myswap(x, y);
assert(x == 42);
assert(y == 6);
myswap(a, b);
assert(a == 3.14160);
assert(b == 3.14159);
cout << "All tests passed!" << endl;
}
|