void testBlock_getFirst(CuTest* testCase) { cactusBlockTestSetup(); CuAssertTrue(testCase, block_getFirst(block) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getFirst(block_getReverse(block)) == rootSegment); Block *block2 = block_construct(1, flower); CuAssertTrue(testCase, block_getFirst(block2) == NULL); CuAssertTrue(testCase, block_getFirst(block_getReverse(block2)) == NULL); cactusBlockTestTeardown(); }
void testBlock_getInstance(CuTest* testCase) { cactusBlockTestSetup(); CuAssertTrue(testCase, block_getInstance(block, segment_getName(rootSegment)) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getInstance(block, segment_getName(leaf1Segment)) == leaf1Segment); CuAssertTrue(testCase, block_getInstance(block, segment_getName(leaf2Segment)) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getInstance(block_getReverse(block), segment_getName(rootSegment)) == rootSegment); CuAssertTrue(testCase, block_getInstance(block_getReverse(block), segment_getName(leaf1Segment)) == segment_getReverse(leaf1Segment)); CuAssertTrue(testCase, block_getInstance(block_getReverse(block), segment_getName(leaf2Segment)) == leaf2Segment); cactusBlockTestTeardown(); }
void testBlock_getName(CuTest* testCase) { cactusBlockTestSetup(); CuAssertTrue(testCase, block_getName(block) != NULL_NAME); CuAssertTrue(testCase, flower_getBlock(flower, block_getName(block)) == block); CuAssertTrue(testCase, block_getName(block) == block_getName(block_getReverse(block))); cactusBlockTestTeardown(); }
void block_check(Block *block) { //Check is connected to flower properly cactusCheck(flower_getBlock(block_getFlower(block), block_getName(block)) == block_getPositiveOrientation(block)); //Check we have actually set built blocks for the flower.. cactusCheck(flower_builtBlocks(block_getFlower(block))); //Checks the two ends are block ends. End *_5End = block_get5End(block); End *_3End = block_get3End(block); cactusCheck(end_isBlockEnd(_5End)); cactusCheck(end_isBlockEnd(_3End)); cactusCheck(end_getOrientation(_5End) == block_getOrientation(block)); cactusCheck(end_getOrientation(_3End) == block_getOrientation(block)); cactusCheck(end_getBlock(_5End) == block); cactusCheck(end_getBlock(_3End) == block); cactusCheck(end_getSide(_5End)); //Check the sides of the ends are consistent. cactusCheck(!end_getSide(_3End)); cactusCheck(block_getLength(block) > 0); //check block has non-zero length //Check reverse Block *rBlock = block_getReverse(block); cactusCheck(rBlock != NULL); cactusCheck(block_getReverse(block) == rBlock); cactusCheck(block_getOrientation(block) == !block_getOrientation(rBlock)); cactusCheck(block_getLength(block) == block_getLength(rBlock)); cactusCheck(block_get5End(block) == end_getReverse(block_get3End(rBlock))); cactusCheck(block_get3End(block) == end_getReverse(block_get5End(rBlock))); cactusCheck(block_getInstanceNumber(block) == block_getInstanceNumber(rBlock)); if(block_getInstanceNumber(block) > 0) { cactusCheck(block_getFirst(block) == segment_getReverse(block_getFirst(rBlock))); if(block_getRootInstance(block) == NULL) { cactusCheck(block_getRootInstance(rBlock) == NULL); } else { cactusCheck(block_getRootInstance(block) == segment_getReverse(block_getRootInstance(rBlock))); } } //For each segment calls segment_check. Block_InstanceIterator *iterator = block_getInstanceIterator(block); Segment *segment; while((segment = block_getNext(iterator)) != NULL) { segment_check(segment); } block_destructInstanceIterator(iterator); }
void flower_check(Flower *flower) { eventTree_check(flower_getEventTree(flower)); Flower_GroupIterator *groupIterator = flower_getGroupIterator(flower); Group *group; while ((group = flower_getNextGroup(groupIterator)) != NULL) { group_check(group); } flower_destructGroupIterator(groupIterator); Flower_ChainIterator *chainIterator = flower_getChainIterator(flower); Chain *chain; while ((chain = flower_getNextChain(chainIterator)) != NULL) { chain_check(chain); } flower_destructCapIterator(chainIterator); //We check built trees in here. Flower_EndIterator *endIterator = flower_getEndIterator(flower); End *end; while ((end = flower_getNextEnd(endIterator)) != NULL) { end_check(end); end_check(end_getReverse(end)); //We will test everything backwards also. } flower_destructEndIterator(endIterator); if (flower_builtFaces(flower)) { Flower_FaceIterator *faceIterator = flower_getFaceIterator(flower); Face *face; while ((face = flower_getNextFace(faceIterator)) != NULL) { face_check(face); } flower_destructFaceIterator(faceIterator); face_checkFaces(flower); } else { cactusCheck(flower_getFaceNumber(flower) == 0); } if (flower_builtBlocks(flower)) { //Note that a flower for which the blocks are not yet built must be a leaf. Flower_BlockIterator *blockIterator = flower_getBlockIterator(flower); Block *block; while ((block = flower_getNextBlock(blockIterator)) != NULL) { block_check(block); block_check(block_getReverse(block)); //We will test everything backwards also. } flower_destructBlockIterator(blockIterator); } else { cactusCheck(flower_isLeaf(flower)); //Defensive cactusCheck(flower_isTerminal(flower)); //Checks that a flower without built blocks is a leaf and does not //contain any blocks. } Flower_SequenceIterator *sequenceIterator = flower_getSequenceIterator(flower); Sequence *sequence; while ((sequence = flower_getNextSequence(sequenceIterator)) != NULL) { sequence_check(sequence); } flower_destructSequenceIterator(sequenceIterator); }
void testEnd_getBlock(CuTest* testCase) { cactusEndTestSetup(); Block *block = block_construct(10, flower); End *leftEnd = block_get5End(block); End *rightEnd = block_get3End(block); CuAssertTrue(testCase, end_getBlock(end) == NULL); CuAssertTrue(testCase, end_getBlock(end_getReverse(end)) == NULL); CuAssertTrue(testCase, end_getBlock(leftEnd) == block); CuAssertTrue(testCase, end_getBlock(end_getReverse(leftEnd)) == block_getReverse(block)); CuAssertTrue(testCase, block_getOrientation(block) == end_getOrientation(leftEnd)); CuAssertTrue(testCase, end_getBlock(rightEnd) == block); CuAssertTrue(testCase, end_getBlock(end_getReverse(rightEnd)) == block_getReverse(block)); CuAssertTrue(testCase, block_getOrientation(block) == end_getOrientation(rightEnd)); cactusEndTestTeardown(); }
void testBlock_getSegmentForEvent(CuTest* testCase) { cactusBlockTestSetup(); CuAssertPtrEquals(testCase, block_getSegmentForEvent(block_getReverse(block), event_getName(rootEvent)), rootSegment); Segment *segment = block_getSegmentForEvent(block, event_getName(leafEvent)); CuAssertTrue(testCase, segment == leaf1Segment || segment == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getSegmentForEvent(block, NULL_NAME) == NULL); cactusBlockTestTeardown(); }
void testBlock_instanceIterator(CuTest* testCase) { cactusBlockTestSetup(); Block_InstanceIterator *iterator; iterator = block_getInstanceIterator(block); CuAssertTrue(testCase, iterator != NULL); CuAssertTrue(testCase, block_getNext(iterator) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getNext(iterator) == leaf1Segment); Block_InstanceIterator *iterator2 = block_copyInstanceIterator(iterator); CuAssertTrue(testCase, block_getNext(iterator) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getNext(iterator) == NULL); CuAssertTrue(testCase, block_getPrevious(iterator) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getPrevious(iterator) == leaf1Segment); CuAssertTrue(testCase, block_getPrevious(iterator) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getPrevious(iterator) == NULL); CuAssertTrue(testCase, block_getNext(iterator2) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getNext(iterator2) == NULL); CuAssertTrue(testCase, block_getPrevious(iterator2) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getPrevious(iterator2) == leaf1Segment); CuAssertTrue(testCase, block_getPrevious(iterator2) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getPrevious(iterator2) == NULL); block_destructInstanceIterator(iterator); block_destructInstanceIterator(iterator2); iterator = block_getInstanceIterator(block_getReverse(block)); CuAssertTrue(testCase, block_getNext(iterator) == rootSegment); CuAssertTrue(testCase, block_getNext(iterator) == segment_getReverse(leaf1Segment)); CuAssertTrue(testCase, block_getNext(iterator) == leaf2Segment); CuAssertTrue(testCase, block_getNext(iterator) == NULL); CuAssertTrue(testCase, block_getPrevious(iterator) == leaf2Segment); CuAssertTrue(testCase, block_getPrevious(iterator) == segment_getReverse(leaf1Segment)); CuAssertTrue(testCase, block_getPrevious(iterator) == rootSegment); CuAssertTrue(testCase, block_getPrevious(iterator) == NULL); block_destructInstanceIterator(iterator); cactusBlockTestTeardown(); }
Block *block_getPositiveOrientation(Block *block) { return block_getOrientation(block) ? block : block_getReverse(block); }
void testBlock_getReverse(CuTest* testCase) { cactusBlockTestSetup(); CuAssertTrue(testCase, block_getReverse(block) != NULL); CuAssertTrue(testCase, block_getReverse(block_getReverse(block)) == block); cactusBlockTestTeardown(); }
void testBlock_getOrientation(CuTest* testCase) { cactusBlockTestSetup(); CuAssertTrue(testCase, block_getOrientation(block)); CuAssertTrue(testCase, !block_getOrientation(block_getReverse(block))); cactusBlockTestTeardown(); }