-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
101 lines (96 loc) · 2.37 KB
/
main.cpp
File metadata and controls
101 lines (96 loc) · 2.37 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
95
96
97
98
99
100
101
#include <cstdlib>
#include <ctime>
#include "Defines.hpp"
#include "Span.hpp"
int
main ()
{
print (TITTLE YELLOW_BOLD "CPP Module 08 - ex01" RESET);
{
print (SUB_TITTLE GREEN
"Exception when try to fill out of bounds - addNumber()\n" RESET);
Span sp = Span (5);
try
{
sp.addNumber (1);
sp.addNumber (2);
sp.addNumber (3);
sp.addNumber (4);
sp.addNumber (5);
sp.addNumber (6);
}
catch (std::exception &e)
{
print (e.what ());
}
}
{
print (SUB_TITTLE GREEN
"Exception when try to fill out of bounds - populate()\n" RESET);
Span sp = Span (5);
std::vector<int> v (6, 42);
try
{
sp.populate (v.begin (), v.end ());
}
catch (std::exception &e)
{
print (e.what ());
}
}
{
print (SUB_TITTLE GREEN "populate() with a valid range\n" RESET);
Span sp = Span (10);
std::vector<int> v (10, -42);
sp.populate (v.begin (), v.end ());
sp.operator<< (std::cout);
}
{
print (SUB_TITTLE GREEN "Exception when try to calculate shortestSpan() "
"with less than 2 numbers\n" RESET);
Span sp = Span (5);
try
{
sp.shortestSpan ();
}
catch (std::exception &e)
{
print (e.what ());
}
}
{
print (SUB_TITTLE GREEN "Exception when try to calculate longestSpan() "
"with less than 2 numbers\n" RESET);
Span sp = Span (5);
try
{
sp.longestSpan ();
}
catch (std::exception &e)
{
print (e.what ());
}
}
std::srand (std::time (0));
{
print (
SUB_TITTLE GREEN
"shortestSpan() and longestSpan() with a few random numbers\n" RESET);
Span sp (15);
for (int i = 0; i < 15; i++)
sp.addNumber (std::rand () % 200);
print (YELLOW "shortestSpan(): " RESET << sp.shortestSpan ());
print (YELLOW "longestSpan(): " RESET << sp.longestSpan ());
sp.operator<< (std::cout);
}
{
print (
SUB_TITTLE GREEN
"shortestSpan() and longestSpan() with 20000 random numbers\n" RESET);
Span sp (20000);
for (int i = 0; i < 20000; i++)
sp.addNumber (std::rand ());
print (YELLOW "shortestSpan(): " RESET << sp.shortestSpan ());
print (YELLOW "longestSpan(): " RESET << sp.longestSpan ());
}
}