tr1::shared_ptr<AbstractNumber> E::divide(tr1::shared_ptr<AbstractNumber>number){ char newSign = '-'; if (getSign() == number->getSign()) { newSign = '+'; } if (number -> getName() == "E") { if (newSign == '+') { tr1::shared_ptr<AbstractNumber> output(new SmartInteger(1)); return output; } else { tr1::shared_ptr<AbstractNumber> output(new SmartInteger(-1)); return output; } } else if (number -> getName() == "Exponent") { tr1::shared_ptr<Exponent> numExp = tr1::static_pointer_cast<Exponent>(number); if (numExp -> getValue("base") -> getName() == "E") { tr1::shared_ptr<AbstractNumber> num(new SmartInteger(1)); tr1::shared_ptr<AbstractNumber> exp = number->getValue("power"); tr1::shared_ptr<AbstractNumber> exp2(new SmartInteger(-1)); tr1::shared_ptr<AbstractNumber> me(new E()); tr1::shared_ptr<AbstractNumber> ans2(new Exponent(me, exp -> add(exp2), newSign)); tr1::shared_ptr<AbstractNumber> output2(new MultExpression(num, ans2, '+')); return output2; } } else if(number->getName() == "MultExpression") { tr1::shared_ptr<MultExpression> MultE = tr1::static_pointer_cast<MultExpression>(number); vector<tr1::shared_ptr<AbstractNumber> > MultENum = MultE->getNumerator(); vector<tr1::shared_ptr<AbstractNumber> > MultEDem = MultE->getDenominator(); if (MultEDem.size() == 0) { tr1::shared_ptr<AbstractNumber> one(new SmartInteger(1)); MultEDem.push_back(one); } tr1::shared_ptr<AbstractNumber> reversedMultE(new MultExpression(MultEDem, MultENum, number->getSign())); return reversedMultE->multiply(shared_from_this()); } tr1::shared_ptr<AbstractNumber> output2(new MultExpression(shared_from_this(), number, newSign)); return output2; }
int Dialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDialog::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: ans1(); break; case 1: ans2(); break; case 2: ans3(); break; case 3: ans4(); break; case 4: ans5(); break; case 5: reload(); break; default: ; } _id -= 6; } return _id; }
tr1::shared_ptr<AbstractNumber> E::multiply(tr1::shared_ptr<AbstractNumber>number){ char newSign = '-'; if (getSign() == number->getSign()) { newSign = '+'; } if(number -> getName() == "E") { if (newSign == '+') { tr1::shared_ptr<AbstractNumber> exp(new SmartInteger(2)); tr1::shared_ptr<AbstractNumber> me(new E()); tr1::shared_ptr<AbstractNumber> ans(new Exponent(me, exp)); return ans; } else { tr1::shared_ptr<AbstractNumber> exp(new SmartInteger(-2)); tr1::shared_ptr<AbstractNumber> me(new E()); tr1::shared_ptr<AbstractNumber> ans(new Exponent(me, exp)); return ans; } } else if (number -> getName() == "Exponent") { tr1::shared_ptr<Exponent> numExp = tr1::static_pointer_cast<Exponent>(number); if (numExp -> getValue("base") -> getName() == "E") { tr1::shared_ptr<AbstractNumber> exp = numExp->getValue("power"); tr1::shared_ptr<AbstractNumber> exp2(new SmartInteger(1)); tr1::shared_ptr<AbstractNumber> me(new E()); tr1::shared_ptr<AbstractNumber> ans2(new Exponent(me, exp -> add(exp2), newSign)); return ans2; } } else if (number->getName() == "Radical") { if (abs(number->getValue("value")->toDouble() - toDouble()) < 0.000001 ) { tr1::shared_ptr<AbstractNumber> one(new SmartInteger(1)); tr1::shared_ptr<AbstractNumber> invertedRoot(new MultExpression(one, number->getValue("root"), '+')); tr1::shared_ptr<AbstractNumber> me(new E()); tr1::shared_ptr<AbstractNumber> output(new Exponent(me, invertedRoot->add(one), newSign)); return output; } else { vector<tr1::shared_ptr<AbstractNumber> > M; M.push_back(number); M.push_back(shared_from_this()); tr1::shared_ptr<AbstractNumber> ans3(new MultExpression(M, '+')); return ans3; } } else if(number->getName() == "MultExpression") { return number->multiply(shared_from_this()); } vector<tr1::shared_ptr<AbstractNumber> > M; M.push_back(number); M.push_back(shared_from_this()); tr1::shared_ptr<AbstractNumber> ans3(new MultExpression(M, '+')); return ans3; }
/// @file unit_tests/genieRoom.cpp /// @brief unit test function for function that implements genieRoom /// /// @param harnessOutput is a reference to an opened file for harness results /// @param harnessError is a reference to an opened file for harness errors /// @param input is the location of the input file that will be utilized /// this is an optional parameter and if not specified will be NULL /// void testFunction(std::ofstream &harnessOutput, std::ofstream &harnessError, char *input = NULL) { bool proper = false; // update return value type to be of expected type // std::string ret_val; std::ofstream inputFile; // Answers that are expected, only one char expected at a time int ansA[] = {0, 0}; vector <int> ans(ansA, ansA + sizeof(ansA) / sizeof(ansA[0])); int ansB[] = {0, 0}; vector <int> ans2(ansB, ansB + sizeof(ansB) / sizeof(ansB[0])); // Parameters to provide function -- one vector per parameter int parA[] = {1, 12}; vector <int> par(parA, parA + sizeof(parA) / sizeof(parA[0])); int parB[] = {1, 12}; vector <int> par2(parB, parB + sizeof(parB) / sizeof(parB[0])); std::string parC[] = {"Pinhead", "Boo"}; vector <std::string> par3(parC, parC + sizeof(parC) / sizeof(parC[0])); // Create input file if warranted // Single test case's input per line, cin.ignore '\n' utilized after test vector <std::string> input_contents; if (input != NULL) { // input file contents can always go out as strings input_contents.push_back("e"); // extra inputs should change depending on what sort of valid inputs // are to be expected by the program std::string extra = "a b c d e f g h i j k l m n o p q "; // clear the file before writing, write out input and extra per line inputFile.open(input, ios::out | ios::trunc); for (int i = 0; i < input_contents.size(); i++) { inputFile << input_contents.at(i) << " " << extra << std::endl << std::endl; } inputFile.close(); } // go through every test in the unit test (each test has 1 answer) for (int i=0; i < ans.size(); i++) { // section title for output, script should replace the generic name std::string call = "Calling STUDENT_FUNC_NAME("; call = call + "var1, \"" + par3.at(i) + "\", var2) // initial values "; call = call + "of var1 and var2: "; call = call + convertInt(par.at(i)) + ", " + convertInt(par2.at(i)); try { // output the section title to standard output so it precedes // any function output within standard out for this individual test std::cout << call << std::endl; // call to generic function, script should replace the name STUDENT_FUNC_NAME(par.at(i), par3.at(i), par2.at(i)); // determine if the return value is what is expected proper = ans.at(i) == par.at(i) && ans2.at(i) == par2.at(i); if (!proper) { // tab separation utilized to break up title and items that // should exist in a list below the title // output section title to harness output harnessOutput << call; harnessOutput << "\t"; // output what was expected harnessOutput << "Expected Result: "; harnessOutput << "var1 = " << ans.at(i); harnessOutput << ", var2 = " << ans2.at(i); harnessOutput << "\t"; // output what was returned by the function call harnessOutput << "Received: "; harnessOutput << "var1 = " << par.at(i); harnessOutput << ", var2 = " << par2.at(i); // output the input file contents for this test if warranted if (input != NULL) { harnessOutput << "\t"; harnessOutput << "Input File Conents: "; harnessOutput << input_contents.at(i); } harnessOutput << std::endl; } } catch(out_of_range& oor) { // Catch out of range errors, output section title and what threw // the exception separated by a tab, similar to harnessOutput harnessError << call; harnessError << "\t"; harnessError << "Out of Range exception thrown by: "; harnessError << oor.what() << std::endl; } catch(...) { // Catch all other exceptions, output section title and a simple // statement that an exception was thrown harnessError << call; harnessError << "\t"; harnessError << "exception thrown" << std::endl; } // The next test's input will be after the next newline if (input != NULL) { std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); } } }