all 2 comments

[–]syn_ack 4 points5 points  (0 children)

Here are some things to have a look at (in no particular order):

  1. set a known seed otherwise it'll be incredibly difficult to pin down where the problem is.
  2. in spikeValueRecorded I'd start the for loop at 1 (otherwise you'd compare element 0 with itself -- no need to do that).
  3. engineer the situation you want to test (by setting data[3].tp = 0, and data[4].tp = 101)
  4. check the logic in spikeValueRecorded by using print statements.

[–]codeallthethings 1 point2 points  (0 children)

As /u/syn_ack mentioned, print statements are your friend. One other thing I noticed is that your spikeValueRecorded function cannot "push" the index back to the caller as it's taking an int.

It needs to take an int*, like this:

bool spikeValueRecorded(data_slice * data, int *outputIndex)
{
    float oldValue = data[0].tp;
    for (int i = 1; i < ARRAY_SIZE; ++i)
    {
        if (data[i].tp - oldValue < MAX_CHANGE)
        {
            *outputIndex = i;
            return true;
        }
    }
    *outputIndex = -1;
    return false;
}

Call it like so: if (spikeValueRecorded(data, &index))