int KMP_Search(char *s, char *p, int pos) { int sLen = strlen(s); int pLen = strlen(p); int i = 0; // i = pos; search from pos. int j = 0; int next[100]; //GetNext(p, next); GetNextVal(p, next); while (i < sLen && j < pLen) { if (j == -1 || s[i] == p[j]) { i++; j++; } else { j = next[j]; } } if (j == pLen) return i - pLen; else return -1; }
TEST(KinematicsTest, TestWithAutomatedData) { std::ifstream file ( "kinematicsdata.csv" ); std::string value; if (!file.good()) { FAIL() << "Could not find test data!"; } while ( file.good() ) { float rotation = GetNextVal( &file ); float vx_i = GetNextVal( &file ); float vy_i = GetNextVal( &file ); float acceleration = GetNextVal( &file ); float time = GetNextVal( &file ); float vx_f = GetNextVal( &file ); float vy_f = GetLastValOfLine( &file ); Vector2 result = Kinematics::CalculateNewVelocity( rotation, Vector2(vx_i, vy_i), acceleration, time ); EXPECT_NEAR( vx_f, result.x, 0.01 ); EXPECT_NEAR( vy_f, result.y, 0.01 ); } }