Improved tests

This commit is contained in:
Carsten Larsen 2017-02-13 21:07:06 +01:00
parent 27fb80dcd9
commit 77e54f9c5e
7 changed files with 33 additions and 13 deletions

View File

@ -438,7 +438,7 @@ amigacatalogs:
.PHONY: test
test: app
./amath test
./amath testz
.PHONY: install
install: app

View File

@ -33,5 +33,5 @@ int main(int argc, char **argv)
Program->Initialize(argc, argv);
Program->Run();
Cleanup();
return 0;
return Program->GetExitStatus();
}

View File

@ -79,7 +79,9 @@ static struct IntuitionBase *IntuitionBase = NULL;
class Program* CreateProgram(int argc, char **argv) {
#ifdef WITHTEST
if (argc == 2 && StrIsEqual(argv[1], "test")) {
return new TestProgram();
return new TestProgram(false);
} else if (argc == 2 && StrIsEqual(argv[1], "testz")) {
return new TestProgram(true);
} else
#endif
{

View File

@ -34,6 +34,7 @@
Program::Program()
{
status = 0;
Variables = new VariableList();
Functions = new FunctionList();
Graphs = new GraphList();
@ -104,3 +105,8 @@ void Program::SetLastResult(Number *number)
delete ins;
ins = number->Clone();
}
int Program::GetExitStatus()
{
return status;
}

View File

@ -64,6 +64,7 @@ public:
void NewPositionalOutput(short unsigned int base, short unsigned int digits);
void SetLastResult(Number *number);
void SetPrompt(const char *text);
int GetExitStatus();
struct Number* GetLastResult();
class Language *Language;
class ConsoleBase *Console;
@ -75,6 +76,9 @@ public:
class FunctionList *Functions;
class GraphList *Graphs;
protected:
int status;
private:
struct Number* ins;
};

View File

@ -33,9 +33,11 @@
#include "system/base/io.h"
#include <stdio.h>
TestProgram::TestProgram()
TestProgram::TestProgram(bool silent)
: Program()
{
this->silent = silent;
// Ignore type of locale fraction point.
delete Input;
Input = new DecimalSystem(Preferences->GetDigits(), '.');
@ -52,10 +54,11 @@ void TestProgram::Run()
RunTests();
if (fail == 0) {
printf("All tests passed (%i)." NEWLINE, pass);
printf("All tests passed (%i)" NEWLINE, pass);
} else {
printf("Something went wrong ..." NEWLINE);
printf("Passed: %i, failed: %i" NEWLINE, pass, fail);
status = 5; // Set exit status 5
}
}
@ -109,10 +112,14 @@ void TestProgram::PerformTest(const char* input, const char* result, bool show,
if (buf->Is(result) || !check) {
pass++;
printf("PASS: [%s]" NEWLINE, show ? result : input);
if (!silent) {
printf("PASS: [%s]" NEWLINE, show ? result : input);
}
} else {
fail++;
printf("FAIL: [%s] expected [%s] but got [%s]" NEWLINE, input, result, buf->GetString());
if (!silent) {
printf("FAIL: [%s] expected [%s] but got [%s]" NEWLINE, input, result, buf->GetString());
}
}
delete buf;
@ -332,16 +339,16 @@ void TestProgram::RunTestset4()
void TestProgram::RunTestset5()
{
TestExecution("delete funtions");
TestStatement("f(x)=x*2+1", "");
TestStatement("g(y)=y^2+y*1.5+2", "");
TestStatement("h(x)=x^3-2*x^2-16*x+6", "");
TestStatement("a=2;b=3;c=a+b;", "");
TestStatement("f(x)=x*2+1", EMPTYSTRING);
TestStatement("g(y)=y^2+y*1.5+2", EMPTYSTRING);
TestStatement("h(x)=x^3-2*x^2-16*x+6", EMPTYSTRING);
TestStatement("a=2;b=3;c=a+b;", EMPTYSTRING);
TestStatement("vars", "a = 2" NEWLINE "b = 3" NEWLINE "c = 5");
TestStatement("funcs", "f(x)=x*2+1" NEWLINE "g(y)=y^2+y*1.5+2" NEWLINE "h(x)=x^3-2*x^2-16*x+6");
TestStatement("f(2.2)", "f(2.2) = 5.4");
TestStatement("h(8.3)", "h(8.3) = 307.207");
TestStatement("c+1.1", "c+1.1 = 6.1");
TestStatement("d=1.1", "");
TestStatement("d=1.1", EMPTYSTRING);
TestStatement("eval d=d+1", "d=(d+1) = 2.1");
TestStatement("eval d=d+1", "d=(d+1) = 3.1");
TestStatement("eval d=d*2", "d=(d*2) = 6.2");

View File

@ -41,13 +41,14 @@
*/
class TestProgram : public Program {
public:
TestProgram();
TestProgram(bool silent);
virtual ~TestProgram();
virtual void Initialize(int argc, char **argv);
virtual void Run();
virtual void Exit();
private:
bool silent;
int pass;
int fail;