Skip to content

Commit a0e4b85

Browse files
committed
add unit testing example
1 parent 70e92aa commit a0e4b85

File tree

7 files changed

+13024
-0
lines changed

7 files changed

+13024
-0
lines changed

08/average.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<iostream>
2+
#include<cstdlib>
3+
#include<ctime>
4+
#include"vector.h"
5+
using namespace std;
6+
7+
template<class T>
8+
int average(Vector<T>& vect)
9+
{
10+
int sum = 0;
11+
for(unsigned int i = 0; i < vect.length(); i++)
12+
{
13+
sum += vect[i];
14+
}
15+
16+
return sum/vect.length();
17+
}
18+
19+
int main()
20+
{
21+
srand(time(NULL));
22+
Vector<int> rand_nums;
23+
24+
for(unsigned int i = 0; i < 1000; i++)
25+
{
26+
rand_nums.push_back(rand()%1000);
27+
cout << average(rand_nums) << endl;
28+
}
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)