From e75beb661f39cf6d043323c61542ffb4c0d87c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 30 May 2017 13:15:55 +0200 Subject: [PATCH] [apps/calculation] Add test for rinn buffer of calculation store Change-Id: I99b9c75b7bc4927b693a67bb5c022d991eb8dec6 --- apps/calculation/Makefile | 5 ++ apps/calculation/calculation.cpp | 2 + apps/calculation/calculation_store.h | 4 +- .../test/.calculation_store.cpp.swp | Bin 0 -> 12288 bytes apps/calculation/test/calculation_store.cpp | 45 ++++++++++++++++++ quiz/Makefile | 2 +- 6 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 apps/calculation/test/.calculation_store.cpp.swp create mode 100644 apps/calculation/test/calculation_store.cpp 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 0000000000000000000000000000000000000000..27f3ccb66c4d5f92e0c15e2eb6be8312fbf1612e GIT binary patch literal 12288 zcmeI2+iDX*7=R~UX|>f_@cK6eyJ>clO=`7i+Da)Zp=y;-K}E`DGijD?cGo>%wA5aR z7m81zf-m5`cj^=LqWB1+K7sh}p>%Vy2M-YW10TCPyL0%ze`cU`D)Q~pb(qS?41cE> z`%#weydQqXu6PN?8=9{18n+eQf7|mHe&kb%7ncy3La8e|jsT(Hzf zlV@S%^zvS{=sg)A17v^fDDiUGC&5%Kpz@Vs*F84%2??b4j%vizw`J1*OQEGBOj1A$ZO;|q9bd_ zHAF&2kgXxcULqX1gbX1A$krg1BL!p<8Ad*zVC)4_K)xMk>=W_|u@M8AM$RDL2N?T; zd_>+NOUNRUK(=wL?~td+CbEbGFT!~dE{HHC!enrBF}N>mz<3tx`1Jr3$Kkdsgl8NLuTkOlQq4aa86AgogcQuq zf|kyuia~|&OUrZWg3Ft(2&Q^g^oWp?qe&85TFIQ8?7Fo6_)PCT$q$#Dj>vH<>KS}|b^QIU=wD9G z1IY9Dn`ptc*MeY5_}jwO_$CW28&;9sS}xsPS(q +#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)