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:
parent
e95d915e3a
commit
d8cd3577a7
|
@ -26,6 +26,7 @@
|
||||||
#include <glibmm/module.h>
|
#include <glibmm/module.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <list>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "glibmm/ustring.h"
|
#include "glibmm/ustring.h"
|
||||||
|
@ -37,15 +38,21 @@
|
||||||
#include "backend/observed_subject.hh"
|
#include "backend/observed_subject.hh"
|
||||||
#include "backend/schedulable_queue.hh"
|
#include "backend/schedulable_queue.hh"
|
||||||
#include "backend/dynamic_schedulable.hh"
|
#include "backend/dynamic_schedulable.hh"
|
||||||
|
#include "templates/smartp.hh"
|
||||||
#include "smartp.hh"
|
|
||||||
|
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/** An HistoryTester object offers a simple interface to test the History class.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
class HistoryTester
|
class HistoryTester
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
HistoryTester(SchedulableQueue sl)
|
HistoryTester(SchedulableQueue sl)
|
||||||
: _history_length(-1), _internal_schedulable_queue(sl)
|
: _history_length(-1), _internal_schedulable_queue(sl)
|
||||||
{}
|
{}
|
||||||
|
@ -54,7 +61,8 @@ public:
|
||||||
* checking for anomalies.
|
* checking for anomalies.
|
||||||
* E stands for EnqueueSlice, R for randomize input, T for truncate the last insertion
|
* 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
|
// prints the test sequence
|
||||||
std::cout << commands_sequence << endl;
|
std::cout << commands_sequence << endl;
|
||||||
|
@ -89,25 +97,33 @@ public:
|
||||||
|
|
||||||
|
|
||||||
// looks for anomalies
|
// looks for anomalies
|
||||||
void _standard_test()
|
void
|
||||||
|
_standard_test()
|
||||||
{
|
{
|
||||||
// checks if the Singleton Pattern has been actually implemented
|
// 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
|
// 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
|
// 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.
|
// 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;
|
return;
|
||||||
|
@ -123,7 +139,7 @@ public:
|
||||||
_get_simulation_status_at[_history_length] = new SchedulableQueue(status);
|
_get_simulation_status_at[_history_length] = new SchedulableQueue(status);
|
||||||
|
|
||||||
if (History::get_instance().get_scheduled_at(_history_length) != memory::smart_ptr<DynamicSchedulable>(NULL))
|
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
|
else
|
||||||
_get_scheduled_at[_history_length] = NULL;
|
_get_scheduled_at[_history_length] = NULL;
|
||||||
return;
|
return;
|
||||||
|
@ -174,8 +190,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
_history_length = _history_length - 1;
|
_history_length = _history_length - 1;
|
||||||
|
History::get_instance().truncate_at(_history_length-1);
|
||||||
}
|
}
|
||||||
History::get_instance().truncate_at(_history_length);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,10 +202,9 @@ main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
using Glib::Module;
|
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)
|
if(argc > 1)
|
||||||
command = argv[1];
|
command = argv[1];
|
||||||
|
|
||||||
|
@ -256,8 +271,24 @@ main(int argc, char** argv)
|
||||||
initial.add_at_bottom(ss18);
|
initial.add_at_bottom(ss18);
|
||||||
|
|
||||||
HistoryTester HT(initial);
|
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);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue