From e04c586c9a54b1c10e7103f7111bb9efb689da66 Mon Sep 17 00:00:00 2001 From: Carsten Larsen Date: Sun, 29 Jan 2017 01:00:29 +0100 Subject: [PATCH] Extend tests --- app/system/program_test.cpp | 53 ++++++++++++++++++++++++++++++++++--- app/system/program_test.h | 4 ++- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/app/system/program_test.cpp b/app/system/program_test.cpp index b6e7b832..06951f49 100644 --- a/app/system/program_test.cpp +++ b/app/system/program_test.cpp @@ -77,19 +77,25 @@ void TestProgram::RunTests() RunTestset3(); RunTestset4(); RunTestset5(); + RunTestset6(); } void TestProgram::TestExpression(const char* expression, const char* result) { - PerformTest(expression, result, true); + PerformTest(expression, result, true, true); } void TestProgram::TestStatement(const char* statement, const char* result) { - PerformTest(statement, result, false); + PerformTest(statement, result, false, true); } -void TestProgram::PerformTest(const char* input, const char* result, bool show) +void TestProgram::TestExecution(const char* statement) +{ + PerformTest(statement, EMPTYSTRING, false, false); +} + +void TestProgram::PerformTest(const char* input, const char* result, bool show, bool check) { Evaluator *evaluator = new Evaluator(input); evaluator->Evaluate(); @@ -100,7 +106,7 @@ void TestProgram::PerformTest(const char* input, const char* result, bool show) buf->RemoveTrailing(NEWLINE); delete evaluator; - if (buf->Is(result)) { + if (buf->Is(result) || !check) { pass++; printf("PASS: [%s]" NEWLINE, show ? result : input); } else { @@ -339,4 +345,43 @@ void TestProgram::RunTestset5() TestStatement("vars", "a = 2" NEWLINE "b = 3" NEWLINE "c = 5" NEWLINE "d = 6.2"); } +void TestProgram::RunTestset6() +{ + TestExecution("help"); + TestExecution("help functions"); + TestExecution("help trigon"); + TestExecution("help hyper"); + TestExecution("help complex"); + TestExecution("help statements"); // Error + TestExecution("help operators"); + TestExecution("help sin"); + TestExecution("help help"); + TestExecution("input hex"); + TestExecution("input dec"); + TestExecution("input oct"); + TestExecution("input bin"); + TestExecution("input 25"); + TestExecution("output hex"); + TestExecution("output dec"); + TestExecution("output oct"); + TestExecution("output bin"); + TestExecution("output 25"); + TestExecution("digits 1"); + TestExecution("digits 5"); + TestExecution("digits 9"); + TestExecution("digits 15"); + TestExecution("digits 33"); + TestExecution("input"); + TestExecution("output"); + TestExecution("digits"); + TestExecution("eval 7+7"); + TestExecution("delete x"); + TestExecution("delete pi"); + TestExecution("eval pi/2"); // Error + TestExecution("list"); + TestExecution("memory"); + TestExecution("version"); + TestExecution("variables"); +} + #endif diff --git a/app/system/program_test.h b/app/system/program_test.h index fb65a76a..2fe65999 100644 --- a/app/system/program_test.h +++ b/app/system/program_test.h @@ -57,8 +57,10 @@ private: void RunTestset3(); void RunTestset4(); void RunTestset5(); + void RunTestset6(); void TestExpression(const char *expression, const char *result); void TestStatement(const char *statement, const char *result); - void PerformTest(const char *input, const char *result, bool show); + void PerformTest(const char *input, const char *result, bool show, bool check); + void TestExecution(const char* statement); };