public void PlusTest() { math_pack cs = new math_pack(); Assert.AreEqual(1, cs.fce_plus(0, 1), 0, "0 + 1 != 1"); Assert.AreEqual(42, cs.fce_plus(39, 3), 0, "39 + 3 != 42"); Assert.AreEqual(9, cs.fce_plus(10, -1), 0, "10 + (-1) != 9"); Assert.AreEqual(9, cs.fce_plus(-1, 10), 0, "-1 + 10 != 9"); Assert.AreEqual(-10, cs.fce_plus(5, -15), 0, "5 + (-15) != -10"); Assert.AreEqual(120569, cs.fce_plus(-50, 120619), 0, "-50 + 120619 != 120569"); Assert.AreEqual(5.2, cs.fce_plus(1.4, 3.8), EPS, "1.4 + 3.8 != 5.2"); Assert.AreEqual(-5.2, cs.fce_plus(-1.4, -3.8), EPS, "-1.4 + (-3.8) != -5.2"); Assert.IsTrue(Double.IsInfinity(cs.fce_plus(Double.MaxValue, Double.MaxValue))); Assert.IsTrue(Double.IsInfinity(cs.fce_plus(Double.MinValue, -Double.MaxValue))); }
/** * \brief Výpočet výsledku * \param input Kontrolní string, kde je celý příklad */ private void InputProcess(string input) { if (string.IsNullOrEmpty(input)) { textInput.Text = "0"; } else { int index = 0; try { #region výpočet while (ExampleList.Count > 1) //výpočet celého příkladu { #if DEBUG Console.WriteLine("//-------------------------"); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("ExampleList.Count = {0}", ExampleList.Count); Console.ForegroundColor = ConsoleColor.Cyan; for (int i = 0; i < ExampleList.Count; i++) { Console.WriteLine("\tExampleList[{0}]\t=\t{1}", i, ExampleList[i]); } Console.ResetColor(); Console.WriteLine("//-------------------------"); #endif //prioritník if (ExampleList.Contains("!")) //pokud stále existuje { index = ExampleList.IndexOf("!"); //nalezení indexu ExampleList[index - 1] = M.fce_fakt(double.Parse(ExampleList[index - 1])).ToString(); //výpočet ExampleList.RemoveAt(index); //smazaní nadbytečného } else if (ExampleList.Contains("√")) //jinak pokud stále existuje { index = ExampleList.IndexOf("√"); //nalezení indexu //if (int.Parse(ExampleList[index - 1]) > 15) throw new ArgumentOutOfRangeException(); ExampleList[index] = M.fce_odmocnina(double.Parse(ExampleList[index + 1]), int.Parse(ExampleList[index - 1]), iter).ToString(); //výpočet ExampleList.RemoveAt(index + 1); //smazání nadbytečného ExampleList.RemoveAt(index - 1); //smazaní nadbytečného } else if (ExampleList.Contains("^")) //pokud stále existuje { index = ExampleList.IndexOf("^"); //nalezení indexu ExampleList[index] = M.fce_mocnina(double.Parse(ExampleList[index - 1]), int.Parse(ExampleList[index + 1])).ToString(); //výpočet ExampleList.RemoveAt(index + 1); //smazání nadbytečného ExampleList.RemoveAt(index - 1); //smazaní nadbytečného } else if (ExampleList.Contains("÷")) //pokud stále existuje { index = ExampleList.IndexOf("÷"); //nalezení indexu ExampleList[index] = M.fce_deleno(double.Parse(ExampleList[index - 1]), double.Parse(ExampleList[index + 1])).ToString(); //výpočet ExampleList.RemoveAt(index + 1); //smazání nadbytečného ExampleList.RemoveAt(index - 1); //smazaní nadbytečného } else if (ExampleList.Contains("×")) //pokud stále existuje { index = ExampleList.IndexOf("×"); //nalezení indexu ExampleList[index] = M.fce_krat(double.Parse(ExampleList[index - 1]), double.Parse(ExampleList[index + 1])).ToString(); //výpočet ExampleList.RemoveAt(index + 1); //smazaní nadbytečného ExampleList.RemoveAt(index - 1); //smazání nadbytečného } else if (ExampleList.Contains("-")) //pokud stále existuje { index = ExampleList.IndexOf("-"); //nalezení indexu ExampleList[index] = M.fce_minus(double.Parse(ExampleList[index - 1]), double.Parse(ExampleList[index + 1])).ToString(); //výpočet ExampleList.RemoveAt(index + 1); //smazaní nadbytečného ExampleList.RemoveAt(index - 1); //smazání nadbytečného } else if (ExampleList.Contains("+")) //pokud stále existuje { index = ExampleList.IndexOf("+"); //nalezení indexu ExampleList[index] = M.fce_plus(double.Parse(ExampleList[index - 1]), double.Parse(ExampleList[index + 1])).ToString(); //výpočet ExampleList.RemoveAt(index + 1); //smazaní nadbytečného ExampleList.RemoveAt(index - 1); //smazání nadbytečného } else { textOutput.Text = "CALC ERROR"; //CHYBA ExampleList.Clear(); //vyčištění Example = string.Empty; //vyčištění InputShow(Example); //vyčištění return; } } #endregion výpočet textOutput.Text = ExampleList[0]; //výpis výsledku ANSWER = ExampleList[0]; //uložení výsledku GotResult = true; //dostal jsem výsledek MadeFakt = false; } catch (Exception ex) { #if DEBUG Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception: {0}", ex.TargetSite.Name); Console.ResetColor(); #endif switch (ex.TargetSite.Name) { case "fce_deleno": textOutput.Text = "DIV BY ZERO"; break; case "fce_odmocnina": textOutput.Text = "BAD ROOT NUMBER"; break; case "StringToNumber": textOutput.Text = "NO DOUBLE EXP"; break; default: textOutput.Text = "CALC ERROR"; break; } NumberMode = false; GotError = true; ANSWER = "0"; textInput.Text = "0"; } Example = string.Empty; //vyčištění ExampleList.Clear(); //vyčištění } }