-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_maximum_and_minimum_main.cpp
More file actions
53 lines (46 loc) · 1.42 KB
/
find_maximum_and_minimum_main.cpp
File metadata and controls
53 lines (46 loc) · 1.42 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
/*
8 kyu
Find Maximum and Minimum Values of a List
https://www.codewars.com/kata/577a98a6ae28071780000989
*/
#include <iostream>
#include <vector>
using VI = std::vector<int>;
int min(const VI& list);
int max(const VI& list);
template <typename T>
static std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
os << "{";
for (size_t i = 0; i < v.size(); ++i) {
os << v[i];
if (i + 1 < v.size())
os << ", ";
}
os << "}";
return os;
}
static void do_test_min(const VI& numbers, const int expected) {
int actual = min(numbers);
std::cout << "Minimum" << std::endl
<< "Array : " << numbers << std::endl
<< "Expected: " << expected << std::endl
<< "Actual : " << actual << std::endl
<< "-> " << (expected == actual ? "OK" : "FAIL") << std::endl
<< std::endl;
}
static void do_test_max(const VI& numbers, const int expected) {
int actual = max(numbers);
std::cout << "Maximum" << std::endl
<< "Array : " << numbers << std::endl
<< "Expected: " << expected << std::endl
<< "Actual : " << actual << std::endl
<< "-> " << (expected == actual ? "OK" : "FAIL") << std::endl
<< std::endl;
}
int main() {
do_test_min({-52, 56, 30, 29, -54, 0, -110}, -110);
do_test_min({42, 54, 65, 87, 0}, 0);
do_test_max({4, 6, 2, 1, 9, 63, -134, 566}, 566);
do_test_max({5}, 5);
return 0;
}