mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/calculation] Add test for rinn buffer of calculation store
Change-Id: I99b9c75b7bc4927b693a67bb5c022d991eb8dec6
This commit is contained in:
@@ -11,5 +11,10 @@ app_objs += $(addprefix apps/calculation/,\
|
||||
text_field.o\
|
||||
)
|
||||
|
||||
tests += $(addprefix apps/calculation/test/,\
|
||||
calculation_store.cpp\
|
||||
)
|
||||
test_objs += $(addprefix apps/calculation/, calculation.o calculation_store.o)
|
||||
|
||||
app_images += apps/calculation/calculation_icon.png
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ using namespace Poincare;
|
||||
namespace Calculation {
|
||||
|
||||
Calculation::Calculation() :
|
||||
m_inputText(""),
|
||||
m_outputText(""),
|
||||
m_input(nullptr),
|
||||
m_inputLayout(nullptr),
|
||||
m_output(nullptr),
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
namespace Calculation {
|
||||
|
||||
// TODO: make tests for the ring buffer
|
||||
|
||||
class CalculationStore {
|
||||
public:
|
||||
CalculationStore();
|
||||
@@ -16,8 +14,8 @@ public:
|
||||
void deleteAll();
|
||||
int numberOfCalculations();
|
||||
void tidy();
|
||||
private:
|
||||
static constexpr int k_maxNumberOfCalculations = 10;
|
||||
private:
|
||||
int m_startIndex;
|
||||
Calculation m_calculations[k_maxNumberOfCalculations];
|
||||
};
|
||||
|
||||
BIN
apps/calculation/test/.calculation_store.cpp.swp
Normal file
BIN
apps/calculation/test/.calculation_store.cpp.swp
Normal file
Binary file not shown.
45
apps/calculation/test/calculation_store.cpp
Normal file
45
apps/calculation/test/calculation_store.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <quiz.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "../calculation_store.h"
|
||||
|
||||
using namespace Poincare;
|
||||
using namespace Calculation;
|
||||
|
||||
QUIZ_CASE(calculation_store) {
|
||||
GlobalContext globalContext;
|
||||
CalculationStore store;
|
||||
assert(CalculationStore::k_maxNumberOfCalculations == 10);
|
||||
for (int i = 0; i < CalculationStore::k_maxNumberOfCalculations; i++) {
|
||||
char text[2] = {(char)(i+'0'), 0};
|
||||
store.push(text, &globalContext);
|
||||
assert(store.numberOfCalculations() == i+1);
|
||||
}
|
||||
/* Store is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} */
|
||||
for (int i = 0; i < CalculationStore::k_maxNumberOfCalculations; i++) {
|
||||
assert(store.calculationAtIndex(i)->input()->approximate(globalContext) == i);
|
||||
}
|
||||
store.push("10", &globalContext);
|
||||
/* Store is now {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} */
|
||||
assert(store.calculationAtIndex(9)->input()->approximate(globalContext) == 10);
|
||||
assert(store.calculationAtIndex(0)->input()->approximate(globalContext) == 1);
|
||||
for (int i = 0; i < CalculationStore::k_maxNumberOfCalculations; i++) {
|
||||
char text[2] = {(char)(i+'0'), 0};
|
||||
store.push(text, &globalContext);
|
||||
assert(store.numberOfCalculations() == 10);
|
||||
}
|
||||
/* Store is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} */
|
||||
for (int i = 9; i > 0; i = i-2) {
|
||||
store.deleteCalculationAtIndex(i);
|
||||
}
|
||||
/* Store is now {0, 2, 4, 6, 8} */
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assert(store.calculationAtIndex(i)->input()->approximate(globalContext) == 2.0f*i);
|
||||
}
|
||||
for (int i = 5; i < CalculationStore::k_maxNumberOfCalculations; i++) {
|
||||
char text[3] = {(char)(i+'0'), 0};
|
||||
store.push(text, &globalContext);
|
||||
assert(store.numberOfCalculations() == i+1);
|
||||
}
|
||||
/* Store is now {0, 2, 4, 6, 8, 5, 6, 7, 8, 9} */
|
||||
}
|
||||
@@ -8,7 +8,7 @@ $(symbols_file): $(tests)
|
||||
@awk -f quiz/src/symbols.awk $(tests) > $@
|
||||
|
||||
runner_objs += $(addprefix quiz/src/, runner.o symbols.o i18n.o)
|
||||
test_objs = $(subst .c,.o, $(subst .cpp,.o,$(tests)))
|
||||
test_objs += $(subst .c,.o, $(subst .cpp,.o,$(tests)))
|
||||
|
||||
test.$(EXE): $(runner_objs) $(test_objs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user