Source of test_operationcounter.cpp


  1: //test_operationcounter.cpp
  2: //A test driver for the Scobey::OperationCounter class.

  4: #include <iostream>
  5: using namespace std;

  7: #include "utilities.h"
  8: using Scobey::OperationCounter;
  9: using Scobey::Pause;

 11: int main()
 12: {
 13:     Pause(0, "\nTesting the Scobey::OperationCounter class ..."
 14:         "\n\nOur first display is the output from displayNonZeroCounts "
 15:         "immediately after\ncreating the counter object, and followed "
 16:         "by a default pause.");

 18:     OperationCounter counter;
 19:     counter.displayNonZeroCounts();
 20:     Pause();

 22:     Pause(0, "Our next display is the output from displayAllCounts "
 23:         "immediately after\ncreating the counter object, and followed "
 24:         "by a default pause.");
 25:     counter.displayAllCounts();
 26:     Pause();

 28:     Pause(0, "\nNext, we will first count 1 comparison, 2 exchanges, "
 29:         "and 3 assignments.\nThen we will set the name of the "
 30:         "\"other\" operation to \"Function Calls\",\nand count 4 of "
 31:         "these operations. No such operations are actually performed."
 32:         "\nThen we show both displays after those counts. Note that "
 33:         "both displays are\nthe same, because everything, including the "
 34:         "\"other\" operation, was counted\nat least once.");

 36:     counter.incrementComparisons();
 37:     counter.incrementExchanges(2);
 38:     counter.incrementAssignments(3);
 39:     counter.setNameOfOtherOp("Function Calls");
 40:     counter.incrementOtherOp(4);
 41:     counter.displayNonZeroCounts();
 42:     Pause();
 43:     counter.displayAllCounts();
 44:     Pause();

 46:     counter.reset();
 47:     Pause(0, "\nFinally, we reset the counter, count just 2 "
 48:         "comparisons and 4 assignments,\nand then show the same "
 49:         "two displays as above.");

 51:     counter.incrementComparisons(2);
 52:     counter.incrementAssignments(4);

 54:     counter.displayNonZeroCounts();
 55:     Pause();
 56:     counter.displayAllCounts();
 57:     Pause();
 58:     Pause(0, "Note that the default name of the \"other\" operation "
 59:         "is \"Other Op\" if no name\nis supplied by the client.");

 61:     Pause(0, "No more tests to perform.\n"
 62:         "Program will now terminate.");
 63: }