I am building a set of Visual Studio 2015 based Unit Tests, based on Microsoft's native framework. I am using the code show below, which compiles and runs without issue. However, when I run the test, it throws an error (full message below). Before drawGraph
, a routine is called which initialises history as equal too float Data[15][5]
, which is then fully populated with 15, arrays of 5. What am I doing wrong?
vector< vector<float> > history;
float drawGraph(float graph[4][10]) {
float m, c, j, x1, x2;
int i = 0;
while (i < history.size() - 1) {
j = i + 1;
x1 = history[i][0];
x2 = history[j][0];
m = history[j][3] / history[j][2];
c = history[i][1] - m*x2;
i++;
graph[0][i] = { x1 };
graph[1][i] = { x2 };
graph[2][i] = { m };
graph[3][i] = { c };
}
return graph[0][0];
};
Here is my Test Code:
TEST_METHOD(Graph_Equations_Correct) {
float graph[4][10];
int i = 1;
while (i < 10) {
drawGraph(graph);
Assert::AreEqual(history[i][4], graph[2][i]);
i++;
}
}
This is the result / error it throws:
Result StackTrace: at std::vector >::operator in c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector:line 1233 at UnitTest1::MyTests::Graph_Equations_Correct() in c:\users\george\documents\history testing 2\unittest1\unittest1.cpp:line 32 Result Message: Invalid parameter detected in function std::vector >::operator [], c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector line 1233. Expression: "out of range"
EDIT:
The first test I call is:
TEST_METHOD(Array_Populates)
{
int i = 0;
while (i < 10) {
populateArray(dummyData[i][0], dummyData[i][1]);
//Assert::AreEqual(history[i][0], dummyData[i][1]);
i++;
}
int j = 0;
while (j < history.size()) {
Assert::AreEqual(dummyData[j][0], history.at(j)[1]);
j++;
}
}
Where The Routine in my code is:
void populateArray(int input, int time) {
values.push_back(time);
values.push_back(input);
if (history.size() > 0) {
values.push_back(values[0] - history.back()[0]);
values.push_back(values[1] - history.back()[1]);
values.push_back(values[3] / values[2]);
}
history.push_back(values);
values.clear();
};