-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
107 lines (99 loc) · 2.72 KB
/
main.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
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
102
103
104
105
106
107
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmartin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 15:24:31 by jmartin #+# #+# */
/* Updated: 2022/11/08 15:24:32 by jmartin ### ########.fr */
/* */
/* ************************************************************************** */
/*
#include "Array.hpp"
int main(void)
{
{
Array<int> arrayInt(5);
Array<float> arrayFloat(5);
Array<std::string> arrayString(5);
for (int i = 0; i < 5; i++)
{
arrayInt[i] = i;
arrayFloat[i] = i + 0.5;
arrayString[i] = "Hello";
}
for (int i = 0; i < 5; i++)
{
std::cout << "arrayInt[" << i << "] = " << arrayInt[i] << std::endl;
std::cout << "arrayFloat[" << i << "] = " << arrayFloat[i] << std::endl;
std::cout << "arrayString[" << i << "] = " << arrayString[i] << std::endl;
std::cout << std::endl;
}
// Get the size of the array
std::cout << "arrayInt[size] = " << arrayInt.size() << std::endl;
std::cout << "arrayFloat[size] = " << arrayFloat.size() << std::endl;
std::cout << "arrayString[size] = " << arrayString.size() << std::endl;
std::cout << std::endl;
// Error handling for out of range
try {
std::cout << arrayInt[6] << std::endl;
}
catch (std::exception & e) {
std::cout << "arrayInt[6] = " << e.what() << std::endl;
}
}
return (0);
}*/
#include <iostream>
#include "Array.hpp"
#define MAX_VAL 750
int main(int, char**)
{
Array<int> numbers(MAX_VAL);
int* mirror = new int[MAX_VAL];
srand(time(NULL));
for (int i = 0; i < MAX_VAL; i++)
{
const int value = rand();
numbers[i] = value;
mirror[i] = value;
}
//SCOPE
{
Array<int> tmp = numbers;
Array<int> test(tmp);
}
for (int i = 0; i < MAX_VAL; i++)
{
if (mirror[i] != numbers[i])
{
std::cerr << "didn't save the same value!!" << std::endl;
return 1;
}
}
try
{
numbers[-2] = 0;
}
catch(const std::exception& e)
{
std::cerr << "test 1" << '\n';
std::cerr << e.what() << '\n';
}
try
{
numbers[MAX_VAL] = 0;
}
catch(const std::exception& e)
{
std::cerr << "test 2" << '\n';
std::cerr << e.what() << '\n';
}
for (int i = 0; i < MAX_VAL; i++)
{
numbers[i] = rand();
}
delete [] mirror;
return 0;
}