-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
82 lines (73 loc) · 2.45 KB
/
main.cpp
File metadata and controls
82 lines (73 loc) · 2.45 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zelhajou <zelhajou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/19 00:21:29 by zelhajou #+# #+# */
/* Updated: 2025/02/25 16:01:22 by zelhajou ### ########.fr */
/* */
/* ************************************************************************** */
#include "Span.hpp"
#include <iostream>
#include <ctime>
int main()
{
// Test 1
{
Span sp = Span(5);
sp.addNumber(6);
sp.addNumber(3);
sp.addNumber(17);
sp.addNumber(9);
sp.addNumber(11);
std::cout << "Test 1" << std::endl;
std::cout << "Shortest span: " << sp.shortestSpan() << std::endl;
std::cout << "Longest span: " << sp.longestSpan() << std::endl;
}
// Test 2
{
Span bigSp = Span(10000);
std::vector<int> numbers;
std::srand(std::time(0));
for (int i = 0; i < 10000; i++)
numbers.push_back(std::rand());
try
{
bigSp.addNumber(numbers.begin(), numbers.end());
std::cout << "Test 2" << std::endl;
std::cout << "Shortest span: " << bigSp.shortestSpan() << std::endl;
std::cout << "Longest span: " << bigSp.longestSpan() << std::endl;
}
catch (const std::exception &e)
{
std::cout << e.what() << std::endl;
}
}
// Test 3
{
Span empty = Span(5);
try
{
empty.shortestSpan();
}
catch (const std::exception &e)
{
std::cout << "Test 3" << std::endl;
std::cout << e.what() << std::endl;
}
Span full(2);
try
{
full.addNumber(1);
full.addNumber(2);
full.addNumber(3);
}
catch (const std::exception &e)
{
std::cout << e.what() << std::endl;
}
}
return 0;
}