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
* 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;
strcpy(todofixthismesswithcopy, param);
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: create a unit test
// unit-tested by 'testMisc()'
int dotIndex = indexOf(string, '.');
if (dotIndex == -1) {
// just an integer

View File

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

View File

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