Skip to content

Commit 2ad0131

Browse files
author
Elizabeth Ventura
committed
adding tests for EEPROM
1 parent 74a35e0 commit 2ad0131

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

SampleProjects/TestSomething/test/eeprom.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,55 @@ unittest(length)
1010
assertEqual(EEPROM_SIZE, EEPROM.length());
1111
}
1212

13+
unittest(firstRead)
14+
{
15+
uint8_t a = EEPROM.read(0);
16+
assertEqual(255, a);
17+
}
18+
19+
unittest(writeRead)
20+
{
21+
EEPROM.write(0, 24);
22+
uint8_t a = EEPROM.read(0);
23+
assertEqual(24, a);
24+
25+
EEPROM.write(0, 128);
26+
uint8_t b = EEPROM.read(0);
27+
assertEqual(128, b);
28+
29+
// this will fail since it is out of bound (0 - 255)
30+
EEPROM.write(0, 256);
31+
uint8_t c = EEPROM.read(0);
32+
assertEqual(256, c);
33+
34+
}
35+
36+
unittest(updateWrite)
37+
{
38+
EEPROM.write(1, 14);
39+
EEPROM.update(1, 22);
40+
uint8_t a = EEPROM.read(1);
41+
assertEqual(22, a);
42+
}
43+
44+
unittest(putGet)
45+
{
46+
const float f1 = 0.025f;
47+
float f2 = 0.0f;
48+
EEPROM.put(5, f1);
49+
assertEqual(0.0f, f2);
50+
EEPROM.get(5, f2);
51+
assertEqual(0.025f, f2);
52+
}
53+
54+
unittest(array)
55+
{
56+
int val = 10;
57+
EEPROM[2] = val;
58+
uint8_t a = EEPROM.read(2);
59+
assertEqual(10, a);
60+
}
61+
1362
#endif
1463

1564
unittest_main()

cpp/arduino/Godmode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <avr/io.h>
44
#include "WString.h"
55
#include "PinHistory.h"
6+
#include "EEPROM.h"
67

78
// random
89
void randomSeed(unsigned long seed);
@@ -87,12 +88,19 @@ class GodmodeState {
8788
spi.readDelayMicros = 0;
8889
}
8990

91+
void resetEEPROM() {
92+
for(int i = 0; i < EEPROM.length(); ++i){
93+
EEPROM.update(i, 255);
94+
}
95+
}
96+
9097
void reset() {
9198
resetClock();
9299
resetPins();
93100
resetInterrupts();
94101
resetPorts();
95102
resetSPI();
103+
resetEEPROM();
96104
seed = 1;
97105
}
98106

0 commit comments

Comments
 (0)