|
| 1 | +#include "test01.h" |
| 2 | +#include "test/lib/testclass.h" |
| 3 | +/** |
| 4 | + * Testing linked list |
| 5 | + */ |
| 6 | +void TTest01::doRun() |
| 7 | +{ |
| 8 | + test01(); |
| 9 | + if(getFailed()) return; |
| 10 | + test02(); |
| 11 | + if(getFailed()) return; |
| 12 | + test03(); |
| 13 | +} |
| 14 | + |
| 15 | +void TTest01::test01() |
| 16 | +{ |
| 17 | + if(list->getStart() != nullptr) fail(" getStart is not null"); |
| 18 | + if(list->getEnd() != nullptr) fail(" End of linklist is not null"); |
| 19 | + if(list->getLength() != 0) fail(" Length !=0"); |
| 20 | + if(!list->isEmpty()) fail("isEmopty returns false"); |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +void TTest01::test02() |
| 25 | +{ |
| 26 | + item1=new TTestItem(1); |
| 27 | + list->append(item1); |
| 28 | + if(list->getStart()==nullptr) { |
| 29 | + fail(" GetStart is null after append"); |
| 30 | + return; |
| 31 | + } |
| 32 | + if(list->getStart() != list->getEnd()){ |
| 33 | + fail("Start and end not equal after appending one item"); |
| 34 | + } |
| 35 | + if(list->getLength()!= 1){ |
| 36 | + fail(" length != 1 after appending one item"); |
| 37 | + return; |
| 38 | + } |
| 39 | + if(list->getStart()->getItem() != item1){ |
| 40 | + fail("getItem doesn't return appended item"); |
| 41 | + return; |
| 42 | + } |
| 43 | + if(list->getStart()->getItem()->getSomeValue()!=1){ |
| 44 | + fail(" GetSomeValue !=1"); |
| 45 | + return; |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | + |
| 50 | +void TTest01::test03() |
| 51 | +{ |
| 52 | + item2=new TTestItem(2); |
| 53 | + list->append(item2); |
| 54 | + if(list->getStart()->getItem() != item1){ |
| 55 | + fail("After appending second item=>fist item != item1"); |
| 56 | + } |
| 57 | + if(list->getEnd()->getItem() != item2){ |
| 58 | + fail("After appending second item end 1= item2"); |
| 59 | + } |
| 60 | + if(list->getLength() != 2){ |
| 61 | + fail("After appending second item length != 2"); |
| 62 | + } |
| 63 | + if(list->isEmpty()){ |
| 64 | + fail("After appending =>isEmpty returns true"); |
| 65 | + } |
| 66 | + return; |
| 67 | +} |
| 68 | + |
| 69 | +TTest01::~TTest01() |
| 70 | +{ |
| 71 | + delete list; |
| 72 | +} |
| 73 | + |
| 74 | +TTest01::TTest01() |
| 75 | +{ |
| 76 | + list=new TLinkList<TTestItem>(); |
| 77 | +} |
| 78 | + |
0 commit comments