cpp/CPP07/ex02/main.cpp
2024-12-04 17:29:31 +01:00

55 lines
974 B
C++

#include <iostream>
#include <time.h>
#include <stdlib.h>
#include "Array.hpp"
int main(void)
{
std::cout << "\n---Test0---\n" << std::endl;
{
Array<int> numbers(750);
int* numbers_copy = new int[750];
srand(time(NULL));
for (int i = 0; i < 750; i++) {
const int value = rand();
numbers[i] = value;
numbers_copy[i] = value;
}
{
Array<int> tmp = numbers;
Array<int> test(tmp);
}
for (int i = 0; i < 750; i++) {
if (numbers_copy[i] != numbers[i]) {
std::cerr << "Not same value" << std::endl;
return 1;
}
}
std::cout << "Same value !" << std::endl;
try {
numbers[-2] = 0;
}
catch(const std::exception& e) {
std::cerr << e.what() << '\n';
}
try {
numbers[750] = 0;
}
catch(const std::exception& e) {
std::cerr << e.what() << '\n';
}
for (int i = 0; i < 750; i++) {
numbers[i] = rand();
}
delete [] numbers_copy;
}
std::cout << "\n---EndTest---\n" << std::endl;
return 0;
}