public void MinusTest() { math_pack cs = new math_pack(); Assert.AreEqual(1, cs.fce_minus(2, 1), 0, "2 - 1 != 1"); Assert.AreEqual(42, cs.fce_minus(60, 18), 0, "60 - 18 != 42"); Assert.AreEqual(42, cs.fce_minus(20, -22), 0, "20 - (-22) != 42"); Assert.AreEqual(10, cs.fce_minus(-20, -30), 0, "-20 - (-30) != 10"); Assert.AreEqual(-5, cs.fce_minus(10, 15), 0, "10 - 15 != -5"); Assert.AreEqual(1337420, cs.fce_minus(1537420, 200000), 0, "1 537 420 - 200 000 != 1 337 420"); Assert.AreEqual(5.2, cs.fce_minus(8.4, 3.2), EPS, "8.4 - 3.2 != 5.2"); Assert.AreEqual(-5.2, cs.fce_minus(-8.4, -3.2), EPS, "-8.4 - (-3.2) != -5.2"); Assert.IsTrue(Double.IsInfinity(cs.fce_minus(Double.MinValue, Double.MaxValue))); Assert.IsTrue(Double.IsInfinity(cs.fce_minus(Double.MaxValue, -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í } }