forked from CSCI-3010-CUBoulder/lec6-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
38 lines (34 loc) · 1.03 KB
/
test.cpp
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
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include "functions_to_implement.cpp"
#include <vector>
TEST_CASE ( "Factorials are computed", "[factorial]") {
REQUIRE( Factorial(0) == 1 );
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}
TEST_CASE("incrementing values in integer vector", "[addN]"){
std::vector<int> v{1,2,3,5,6,7,8,10};
SECTION("checking with +ve n"){
int n=5;
std::vector<int> res = AddN(v, n);
srand(time(NULL));
int random = rand()%v.size();
REQUIRE(v.size() == res.size());
REQUIRE( res[0] == 6 );
REQUIRE( res[v.size()-1] == 15 );
REQUIRE(res[random] == v[random]+n);
}
SECTION("checking with -ve n"){
int n=-5;
std::vector<int> res = AddN(v, n);
srand(time(NULL));
int random = rand()%v.size();
REQUIRE(v.size() == res.size());
REQUIRE( res[0] == -4 );
REQUIRE( res[v.size()-1] == 5 );
REQUIRE(res[random] == v[random]+n);
}
}