Skip to content

Commit

Permalink
Unit test and small fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlyubimov committed Jul 10, 2017
1 parent 9efc7d7 commit 190177b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Hydra_EVSE/Hydra_EVSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions Hydra_EVSE/onlineSum.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class RTCModel {

void reset();

// For testing only
double getRate() { return rate; }



};
Expand Down
34 changes: 33 additions & 1 deletion Hydra_EVSE/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,46 @@ 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");

}




int unitsSetup() {

testEepromSetup();
testDstSetup();
testEWASumSetup();
// testEWASumSetup();
testRTCModelSetup();
testDisplayStatus();
testMenuSetup();
return false;
Expand Down

0 comments on commit 190177b

Please sign in to comment.