d07 ex02 ok avec test main de l'enoncé

This commit is contained in:
hugogogo
2022-03-12 11:44:03 +01:00
parent 9197577889
commit 329e38b84b
3 changed files with 37 additions and 77 deletions

View File

@@ -146,36 +146,49 @@ int main() {
#define MAX_VAL 750
Array<int> numbers(MAX_VAL);
int* mirror = new int[MAX_VAL];
for (int i = 0; i < MAX_VAL; i++) {
const int value = rand();
numbers[i] = value;
mirror[i] = value;
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);
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!!" << '\n';
return 1;
}
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 << e.what() << '\n';}
try {
numbers[MAX_VAL] = 0;}
catch(const std::exception& e) {
std::cerr << e.what() << '\n';}
for (int i = 0; i < MAX_VAL; i++) {
numbers[i] = rand();
try
{
numbers[-2] = 0;
}
delete [] mirror;
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
}
try
{
numbers[MAX_VAL] = 0;
}
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
}
for (int i = 0; i < MAX_VAL; i++)
{
numbers[i] = rand();
}
delete [] mirror;//
}
return 0;