public void FactorialTest() { math_pack cs = new math_pack(); try { cs.fce_fakt(-4); Assert.Fail("No exception thrown for invalid argument (tried to calculate (-4)!)"); } catch (ArgumentException ex) { Assert.AreEqual("Cannot calculate the factorial of a negative number", ex.Message); } Assert.AreEqual(1, cs.fce_fakt(0), 0, "0! != 1"); Assert.AreEqual(1, cs.fce_fakt(1), 0, "1! != 1"); Assert.AreEqual(2, cs.fce_fakt(2), 0, "2! != 2"); Assert.AreEqual(120, cs.fce_fakt(5), 0, "5! != 120"); Assert.AreEqual(3628800, cs.fce_fakt(10), 0, "10! != 3,628,800"); Assert.IsTrue(Double.IsInfinity(cs.fce_fakt(200))); }
/** * \brief Reakce na kliknutí na tlačítko * \param sender Odesílatel funkce * \param e Argumenty eventu */ private void ButtonClick(object sender, RoutedEventArgs e) { ROVNASE.Focus(); //aby na tlačítko 'ENTER' reagovalo '=' Button clickedButton = sender as Button; //které tlačítko vyvolalo proceduru #if DEBUG Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("BUTTON:\t\t\tZmáčknuta tlačítko \"{0}\"", clickedButton.Name); Console.ResetColor(); #endif if (clickedButton == null) { return; //kontrola "kdyby náhodou" } if ((Keyboard.Modifiers == ModifierKeys.Control) && (clickedButton.Name == "minus")) { NumberNeg(); } else { switch (clickedButton.Name) { #region ísla case "jedna": //1 NumberOutput("1"); break; case "dva": //2 NumberOutput("2"); break; case "tri": //3 NumberOutput("3"); break; case "ctr": //4 NumberOutput("4"); break; case "pet": //5 NumberOutput("5"); break; case "sest": //6 NumberOutput("6"); break; case "sedm": //7 NumberOutput("7"); break; case "osm": //8 NumberOutput("8"); break; case "devet": //9 NumberOutput("9"); break; case "nula": //0 NumberOutput("0"); break; case "tecka": //. if (!(string.IsNullOrEmpty(textOutput.Text)) && PointMode != true) { PointMode = true; if (NumberMode == false) { textOutput.Text = "0,"; NumberMode = true; } else { textOutput.Text += ","; } } break; #endregion ísla #region základní znamínka case "plus": SignInput("+"); InputShow(Example); break; case "minus": SignInput("-"); InputShow(Example); break; case "krat": SignInput("×"); InputShow(Example); break; case "deleno": SignInput("÷"); InputShow(Example); break; #endregion základní znamínka #region pokročilá znamínka case "mocnina": SignInput("^"); InputShow(Example); break; case "odmocnina": SignInput("√"); InputShow(Example); break; case "faktorial": //SignInput("!"); //InputShow(Example); try { if (double.Parse(textOutput.Text) > 170) { throw new ArgumentOutOfRangeException(); } textOutput.Text = M.fce_fakt(double.Parse(textOutput.Text)).ToString(); MadeFakt = true; } 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_fakt": textOutput.Text = "NO NEG FAKT"; break; default: textOutput.Text = "FAKT ERROR"; break; } GotError = true; PointMode = false; ANSWER = "0"; NumberMode = false; Example = string.Empty; ExampleList.Clear(); textInput.Text = "0"; } break; #endregion pokročilá znamínka #region pomocná tlačítka case "zpet": if (!(string.IsNullOrEmpty(textOutput.Text)) && textOutput.Text.Length > 1) { if (textOutput.Text[textOutput.Text.Length - 1] == '.') { PointMode = false; } textOutput.Text = textOutput.Text.Remove(textOutput.Text.Length - 1); } else { textOutput.Text = "0"; } break; case "clean": textOutput.Text = "0"; PointMode = false; break; case "cleanall": Example = string.Empty; ExampleList.Clear(); textOutput.Text = "0"; textInput.Text = "0"; PointMode = false; break; case "switch": ResultSwitch(); break; #endregion pomocná tlačítka #region konečná tlačítka case "ANS": textOutput.Text = ANSWER; break; case "ROVNASE": Example += textOutput.Text; ExampleList.Add(textOutput.Text); InputShow(Example); textOutput.Text = "0"; InputProcess(Example); break; #endregion konečná tlačítka } } }