/************************************************* * B_tree_node_tester * A class for testing B-tree nodes. * * Author: Douglas Wilhelm Harder * Copyright (c) 2006-11 by Douglas Wilhelm Harder. All rights reserved. * * DO NOT EDIT THIS FILE *************************************************/ #ifndef B_TREE_NODE_TESTER_H #define B_TREE_NODE_TESTER_H #ifndef nullptr #define nullptr 0 #endif #include "Exception.h" #include "Tester.h" #include "B_tree_node.h" #include template class B_tree_node_tester:public Tester< B_tree_node > { using Tester< B_tree_node >::object; using Tester< B_tree_node >::command; public: B_tree_node_tester( B_tree_node *obj = 0 ):Tester< B_tree_node >( obj ) { // empty } void process(); }; /**************************************************** * void process() * * Process the current command. For B-tree nodes, these include: * * Accessors * * size n size the size equals n * full b full the result is the Boolean value b * empty b empty the result is the Boolean value b * leaf b leaf the result is the Boolean value b * subtree n subtree the nth subtree is not 0 and sends the next N instructions to B_tree_node_tester * retrieve n m retrieve the nth element in the tree is m * count n m count the count of n is m * * No mutator testing * * Others * summary prints the amount of memory allocated * minus the memory deallocated * details prints a detailed description of which * memory was allocated with details * !! use the previous command, e.g. 5 push_front 3 * 6 !! 7 // same as push_front 7 * !n use the command used in line n 7 front 7 * 8 !7 9 // same as push_front 9 * ****************************************************/ template void B_tree_node_tester::process() { if ( command == "size" ) { // check if the size equals the next integer read int expected_size; std::cin >> expected_size; int actual_size = object->size(); if ( actual_size == expected_size ) { std::cout << "Okay" << std::endl; } else { std::cout << "Failure in size(): expecting the value '" << expected_size << "' but got '" << actual_size << "'" << std::endl; } } else if ( command == "full" ) { // check if the full status equals the next Boolean read bool expected_full; std::cin >> expected_full; bool actual_full = object->full(); if ( actual_full == expected_full ) { std::cout << "Okay" << std::endl; } else { std::cout << "Failure in full(): expecting the value '" << expected_full << "' but got '" << actual_full << "'" << std::endl; } } else if ( command == "empty" ) { // check if the empty status equals the next Boolean read bool expected_empty; std::cin >> expected_empty; bool actual_empty = object->empty(); if ( actual_empty == expected_empty ) { std::cout << "Okay" << std::endl; } else { std::cout << "Failure in empty(): expecting the value '" << expected_empty << "' but got '" << actual_empty << "'" << std::endl; } } else if ( command == "leaf" ) { // check if the leaf status equals the next Boolean read bool expected_leaf; std::cin >> expected_leaf; bool actual_leaf = object->leaf(); if ( actual_leaf == expected_leaf ) { std::cout << "Okay" << std::endl; } else { std::cout << "Failure in leaf(): expecting the value '" << expected_leaf << "' but got '" << actual_leaf << "'" << std::endl; } } else if ( command == "subtree" ) { // checks that the nth subtree is not null, and if it is not, // the next object gives the number of commands which should // be tested by the B_tree_node int n; std::cin >> n; B_tree_node *actual_subtree = object->subtree( n ); if ( actual_subtree == 0 ) { std::cout << "Failure in subtree( " << n << " ): expecting a non-null sub-tree pointer" << std::endl; } else { std::cout << "Okay" << std::endl; B_tree_node_tester tester( actual_subtree ); tester.run(); } } else if ( command == "retrieve" ) { // checks if the first object in the linked list equals the next object read int n; std::cin >> n; Type expected_retrieve; std::cin >> expected_retrieve; Type actual_retrieve = object->retrieve( n ); if ( actual_retrieve == expected_retrieve ) { std::cout << "Okay" << std::endl; } else { std::cout << "Failure in retrieve( " << n << " ): expecting the value '" << expected_retrieve << "' but got '" << actual_retrieve << "'" << std::endl; } } else if ( command == "count" ) { // check if the next object read in is in the B-tree node Type element; int expected_count; std::cin >> element; std::cin >> expected_count; int actual_count = object->count( element ); if ( actual_count == expected_count ) { std::cout << "Okay" << std::endl; } else { std::cout << "Failure in count( " << element << " ): expecting the value '" << expected_count << "' but got '" << actual_count << "'" << std::endl; } } else { std::cout << command << ": Command not found." << std::endl; } } #endif