summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2013-04-23 09:47:29 -0600
committerMike Buland <mike@xagasoft.com>2013-04-23 09:47:29 -0600
commitc234914394b4c8cdee66d7528bad3c132f90dc4d (patch)
treee2204b30d1edd0d7f45a5f8579738e8fa274c644
parent95da25821bcbcd6a94a7fdf64da1618f5324b779 (diff)
downloadclic-c234914394b4c8cdee66d7528bad3c132f90dc4d.tar.gz
clic-c234914394b4c8cdee66d7528bad3c132f90dc4d.tar.bz2
clic-c234914394b4c8cdee66d7528bad3c132f90dc4d.tar.xz
clic-c234914394b4c8cdee66d7528bad3c132f90dc4d.zip
Added cli params & a unit test.
-rw-r--r--src/main.cpp5
-rw-r--r--src/options.cpp24
-rw-r--r--src/options.h16
-rw-r--r--src/unitnumber.cpp22
-rw-r--r--src/unitnumber.h15
5 files changed, 81 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 0325db0..afa1d5e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,6 +3,7 @@
3#include "lexer.h" 3#include "lexer.h"
4#include "token.h" 4#include "token.h"
5#include "parser.h" 5#include "parser.h"
6#include "options.h"
6#include <math.h> 7#include <math.h>
7#include <sys/time.h> 8#include <sys/time.h>
8 9
@@ -360,8 +361,10 @@ void fractest()
360 println("%1 / %2 = %3").arg( a ).arg( b ).arg( a / b ); 361 println("%1 / %2 = %3").arg( a ).arg( b ).arg( a / b );
361} 362}
362 363
363int main( int , char *[] ) 364int main( int argc, char *argv[] )
364{ 365{
366 Options opt( argc, argv );
367
365 println("CliC - 0.02"); 368 println("CliC - 0.02");
366 println("Try \\exit, \\scale, and \\radix commands."); 369 println("Try \\exit, \\scale, and \\radix commands.");
367 println(""); 370 println("");
diff --git a/src/options.cpp b/src/options.cpp
new file mode 100644
index 0000000..ef46e82
--- /dev/null
+++ b/src/options.cpp
@@ -0,0 +1,24 @@
1#include "options.h"
2
3#include "unitnumber.h"
4
5Options::Options( int argc, char *argv[] )
6{
7 addOption( Bu::slot(this, &Options::selfTest), "self-test",
8 "Run a series of tests to ensure everything is working correctly.");
9 addHelpOption('h', "help", "This help");
10
11 parse( argc, argv );
12}
13
14Options::~Options()
15{
16}
17
18int Options::selfTest( Bu::StringArray aArgs )
19{
20 UnitNumber().run();
21
22 exit( 0 );
23}
24
diff --git a/src/options.h b/src/options.h
new file mode 100644
index 0000000..667e486
--- /dev/null
+++ b/src/options.h
@@ -0,0 +1,16 @@
1#ifndef OPTIONS_H
2#define OPTIONS_H
3
4#include <bu/optparser.h>
5
6class Options : public Bu::OptParser
7{
8public:
9 Options( int argc, char *argv[] );
10 virtual ~Options();
11
12private:
13 int selfTest( Bu::StringArray aArgs );
14};
15
16#endif
diff --git a/src/unitnumber.cpp b/src/unitnumber.cpp
new file mode 100644
index 0000000..d4bc7a8
--- /dev/null
+++ b/src/unitnumber.cpp
@@ -0,0 +1,22 @@
1#include "unitnumber.h"
2
3#include "number.h"
4
5UnitNumber::UnitNumber()
6{
7 setName("Number");
8 add( static_cast<Bu::UnitSuite::Test>(&UnitNumber::multiply1),
9 "multiply1", Bu::UnitSuite::expectPass );
10}
11
12UnitNumber::~UnitNumber()
13{
14}
15
16void UnitNumber::multiply1()
17{
18 unitTest(
19 (Number("123456789123456789") * Number("987654321987654321")).toString()
20 == "121932631356500531347203169112635269" );
21}
22
diff --git a/src/unitnumber.h b/src/unitnumber.h
new file mode 100644
index 0000000..89b1c0f
--- /dev/null
+++ b/src/unitnumber.h
@@ -0,0 +1,15 @@
1#ifndef UNIT_NUMBER_H
2#define UNIT_NUMBER_H
3
4#include <bu/unitsuite.h>
5
6class UnitNumber : public Bu::UnitSuite
7{
8public:
9 UnitNumber();
10 virtual ~UnitNumber();
11
12 void multiply1();
13};
14
15#endif