diff --git a/apps/calculation/Makefile b/apps/calculation/Makefile index e5f464fcf..22457b7c3 100644 --- a/apps/calculation/Makefile +++ b/apps/calculation/Makefile @@ -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 diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index 182b769d3..c8c4a2015 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -5,6 +5,8 @@ using namespace Poincare; namespace Calculation { Calculation::Calculation() : + m_inputText(""), + m_outputText(""), m_input(nullptr), m_inputLayout(nullptr), m_output(nullptr), diff --git a/apps/calculation/calculation_store.h b/apps/calculation/calculation_store.h index 15eeb0b72..598b7b32a 100644 --- a/apps/calculation/calculation_store.h +++ b/apps/calculation/calculation_store.h @@ -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]; }; diff --git a/apps/calculation/test/.calculation_store.cpp.swp b/apps/calculation/test/.calculation_store.cpp.swp new file mode 100644 index 000000000..27f3ccb66 Binary files /dev/null and b/apps/calculation/test/.calculation_store.cpp.swp differ diff --git a/apps/calculation/test/calculation_store.cpp b/apps/calculation/test/calculation_store.cpp new file mode 100644 index 000000000..c581ecf08 --- /dev/null +++ b/apps/calculation/test/calculation_store.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#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} */ +} diff --git a/quiz/Makefile b/quiz/Makefile index 2028a6f7c..840e30d9a 100644 --- a/quiz/Makefile +++ b/quiz/Makefile @@ -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)