mirror of https://gitlab.com/rnger/amath
Improved tests
This commit is contained in:
parent
27fb80dcd9
commit
77e54f9c5e
|
@ -438,7 +438,7 @@ amigacatalogs:
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: app
|
test: app
|
||||||
./amath test
|
./amath testz
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: app
|
install: app
|
||||||
|
|
|
@ -33,5 +33,5 @@ int main(int argc, char **argv)
|
||||||
Program->Initialize(argc, argv);
|
Program->Initialize(argc, argv);
|
||||||
Program->Run();
|
Program->Run();
|
||||||
Cleanup();
|
Cleanup();
|
||||||
return 0;
|
return Program->GetExitStatus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,9 @@ static struct IntuitionBase *IntuitionBase = NULL;
|
||||||
class Program* CreateProgram(int argc, char **argv) {
|
class Program* CreateProgram(int argc, char **argv) {
|
||||||
#ifdef WITHTEST
|
#ifdef WITHTEST
|
||||||
if (argc == 2 && StrIsEqual(argv[1], "test")) {
|
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
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
Program::Program()
|
Program::Program()
|
||||||
{
|
{
|
||||||
|
status = 0;
|
||||||
Variables = new VariableList();
|
Variables = new VariableList();
|
||||||
Functions = new FunctionList();
|
Functions = new FunctionList();
|
||||||
Graphs = new GraphList();
|
Graphs = new GraphList();
|
||||||
|
@ -104,3 +105,8 @@ void Program::SetLastResult(Number *number)
|
||||||
delete ins;
|
delete ins;
|
||||||
ins = number->Clone();
|
ins = number->Clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Program::GetExitStatus()
|
||||||
|
{
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ public:
|
||||||
void NewPositionalOutput(short unsigned int base, short unsigned int digits);
|
void NewPositionalOutput(short unsigned int base, short unsigned int digits);
|
||||||
void SetLastResult(Number *number);
|
void SetLastResult(Number *number);
|
||||||
void SetPrompt(const char *text);
|
void SetPrompt(const char *text);
|
||||||
|
int GetExitStatus();
|
||||||
struct Number* GetLastResult();
|
struct Number* GetLastResult();
|
||||||
class Language *Language;
|
class Language *Language;
|
||||||
class ConsoleBase *Console;
|
class ConsoleBase *Console;
|
||||||
|
@ -75,6 +76,9 @@ public:
|
||||||
class FunctionList *Functions;
|
class FunctionList *Functions;
|
||||||
class GraphList *Graphs;
|
class GraphList *Graphs;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int status;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Number* ins;
|
struct Number* ins;
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,9 +33,11 @@
|
||||||
#include "system/base/io.h"
|
#include "system/base/io.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
TestProgram::TestProgram()
|
TestProgram::TestProgram(bool silent)
|
||||||
: Program()
|
: Program()
|
||||||
{
|
{
|
||||||
|
this->silent = silent;
|
||||||
|
|
||||||
// Ignore type of locale fraction point.
|
// Ignore type of locale fraction point.
|
||||||
delete Input;
|
delete Input;
|
||||||
Input = new DecimalSystem(Preferences->GetDigits(), '.');
|
Input = new DecimalSystem(Preferences->GetDigits(), '.');
|
||||||
|
@ -52,10 +54,11 @@ void TestProgram::Run()
|
||||||
RunTests();
|
RunTests();
|
||||||
|
|
||||||
if (fail == 0) {
|
if (fail == 0) {
|
||||||
printf("All tests passed (%i)." NEWLINE, pass);
|
printf("All tests passed (%i)" NEWLINE, pass);
|
||||||
} else {
|
} else {
|
||||||
printf("Something went wrong ..." NEWLINE);
|
printf("Something went wrong ..." NEWLINE);
|
||||||
printf("Passed: %i, failed: %i" NEWLINE, pass, fail);
|
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) {
|
if (buf->Is(result) || !check) {
|
||||||
pass++;
|
pass++;
|
||||||
printf("PASS: [%s]" NEWLINE, show ? result : input);
|
if (!silent) {
|
||||||
|
printf("PASS: [%s]" NEWLINE, show ? result : input);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fail++;
|
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;
|
delete buf;
|
||||||
|
@ -332,16 +339,16 @@ void TestProgram::RunTestset4()
|
||||||
void TestProgram::RunTestset5()
|
void TestProgram::RunTestset5()
|
||||||
{
|
{
|
||||||
TestExecution("delete funtions");
|
TestExecution("delete funtions");
|
||||||
TestStatement("f(x)=x*2+1", "");
|
TestStatement("f(x)=x*2+1", EMPTYSTRING);
|
||||||
TestStatement("g(y)=y^2+y*1.5+2", "");
|
TestStatement("g(y)=y^2+y*1.5+2", EMPTYSTRING);
|
||||||
TestStatement("h(x)=x^3-2*x^2-16*x+6", "");
|
TestStatement("h(x)=x^3-2*x^2-16*x+6", EMPTYSTRING);
|
||||||
TestStatement("a=2;b=3;c=a+b;", "");
|
TestStatement("a=2;b=3;c=a+b;", EMPTYSTRING);
|
||||||
TestStatement("vars", "a = 2" NEWLINE "b = 3" NEWLINE "c = 5");
|
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("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("f(2.2)", "f(2.2) = 5.4");
|
||||||
TestStatement("h(8.3)", "h(8.3) = 307.207");
|
TestStatement("h(8.3)", "h(8.3) = 307.207");
|
||||||
TestStatement("c+1.1", "c+1.1 = 6.1");
|
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) = 2.1");
|
||||||
TestStatement("eval d=d+1", "d=(d+1) = 3.1");
|
TestStatement("eval d=d+1", "d=(d+1) = 3.1");
|
||||||
TestStatement("eval d=d*2", "d=(d*2) = 6.2");
|
TestStatement("eval d=d*2", "d=(d*2) = 6.2");
|
||||||
|
|
|
@ -41,13 +41,14 @@
|
||||||
*/
|
*/
|
||||||
class TestProgram : public Program {
|
class TestProgram : public Program {
|
||||||
public:
|
public:
|
||||||
TestProgram();
|
TestProgram(bool silent);
|
||||||
virtual ~TestProgram();
|
virtual ~TestProgram();
|
||||||
virtual void Initialize(int argc, char **argv);
|
virtual void Initialize(int argc, char **argv);
|
||||||
virtual void Run();
|
virtual void Run();
|
||||||
virtual void Exit();
|
virtual void Exit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool silent;
|
||||||
int pass;
|
int pass;
|
||||||
int fail;
|
int fail;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue