From 190177bb6792fa3d4f54b1edfd198ee101543bdf Mon Sep 17 00:00:00 2001 From: Dmitriy Lyubimov Date: Sun, 9 Jul 2017 23:27:11 -0700 Subject: [PATCH] Unit test and small fix. --- Hydra_EVSE/Hydra_EVSE.h | 2 +- Hydra_EVSE/onlineSum.h | 3 +++ Hydra_EVSE/units.cpp | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Hydra_EVSE/Hydra_EVSE.h b/Hydra_EVSE/Hydra_EVSE.h index 89e4b7f..5789e0a 100644 --- a/Hydra_EVSE/Hydra_EVSE.h +++ b/Hydra_EVSE/Hydra_EVSE.h @@ -39,7 +39,7 @@ #define SW_VERSION "2.4.1-dev" // Define this for the basic unit tests run in a generica arduino uno board with a display shield. -// #define UNIT_TESTS + #define UNIT_TESTS #define UINT_BITS (sizeof(unsigned int) << 3) #define ULONG_BITS (sizeof(unsigned long) << 3) diff --git a/Hydra_EVSE/onlineSum.h b/Hydra_EVSE/onlineSum.h index b3db849..dc4d806 100644 --- a/Hydra_EVSE/onlineSum.h +++ b/Hydra_EVSE/onlineSum.h @@ -121,6 +121,9 @@ class RTCModel { void reset(); + // For testing only + double getRate() { return rate; } + }; diff --git a/Hydra_EVSE/units.cpp b/Hydra_EVSE/units.cpp index 54635c7..0da7a6a 100644 --- a/Hydra_EVSE/units.cpp +++ b/Hydra_EVSE/units.cpp @@ -180,6 +180,37 @@ static void testEWASumSetup() { ok("ewa-sum"); } +static void testRTCModelSetup() { + double calRate = .175; + int offPerDay = 4; + int adjustError = 3 * 60; + char calib = 0; + + time_t t = now(); + RTCModel calibrator (0.5); + calib = calibrator.update(t, t); + + for (int i = 0; i < 10; i++) { + double dailyOff = offPerDay + calib*calRate; + double skipDays = abs(adjustError /dailyOff); + if (isinf(skipDays)) { + logInfo(P("Inf done")); + break; + } + double adjErr = skipDays * dailyOff + random(60) - 30; + Serial.print((int)calib); + Serial.print('/'); + Serial.print(skipDays); + Serial.print('/'); + Serial.println(calibrator.getRate()); + + t+= skipDays * SECS_PER_DAY; + calib = calibrator.update(t,-adjErr); + } + ok("RTCModel"); + +} + @@ -187,7 +218,8 @@ int unitsSetup() { testEepromSetup(); testDstSetup(); - testEWASumSetup(); +// testEWASumSetup(); + testRTCModelSetup(); testDisplayStatus(); testMenuSetup(); return false;