Skip to content
Snippets Groups Projects
Commit 6a3327aa authored by Jacob Kegerreis's avatar Jacob Kegerreis
Browse files

Add extra array slice test

parent 0a4406a5
Branches
Tags
1 merge request!547Add generic utility function to find a value in an array
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
*/ */
int main() { int main() {
/// Test find_value_in_monotonic_array() /// Test find_value_in_monotonic_array()
const int n = 100; int n = 100;
float arr[n]; float arr[n];
int i; int i;
float x; float x;
...@@ -35,15 +35,15 @@ int main() { ...@@ -35,15 +35,15 @@ int main() {
arr[j] = j; arr[j] = j;
} }
// Typical example // Typical value
x = 42.42f; x = 42.42f;
find_value_in_monotonic_array(x, arr, n, &i); find_value_in_monotonic_array(x, arr, n, &i);
if (i != 42) { if (i != 42) {
printf("Failed with a normal value \n"); printf("Failed with a typical value \n");
return 1; return 1;
} }
// On array element // Value on array element
x = 33.f; x = 33.f;
find_value_in_monotonic_array(x, arr, n, &i); find_value_in_monotonic_array(x, arr, n, &i);
if (i != 33) { if (i != 33) {
...@@ -51,7 +51,7 @@ int main() { ...@@ -51,7 +51,7 @@ int main() {
return 1; return 1;
} }
// Below array // Value below array
x = -123.f; x = -123.f;
find_value_in_monotonic_array(x, arr, n, &i); find_value_in_monotonic_array(x, arr, n, &i);
if (i != -1) { if (i != -1) {
...@@ -59,7 +59,7 @@ int main() { ...@@ -59,7 +59,7 @@ int main() {
return 1; return 1;
} }
// Above array // Value above array
x = 123.f; x = 123.f;
find_value_in_monotonic_array(x, arr, n, &i); find_value_in_monotonic_array(x, arr, n, &i);
if (i != n) { if (i != n) {
...@@ -67,5 +67,14 @@ int main() { ...@@ -67,5 +67,14 @@ int main() {
return 1; return 1;
} }
// Array slice with typical value
x = 9.81f;
n = 10;
find_value_in_monotonic_array(x, arr + 5, n, &i);
if (i != 4) {
printf("Failed with an array slice \n");
return 1;
}
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment