Arthur Dent: completed test-history, merging with Matteo's.

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@651 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-06-22 10:47:23 +00:00
parent e95d915e3a
commit d8cd3577a7
1 changed files with 50 additions and 19 deletions

View File

@ -26,6 +26,7 @@
#include <glibmm/module.h>
#include <cassert>
#include <string>
#include <list>
#include "config.h"
#include "gettext.h"
#include "glibmm/ustring.h"
@ -37,15 +38,21 @@
#include "backend/observed_subject.hh"
#include "backend/schedulable_queue.hh"
#include "backend/dynamic_schedulable.hh"
#include "smartp.hh"
#include "templates/smartp.hh"
using namespace sgpem;
using namespace std;
/** An HistoryTester object offers a simple interface to test the History class.
*
*
*
*/
class HistoryTester
{
public:
public:
HistoryTester(SchedulableQueue sl)
: _history_length(-1), _internal_schedulable_queue(sl)
{}
@ -54,7 +61,8 @@ public:
* checking for anomalies.
* E stands for EnqueueSlice, R for randomize input, T for truncate the last insertion
*/
void test(std::string commands_sequence)
void
test(std::string commands_sequence)
{
// prints the test sequence
std::cout << commands_sequence << endl;
@ -89,25 +97,33 @@ public:
// looks for anomalies
void _standard_test()
void
_standard_test()
{
// checks if the Singleton Pattern has been actually implemented
if (&History::get_instance() != &History::get_instance()) std::cout << "get_instance" << endl;
if (&History::get_instance() != &History::get_instance()) std::cout << "\nget_instance";
// checks if the History is long how it should be
if (History::get_instance().get_current_time() != _history_length) std::cout << "get_current_time" << endl <<History::get_instance().get_current_time() <<',' << _history_length<<endl;
if (History::get_instance().get_current_time() != _history_length) std::cout << "\nget_current_time: real: " << History::get_instance().get_current_time() <<", expected " << _history_length<<endl;
// checks if the History contains the right stuff
for (int i = 0; i < _history_length+1; i++)
int min = History::get_instance().get_current_time();
min = min < _history_length ? min : _history_length;
for (int i = 0; i < min+1; i++)
{
// watch out here, it's if (NOT ...) operator != was not available.
if (!(*History::get_instance().get_simulation_status_at(i) == *_get_simulation_status_at[i]))
if
(
!(
History::get_instance().get_simulation_status_at(i)->has_same_objects( *_get_simulation_status_at[i])
)
)
{
std::cout << "get_simulation_status_at" << endl;
std::cout << "\nget_simulation_status_at";
}
if (History::get_instance().get_scheduled_at(i) != memory::smart_ptr<DynamicSchedulable>(NULL) && !(*History::get_instance().get_scheduled_at(i) == *_get_scheduled_at[i]))
if (History::get_instance().get_scheduled_at(i) != memory::smart_ptr<DynamicSchedulable>(NULL) && !(*(History::get_instance().get_scheduled_at(i)) == *(_get_scheduled_at[i])))
{
std::cout << "get_simulation_status_at" << endl;
std::cout << "\nget_scheduled_at";
}
}
return;
@ -123,7 +139,7 @@ public:
_get_simulation_status_at[_history_length] = new SchedulableQueue(status);
if (History::get_instance().get_scheduled_at(_history_length) != memory::smart_ptr<DynamicSchedulable>(NULL))
_get_scheduled_at[_history_length] = new DynamicSchedulable(*(status.top()));
_get_scheduled_at[_history_length] = new DynamicSchedulable(*(History::get_instance().get_scheduled_at(_history_length)));
else
_get_scheduled_at[_history_length] = NULL;
return;
@ -174,8 +190,8 @@ public:
}
_history_length = _history_length - 1;
History::get_instance().truncate_at(_history_length-1);
}
History::get_instance().truncate_at(_history_length);
return;
}
@ -186,10 +202,9 @@ main(int argc, char** argv)
{
using namespace sgpem;
using Glib::Module;
std::string command("ERERERT"); // the sequence of commands to test
//std::string command("ERERERT"); // the sequence of commands to test
if(argc > 1)
command = argv[1];
@ -256,8 +271,24 @@ main(int argc, char** argv)
initial.add_at_bottom(ss18);
HistoryTester HT(initial);
HT.test(command);
//HT.test("EEEEREREEEERERRREEEEEEEETERRERERTTT");
HT.test("E");
HT.test("EE");
HT.test("EERE");
HT.test("EEEREE");
HT.test("EEEREE");
HT.test("EEER");
HT.test("EEEERER");
HT.test("EEER");
HT.test("EREE");
HT.test("EEEERERT");
HT.test("EEEERERTEEEERERT");
HT.test("EEEERERTEEETRERERT");
HT.test("EEEERERTEEEERRRERT");
HT.test("EEEEEEERERTERERT");
HT.test("EEEEREREEEERERRREEEEEEEETERRERERTTT");
//HT.test(command);
cout << std::endl << "end of test\n";
cout << std::endl << "\nend of test!\n";
exit(0);
}