-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
94 lines (81 loc) · 2.78 KB
/
Copy pathtest.cpp
File metadata and controls
94 lines (81 loc) · 2.78 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "functions_to_implement.cpp"
#include <vector>
TEST_CASE("Factorials are computed", "[factorial]")
{
CHECK(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, 4, 5, 6, 7, 8, 9, 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);
}
}
// Test case for SubtractN function
TEST_CASE("SubtractN function subtracts correctly from vector", "[SubtractN]")
{
std::vector<double> input = {10.5, 20.8, 30.3};
std::vector<double> expected = {5.0, 15.3, 24.8};
REQUIRE(SubtractN(input, 5.5) == expected);
}
// Test case for RemoveAllSubstrings function
TEST_CASE("RemoveAllSubstrings function removes all substrings", "[RemoveAllSubstrings]")
{
SECTION("remove all occurences of substring")
{
std::string text = "one, two, one, three, four";
std::string to_remove = "one";
std::string expected = ", two, , three, four";
REQUIRE(RemoveAllSubstrings(text, to_remove) == expected);
}
SECTION("no occurrences of substring")
{
std::string text = "one, two, three";
std::string to_remove = "four";
std::string expected = "one, two, three";
REQUIRE(RemoveAllSubstrings(text, to_remove) == expected);
}
}
// Test case for RemoveFirstSubString function
TEST_CASE("RemoveFirstSubstring function removes first substring", "[RemoveFirstSubstring]")
{
SECTION("remove first occurrence")
{
std::string text = "one, two, three, four, one";
std::string to_remove = "one";
std::string expected = ", two, three, four, one";
REQUIRE(RemoveFirstSubstring(text, to_remove) == expected);
}
SECTION("no occurrences of substring")
{
std::string text = "one, two, three";
std::string to_remove = "four";
std::string expected = "one, two, three";
REQUIRE(RemoveFirstSubstring(text, to_remove) == expected);
}
}