// /*--------------------------------------------------------*\ // | Main Program: Simple tester for Natural Power extension // |*--------------------------------------------------------*| // | Date: Summer Quarter 2006 // | Author: Bruce W. Weide (adapted from "anonymous") // | // | Brief User's Manual: // | Allows user either to exercise the Power operation // | in an interactive menu-driven mode or in a batch // | file mode (using input redirection). // | // | Modified: 8 April 2004 // | Modifier: Wayne D. Heym // | Modification: // | Support for comments in test scripts // | // | Modified: 6 December 2006 // | Modifier: Tim Long // | Modification: // | Request expected outgoing values for each test case // | // \*--------------------------------------------------------*/ ///------------------------------------------------------------- /// Global Context --------------------------------------------- ///------------------------------------------------------------- #include "RESOLVE_Foundation.h" #include "CI/Natural/Power_1.h" ///------------------------------------------------------------- /// Interface -------------------------------------------------- ///------------------------------------------------------------- program_body main () { object Character_IStream input; object Character_OStream output; object Text response; object Boolean interactive_mode; object Integer p, p_exp_out; object Natural_Power_1 n, n_exp_out; // Open input and output streams input.Open_External (""); output.Open_External (""); // Ask user about interactive mode output << "Run in interactive mode (y/n)? "; input >> response; interactive_mode = (response == "y"); output << "\n"; // Ask user for whether to test if (interactive_mode) { output << "Start testing (y/n)? "; } input >> response; // Execute interactive testing loop until finished while (response != "n") { if (response != "y") { output << response << '\n'; } else { // Get values for n and p for this test case if (interactive_mode) { output << "n = "; } input >> n; if (interactive_mode) { output << "p = "; } input >> p; // Get expected output for n and p for this test case if (interactive_mode) { output << "\nexpected output for n = "; } input >> n_exp_out; if (interactive_mode) { output << "expected output for p = "; } input >> p_exp_out; // Report results of this test case output << "-------------------------------------------------\n" << " | n = " << n << '\n' << " | p = " << p << '\n' << "-------------------------------------------------\n"; n.Power (p); output << "n.Power (p); |\n" << "-------------------------------------------------\n" << " | n = " << n << '\n' << " | p = " << p << '\n' << "-------------------------------------------------\n"; if (p != p_exp_out) { output << "\nERROR DETECTED:\n" << " expected p = " << p_exp_out << '\n' << " observed p = " << p << "\nEXECUTION TERMINATING\n"; return 0; } if (n.Compare (n_exp_out) != 0) { output << "ERROR DETECTED:\n" << " expected n = " << n_exp_out << '\n' << " observed n = " << n << "\nEXECUTION TERMINATING\n"; return 0; } } // Determine whether to continue testing if (interactive_mode) { output << "\nContinue testing (y/n)? "; } input >> response; } // Close input and output streams input.Close_External (); output.Close_External (); }