From c5beb6fdd24dffa27ac5a06b6c6aa602970f5f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 4 Nov 2020 12:17:32 +0100 Subject: [PATCH] [app/sequence] Test: avoid duplicating sequence stores and ensure to tidy it (empty the Poincare Pool) between quiz_cases --- apps/sequence/test/sequence.cpp | 21 +++++++++++++-------- apps/shared/global_context.cpp | 2 -- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/sequence/test/sequence.cpp b/apps/sequence/test/sequence.cpp index c7bc064e9..fb729ab14 100644 --- a/apps/sequence/test/sequence.cpp +++ b/apps/sequence/test/sequence.cpp @@ -30,12 +30,12 @@ Sequence * addSequence(SequenceStore * store, Sequence::Type type, const char * void check_sequences_defined_by(double result[MaxNumberOfSequences][10], Sequence::Type types[MaxNumberOfSequences], const char * definitions[MaxNumberOfSequences], const char * conditions1[MaxNumberOfSequences], const char * conditions2[MaxNumberOfSequences]) { Shared::GlobalContext globalContext; - SequenceStore store; - SequenceContext sequenceContext(&globalContext, &store); + SequenceStore * store = globalContext.sequenceStore(); + SequenceContext sequenceContext(&globalContext, store); Sequence * seqs[MaxNumberOfSequences]; for (int i = 0; i < MaxNumberOfSequences; i++) { - seqs[i] = addSequence(&store, types[i], definitions[i], conditions1[i], conditions2[i], &globalContext); + seqs[i] = addSequence(store, types[i], definitions[i], conditions1[i], conditions2[i], &globalContext); } for (int j = 0; j < 10; j++) { @@ -46,20 +46,25 @@ void check_sequences_defined_by(double result[MaxNumberOfSequences][10], Sequenc } } } - store.removeAll(); + store->removeAll(); + /* The store is a global variable that has been contructed through + * GlobalContext::sequenceStore singleton. It won't be destructed. However, + * we need to make sure that the pool is empty between quiz_cases. */ + store->tidy(); } void check_sum_of_sequence_between_bounds(double result, double start, double end, Sequence::Type type, const char * definition, const char * condition1, const char * condition2) { Shared::GlobalContext globalContext; - SequenceStore store; - SequenceContext sequenceContext(&globalContext, &store); + SequenceStore * store = globalContext.sequenceStore(); + SequenceContext sequenceContext(&globalContext, store); - Sequence * seq = addSequence(&store, type, definition, condition1, condition2, &globalContext); + Sequence * seq = addSequence(store, type, definition, condition1, condition2, &globalContext); double sum = PoincareHelpers::ApproximateToScalar(seq->sumBetweenBounds(start, end, &sequenceContext), &globalContext); quiz_assert(std::fabs(sum - result) < 0.00000001); - store.removeAll(); + store->removeAll(); + store->tidy(); // Cf comment above } QUIZ_CASE(sequence_evaluation) { diff --git a/apps/shared/global_context.cpp b/apps/shared/global_context.cpp index 18bacf7b7..5df988953 100644 --- a/apps/shared/global_context.cpp +++ b/apps/shared/global_context.cpp @@ -18,8 +18,6 @@ SequenceStore * GlobalContext::sequenceStore() { return &sequenceStore; } - - bool GlobalContext::SymbolAbstractNameIsFree(const char * baseName) { return SymbolAbstractRecordWithBaseName(baseName).isNull(); }