Originally Posted by
laserlight
That said, I think your interpretation of the third column is (deliberately?) wrong, but it is still spoonfeeding.
Code:
#include "greatest.h"
char* third_column(char* str)
{
char* ret = NULL;
int space = 0;
while( *str ) {
space += *str == ' ';
switch( space ) {
case 2:
if( *str == ',' ) { *str = '.'; }
if( !ret ) { ret = str; }
break;
case 3:
*str = '\0';
return ret;
break;
}
++str;
}
return ret;
}
TEST third_column_1()
{
ASSERT_EQ(atof(third_column("02/01/2007 01.10.00 -2,0 G")), -2.0);
PASS();
}
TEST third_column_2()
{
ASSERT_EQ(atof(third_column("02/01/2007 01.20.00 -2,0 G")), -2.0);
PASS();
}
TEST third_column_3()
{
ASSERT_EQ(atof(third_column("02/01/2007 01.30.00 -2,1 G")), -2.1);
PASS();
}
TEST third_column_4()
{
ASSERT_EQ(atof(third_column("02/01/2007 01.40.00 -2,0 G")), -2.0);
PASS();
}
TEST third_column_5()
{
ASSERT_EQ(atof(third_column("02/01/2007 01.50.00 -2,3 G")), -2.3);
PASS();
}
TEST third_column_6()
{
ASSERT_EQ(atof(third_column("02/01/2007 02.00.00 -2,4 G")), -2.4);
PASS();
}
TEST third_column_7()
{
ASSERT_EQ(atof(third_column("02/01/2007 02.10.00 -2,1 G")), -2.1);
PASS();
}
TEST third_column_8()
{
ASSERT_EQ(atof(third_column("02/01/2007 02.20.00 -1,9 G")), -1.9);
PASS();
}
TEST third_column_9()
{
ASSERT_EQ(atof(third_column("02/01/2007 02.30.00 -2,1 G")), -2.1);
PASS();
}
TEST third_column_10()
{
ASSERT_EQ(atof(third_column("02/01/2007 02.40.00 -2,2 G")), -2.2);
PASS();
}
TEST third_column_11()
{
ASSERT_EQ(atof(third_column("02/01/2007 02.50.00 -2,1 G")), -2.1);
PASS();
}
TEST third_column_12()
{
ASSERT_EQ(atof(third_column("02/01/2007 03.00.00 -2,1 G")), -2.1);
PASS();
}
SUITE(test_third_column)
{
RUN_TEST(third_column_1);
RUN_TEST(third_column_2);
RUN_TEST(third_column_3);
RUN_TEST(third_column_4);
RUN_TEST(third_column_5);
RUN_TEST(third_column_6);
RUN_TEST(third_column_7);
RUN_TEST(third_column_8);
RUN_TEST(third_column_9);
RUN_TEST(third_column_10);
RUN_TEST(third_column_11);
RUN_TEST(third_column_12);
}
GREATEST_MAIN_DEFS();
int main(int argc, char **argv) {
GREATEST_MAIN_BEGIN(); /* command-line arguments, initialization. */
RUN_SUITE(test_third_column);
GREATEST_MAIN_END(); /* display results */
}
C:\UTIL\tcc>tcc.exe -run -Wall run.c
* Suite test_third_column:
............
12 tests - 12 pass, 0 fail, 0 skipped (4 ticks, 0.004 sec)
Total: 12 tests (9 ticks, 0.009 sec)
Pass: 12, fail: 0, skip: 0.