mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
variable-length arrays fixed
This commit is contained in:
parent
8e53f4da83
commit
4b3749ed49
@ -67,7 +67,7 @@ bool one_occurence_test(){
|
|||||||
bool passed = true;
|
bool passed = true;
|
||||||
// last element
|
// last element
|
||||||
length = 3;
|
length = 3;
|
||||||
int arr1[length] = {1, 2, 3};
|
int arr1[3] = {1, 2, 3};
|
||||||
value = 3;
|
value = 3;
|
||||||
index = fibonacci_search(arr1, value, length);
|
index = fibonacci_search(arr1, value, length);
|
||||||
passed = passed && (index == 2);
|
passed = passed && (index == 2);
|
||||||
@ -77,13 +77,13 @@ bool one_occurence_test(){
|
|||||||
passed = passed && (index == 0);
|
passed = passed && (index == 0);
|
||||||
// somewhere in the middle element
|
// somewhere in the middle element
|
||||||
length = 4;
|
length = 4;
|
||||||
int arr2[length] = {1, 3, 5, 7};
|
int arr2[4] = {1, 3, 5, 7};
|
||||||
value = 3;
|
value = 3;
|
||||||
index = fibonacci_search(arr2, value, length);
|
index = fibonacci_search(arr2, value, length);
|
||||||
passed = passed && (index == 1);
|
passed = passed && (index == 1);
|
||||||
// arr size is 1
|
// arr size is 1
|
||||||
length = 1;
|
length = 1;
|
||||||
int arr3[length] = {10};
|
int arr3[1] = {10};
|
||||||
value = 10;
|
value = 10;
|
||||||
index = fibonacci_search(arr3, value, length);
|
index = fibonacci_search(arr3, value, length);
|
||||||
passed = passed && (index == 0);
|
passed = passed && (index == 0);
|
||||||
@ -100,7 +100,7 @@ bool many_occurence_test(){
|
|||||||
bool passed = true;
|
bool passed = true;
|
||||||
// last element
|
// last element
|
||||||
length = 4;
|
length = 4;
|
||||||
int arr1[length] = {1, 1, 10, 10};
|
int arr1[4] = {1, 1, 10, 10};
|
||||||
value = 10;
|
value = 10;
|
||||||
index = fibonacci_search(arr1, value, length);
|
index = fibonacci_search(arr1, value, length);
|
||||||
passed = passed && (index == 2 || index == 3);
|
passed = passed && (index == 2 || index == 3);
|
||||||
@ -110,13 +110,13 @@ bool many_occurence_test(){
|
|||||||
passed = passed && (index == 0 || index == 1);
|
passed = passed && (index == 0 || index == 1);
|
||||||
// somewhere in the middle element
|
// somewhere in the middle element
|
||||||
length = 4;
|
length = 4;
|
||||||
int arr2[length] = {1, 3, 3, 7};
|
int arr2[4] = {1, 3, 3, 7};
|
||||||
value = 3;
|
value = 3;
|
||||||
index = fibonacci_search(arr2, value, length);
|
index = fibonacci_search(arr2, value, length);
|
||||||
passed = passed && (index == 1 || index == 2);
|
passed = passed && (index == 1 || index == 2);
|
||||||
// all elements are the same
|
// all elements are the same
|
||||||
length = 3;
|
length = 3;
|
||||||
int arr3[length] = {10, 10, 10};
|
int arr3[3] = {10, 10, 10};
|
||||||
value = 10;
|
value = 10;
|
||||||
index = fibonacci_search(arr3, value, length);
|
index = fibonacci_search(arr3, value, length);
|
||||||
passed = passed && (index >= 0 && index <= 2);
|
passed = passed && (index >= 0 && index <= 2);
|
||||||
@ -133,19 +133,19 @@ bool no_occurence_test(){
|
|||||||
bool passed = true;
|
bool passed = true;
|
||||||
// many elements
|
// many elements
|
||||||
length = 4;
|
length = 4;
|
||||||
int arr1[length] = {1, 2, 4, 5};
|
int arr1[4] = {1, 2, 4, 5};
|
||||||
value = 3;
|
value = 3;
|
||||||
index = fibonacci_search(arr1, value, length);
|
index = fibonacci_search(arr1, value, length);
|
||||||
passed = passed && (index == -1);
|
passed = passed && (index == -1);
|
||||||
// one element
|
// one element
|
||||||
length = 1;
|
length = 1;
|
||||||
int arr2[length] = {1};
|
int arr2[1] = {1};
|
||||||
value = 2;
|
value = 2;
|
||||||
index = fibonacci_search(arr2, value, length);
|
index = fibonacci_search(arr2, value, length);
|
||||||
passed = passed && (index == -1);
|
passed = passed && (index == -1);
|
||||||
// empty array
|
// empty array
|
||||||
length = 0;
|
length = 0;
|
||||||
int arr3[length];
|
int arr3[10] = {};
|
||||||
value = 10;
|
value = 10;
|
||||||
index = fibonacci_search(arr3, value, length);
|
index = fibonacci_search(arr3, value, length);
|
||||||
passed = passed && (index == -1);
|
passed = passed && (index == -1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user