summaryrefslogtreecommitdiff
path: root/src/auxiliaryFunctions/find/testFind.c
blob: f191b368bbd87b8465a6897258f07b626c94e586 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 *  Copyright (C) 2007-2008 - INRIA - Bruno JOFRET
 *
 *  This file must be used under the terms of the CeCILL.
 *  This source file is licensed as described in the file COPYING, which
 *  you should have received as part of this distribution.  The terms
 *  are also available at
 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 *
 */

#include "testFind.h"

int sfindaTest() {
  int result = 0;
  float goodArray[5] = {0.,2.,3.,5.,10.};
  float badArray[5] = {0.,0.,0.,0.,0.};

  printf(">> Floats \n");
  if (sfinda(goodArray, 5) == NOT_FOUND) {
    printf("ERROR ! : Test Failed (non empty array)\n");
    result = ERROR;
  }
  assert(sfinda(goodArray, 5) != NOT_FOUND);
  assert(sfinda(goodArray, 5) == 1);
  if (sfinda(badArray, 5) != NOT_FOUND) {
    printf("ERROR ! : Test Failed (empty array)\n");
    result = ERROR;
  }
  assert(sfinda(badArray, 5) == NOT_FOUND);
  return result;
}

int dfindaTest() {
  double goodArray[5] = {0.,2.,3.,5.,10.};
  double badArray[5] = {0.,0.,0.,0.,0.};

  printf(">> Doubles \n");
  assert(dfinda(goodArray, 5) != NOT_FOUND);
  assert(dfinda(goodArray, 5) == 1);
  if (dfinda(goodArray, 5) == NOT_FOUND) {
    printf("ERROR ! : Test Failed (non empty array)\n");
    return ERROR;
  }
  assert(dfinda(badArray, 5) == NOT_FOUND);
  if (dfinda(badArray, 5) != NOT_FOUND) {
    printf("ERROR ! : Test Failed (empty array)\n");
    return ERROR;
  }
  return 0;
}

int cfindaTest() {
  int result = 0;
  floatComplex goodArray[5];
  floatComplex badArray[5];
  /* Good values in goodArray */
  goodArray[0] = FloatComplex(0., 0.);
  goodArray[1] = FloatComplex(0., 2.);
  goodArray[2] = FloatComplex(3., 50.);
  goodArray[3] = FloatComplex(5., 10.);
  goodArray[4] = FloatComplex(10., -10.);
  /* Bad values in badArray */
  badArray[0] = FloatComplex(0., 0.);
  badArray[1] = FloatComplex(0., 0.);
  badArray[2] = FloatComplex(0., 0.);
  badArray[3] = FloatComplex(0., 0.);
  badArray[4] = FloatComplex(0., 0.);

  printf(">> Float Complex \n");
  if (cfinda(goodArray, 5) == NOT_FOUND) {
    printf("ERROR ! : Test Failed (non empty array)\n");
    result = ERROR;
  }
  assert(cfinda(goodArray, 5) != NOT_FOUND);
  assert(cfinda(goodArray, 5) == 1);
  if (cfinda(badArray, 5) != NOT_FOUND) {
    printf("ERROR ! : Test Failed (empty array)\n");
    result = ERROR;
  }
  assert(cfinda(badArray, 5) == NOT_FOUND);
  return result;
}

int zfindaTest() {
  int result = 0;
  doubleComplex goodArray[5];
  doubleComplex badArray[5];
  /* Good values in goodArray. */
  goodArray[0] = DoubleComplex(0., 0.);
  goodArray[1] = DoubleComplex(0., 2.);
  goodArray[2] = DoubleComplex(3., 50.);
  goodArray[3] = DoubleComplex(5., 10.);
  goodArray[4] = DoubleComplex(10., -10.);
  /* Bad values in badArray */
  badArray[0] = DoubleComplex(0., 0.);
  badArray[1] = DoubleComplex(0., 0.);
  badArray[2] = DoubleComplex(0., 0.);
  badArray[3] = DoubleComplex(0., 0.);
  badArray[4] = DoubleComplex(0., 0.);

  printf(">> Double Complex \n");
  if (zfinda(goodArray, 5) == NOT_FOUND) {
    printf("ERROR ! : Test Failed (non empty array)\n");
    result = ERROR;
  }
  assert(zfinda(goodArray, 5) != NOT_FOUND);
  if (zfinda(goodArray, 5) != 1) {
    printf("ERROR ! : Test Failed (Element found in place %d instead of 1)\n", zfinda(goodArray, 5));
    result = ERROR;
  }
  assert(zfinda(goodArray, 5) == 1);
  if (zfinda(badArray, 5) != NOT_FOUND) {
    printf("ERROR ! : Test Failed (empty array)\n");
    result = ERROR;
  }
  assert(zfinda(badArray, 5) == NOT_FOUND);
  return result;
}

int testFind() {
  int sfindaStatus, dfindaStatus = 0;
  int cfindaStatus, zfindaStatus = 0;

  printf(">>>> Find Tests\n");
  sfindaStatus = sfindaTest();
  dfindaStatus = dfindaTest();
  cfindaStatus = cfindaTest();
  zfindaStatus = zfindaTest();

  return (sfindaStatus + dfindaStatus +
	  cfindaStatus + zfindaStatus);
}

int main(void) {
  assert(testFind() == 0);
  return 0;
}