| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
#include "TestTools.h" |
|---|
| 6 |
#include "Action.h" |
|---|
| 7 |
|
|---|
| 8 |
vector<string> values, values2, values3; |
|---|
| 9 |
SentenceStructure *structure = NULL, *structure2 = NULL; |
|---|
| 10 |
Action *action = NULL, *action2 = NULL, *action3 = NULL; |
|---|
| 11 |
|
|---|
| 12 |
void testConstructor() { |
|---|
| 13 |
|
|---|
| 14 |
cout << "Testing Constructor... "; |
|---|
| 15 |
assertTrue(action->getStructure() == structure, |
|---|
| 16 |
"Structures don't match"); |
|---|
| 17 |
cout << "Passed" << endl; |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
void testAtomicSentences() { |
|---|
| 21 |
|
|---|
| 22 |
cout << "Testing getAtomicSentences and getIndex... "; |
|---|
| 23 |
vector<Sentence*> atomicSentences = action3->getAtomicSentences(); |
|---|
| 24 |
int theIndex; |
|---|
| 25 |
assertEquals(9, atomicSentences.size(), "Atomic Action size failed."); |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
for (unsigned int i = 0; i < atomicSentences.size(); i++) { |
|---|
| 29 |
cout << atomicSentences[i]->getName() << " "; |
|---|
| 30 |
for (unsigned int j = 0; j < atomicSentences[i]->getNumValues(); j++) { |
|---|
| 31 |
cout << (*(atomicSentences[i]))[j] << " "; |
|---|
| 32 |
} |
|---|
| 33 |
cout << endl; |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
int step = 1; |
|---|
| 37 |
unsigned int value = structure2->getOffset(); |
|---|
| 38 |
if (ENDIAN == BIG_ENDIAN) { |
|---|
| 39 |
step = 3; |
|---|
| 40 |
} |
|---|
| 41 |
for(unsigned int i = 0; i < atomicSentences.size(); |
|---|
| 42 |
i++, value += step) |
|---|
| 43 |
{ |
|---|
| 44 |
theIndex = atomicSentences[i]->getIndex(); |
|---|
| 45 |
assertEquals(value, theIndex, "Index test failed."); |
|---|
| 46 |
} |
|---|
| 47 |
cout << "Passed" << endl; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
void testDependencies() { |
|---|
| 51 |
|
|---|
| 52 |
cout << "Testing dependencies... " << endl; |
|---|
| 53 |
action->addAndDependency(action2, true); |
|---|
| 54 |
action->addAndDependency(action3, false); |
|---|
| 55 |
|
|---|
| 56 |
assertEquals(1, action->isDependencyNegated(0), |
|---|
| 57 |
"Negation test failed."); |
|---|
| 58 |
assertEquals(0, action->isDependencyNegated(1), |
|---|
| 59 |
"Negation test2 failed."); |
|---|
| 60 |
vector<vector<Sentence*> > dependencies = action->getDependencies(); |
|---|
| 61 |
assertTrue(dependencies[0][0] == action2, |
|---|
| 62 |
"Dependency test 1 failed."); |
|---|
| 63 |
assertTrue(dependencies[1][0] == action3, |
|---|
| 64 |
"Dependency test 2 failed."); |
|---|
| 65 |
|
|---|
| 66 |
vector<Sentence*> orDependency; |
|---|
| 67 |
orDependency.push_back(action); |
|---|
| 68 |
orDependency.push_back(action3); |
|---|
| 69 |
action2->addOrDependency(orDependency, true); |
|---|
| 70 |
|
|---|
| 71 |
vector<vector<Sentence*> > dependencies2 = action2->getDependencies(); |
|---|
| 72 |
assertTrue(dependencies2[0][0] == action, |
|---|
| 73 |
"Dependency test 3 failed."); |
|---|
| 74 |
assertTrue(dependencies2[0][1] == action3, |
|---|
| 75 |
"Dependency test 4 failed."); |
|---|
| 76 |
cout << "Passed" << endl; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
void testAction() { |
|---|
| 82 |
cout << "Testing new Action functions... "; |
|---|
| 83 |
|
|---|
| 84 |
vector<double> inputs = action->toInputs(); |
|---|
| 85 |
assertEquals(inputs.size(), action->inputSize(), "Sizes do not match"); |
|---|
| 86 |
|
|---|
| 87 |
assertEquals(inputs.size(), 2, "The size is incorrect"); |
|---|
| 88 |
|
|---|
| 89 |
assertEquals(inputs[0], .5, "The first input is incorrect"); |
|---|
| 90 |
assertEquals(inputs[1], 2 / (double) 3, "The second input is incorrect"); |
|---|
| 91 |
|
|---|
| 92 |
cout << "Passed" << endl; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
int main(void) |
|---|
| 96 |
{ |
|---|
| 97 |
|
|---|
| 98 |
cout << "***** Running Tests *****" << endl; |
|---|
| 99 |
|
|---|
| 100 |
values.push_back("1"); |
|---|
| 101 |
values.push_back("2"); |
|---|
| 102 |
values2.push_back("?a"); |
|---|
| 103 |
values2.push_back("?b"); |
|---|
| 104 |
values2.push_back("b"); |
|---|
| 105 |
values3.push_back("?x"); |
|---|
| 106 |
values3.push_back("?y"); |
|---|
| 107 |
values3.push_back("x"); |
|---|
| 108 |
|
|---|
| 109 |
structure = new SentenceStructure("succ", 2, true); |
|---|
| 110 |
structure2= new SentenceStructure("cell", 3, true); |
|---|
| 111 |
structure->setOffset(0); |
|---|
| 112 |
structure->addValue(0, "0"); |
|---|
| 113 |
structure->addValue(0, "1"); |
|---|
| 114 |
structure->addValue(1, "0"); |
|---|
| 115 |
structure->addValue(1, "1"); |
|---|
| 116 |
structure->addValue(1, "2"); |
|---|
| 117 |
|
|---|
| 118 |
structure2->setOffset(6); |
|---|
| 119 |
structure2->addValue(0, "0"); |
|---|
| 120 |
structure2->addValue(0, "1"); |
|---|
| 121 |
structure2->addValue(0, "2"); |
|---|
| 122 |
structure2->addValue(1, "0"); |
|---|
| 123 |
structure2->addValue(1, "1"); |
|---|
| 124 |
structure2->addValue(1, "2"); |
|---|
| 125 |
structure2->addValue(2, "x"); |
|---|
| 126 |
structure2->addValue(2, "o"); |
|---|
| 127 |
structure2->addValue(2, "b"); |
|---|
| 128 |
|
|---|
| 129 |
vector<string> possibleActors; |
|---|
| 130 |
action = new Action(values, structure, "", possibleActors); |
|---|
| 131 |
action2 = new Action(values2, structure2, "", possibleActors); |
|---|
| 132 |
action3 = new Action(values3, structure2, "", possibleActors); |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
testConstructor(); |
|---|
| 136 |
testAtomicSentences(); |
|---|
| 137 |
testDependencies(); |
|---|
| 138 |
testAction(); |
|---|
| 139 |
|
|---|
| 140 |
cout << "***** Tests Passed! *****" << endl; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|