unit test for atoff()

This commit is contained in:
rusEfi 2018-11-25 22:20:57 -05:00
parent 1fb9f8d022
commit b8e7bac586
3 changed files with 12 additions and 4 deletions

View File

@ -209,7 +209,7 @@ int efiPow10(int param) {
} }
/** /**
* string to float. NaN input is not supported * string to float. NaN input is supported
* *
* @return NAN in case of invalid string * @return NAN in case of invalid string
* todo: explicit value for error code? probably not, NaN is only returned in case of an error * todo: explicit value for error code? probably not, NaN is only returned in case of an error
@ -220,9 +220,13 @@ float atoff(const char *param) {
return (float) NAN; return (float) NAN;
strcpy(todofixthismesswithcopy, param); strcpy(todofixthismesswithcopy, param);
char *string = todofixthismesswithcopy; char *string = todofixthismesswithcopy;
if (indexOf(string, 'n') != -1 || indexOf(string, 'N') != -1) {
printf("NAN from [%s]\r\n", string);
return (float) NAN;
}
// todo: is there a standard function? // todo: is there a standard function?
// todo: create a unit test // unit-tested by 'testMisc()'
int dotIndex = indexOf(string, '.'); int dotIndex = indexOf(string, '.');
if (dotIndex == -1) { if (dotIndex == -1) {
// just an integer // just an integer

View File

@ -61,6 +61,7 @@ extern bool printTriggerDebug;
int main(void) { int main(void) {
// printTriggerDebug = true; // printTriggerDebug = true;
testMisc();
testDifferentInjectionModes(); testDifferentInjectionModes();
testPidAutoZigZag(); testPidAutoZigZag();
testMissedSpark299(); testMissedSpark299();
@ -76,7 +77,6 @@ int main(void) {
testFasterEngineSpinningUp(); testFasterEngineSpinningUp();
testInterpolate2d(); testInterpolate2d();
testGpsParser(); testGpsParser();
testMisc();
testFuelMap(); testFuelMap();
testFuelCut(); testFuelCut();
testEngineMath(); testEngineMath();
@ -114,7 +114,7 @@ int main(void) {
testTriggerDecoder(); testTriggerDecoder();
// resizeMap(); // resizeMap();
printf("Success 20180120\r\n"); printf("Success 20181120\r\n");
printAllTriggers(); printAllTriggers();
// printConvertedTable(); // printConvertedTable();
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -407,6 +407,10 @@ void testMisc(void) {
assertTrue(strEqual("ab", efiTrim(buff))); assertTrue(strEqual("ab", efiTrim(buff)));
{
float v = atoff("1.0");
assertEqualsM("atoff", 1.0, v);
}
{ {
float v = atoff("nan"); float v = atoff("nan");
assertTrueM("NaN atoff", cisnan(v)); assertTrueM("NaN atoff", cisnan(v));