-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (71 loc) · 1.63 KB
/
Copy pathmain.cpp
File metadata and controls
89 lines (71 loc) · 1.63 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
#include <iostream>
#include <cstdlib>
#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;
}
// Deep copy test
{
Array<int> tmp = numbers;
Array<int> test(tmp);
}
// Basic functionality test
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;
}
}
// Exception tests
try
{
numbers[-2] = 0;
}
catch(const std::exception& e)
{
std::cerr << "Failed to access numbers[-2]: " << e.what() << '\n';
}
try
{
numbers[MAX_VAL] = 0;
}
catch(const std::exception& e)
{
std::cerr << "Failed to access numbers[MAX_VAL]: " << e.what() << '\n';
}
// Indexing test
for (int i = 0; i < MAX_VAL; i++)
{
numbers[i] = rand();
}
// Empty array test
Array<float> empty;
try
{
empty[0] = 42;
}
catch(const std::exception& e)
{
std::cerr << "Failed to access empty[0]: " << e.what() << '\n';
}
// Reading/writing test
std::cout << "numbers[0]: " << numbers[0] << std::endl;
numbers[0] = 42;
std::cout << "numbers[0]: " << numbers[0] << std::endl;
delete [] mirror;//
// const test
const Array<int> const_check(numbers);
std::cout << const_check[1] << std::endl;
return 0;
}