//testovanie MathHead Faktorial public void Function_Fakt() { MathHeadFunctiones mh = new MathHeadFunctiones(); Assert.AreEqual(120, mh.Fact(5)); Assert.AreEqual(1, mh.Fact(1)); Assert.AreEqual(1, mh.Fact(0)); Assert.AreEqual(479001600, mh.Fact(12)); // Doplnit osetrenie ak faqtorial sa == zaporne cislo }
/// <summary> /// Metóda btn_fact_Click, ktorá je volaná pri stlačení tlačidla "x!". Metóda počíta faktorial čísla pomocou metódy Fact() volanej z matematickej knižnice /// Ošetruje chybové stavy, pridá funkciu do histórie a výsledok vypíše do textBoxu výsledku. /// </summary> /// <param name="sender">Objekt, ktorý sa posiela do danej metódy</param> /// <param name="e">Dáta udalosti, ktoré sa posielajú do danej metódy</param> private void btn_fact_Click(object sender, EventArgs e) { MathHead mh = new MathHead(); if (enterPressed == true) { lbl_history.Text = ""; enterPressed = false; } double x; if (Double.TryParse(resultBox.Text, out x)) { if (x < 0) { lbl_history.Text = ""; historyStringValue = 0; historyValue = 0; resultBox.Font = new Font(resultBox.Font.FontFamily, 20); resultBox.Text = "Neplatný vstup"; errorCode = 1; funcPressed = false; operationPressed = false; enterPressed = true; operation = ""; return; } } try { UInt64.Parse(resultBox.Text); } catch (FormatException) { Error(1); return; } catch (OverflowException) { Error(3); return; } switch (operation) { case "+": lbl_history.Text = lbl_history.Text + "fact(" + UInt64.Parse(resultBox.Text) + ")"; resultValue = historyValue + mh.Fact(UInt64.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; case "-": lbl_history.Text = lbl_history.Text + "fact(" + UInt64.Parse(resultBox.Text) + ")"; resultValue = historyValue - mh.Fact(UInt64.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; case "*": lbl_history.Text = lbl_history.Text + "fact(" + UInt64.Parse(resultBox.Text) + ")"; resultValue = historyValue * mh.Fact(UInt64.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; case "/": lbl_history.Text = lbl_history.Text + "fact(" + UInt64.Parse(resultBox.Text) + ")"; resultValue = historyValue / mh.Fact(UInt64.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; default: if (funcPressed == true) { lbl_history.Text = "fact(" + historyString + ")"; } else { lbl_history.Text = lbl_history.Text + "fact(" + UInt64.Parse(resultBox.Text) + ")"; } resultValue = mh.Fact(UInt64.Parse(resultBox.Text)); resultBox.Text = resultValue.ToString(); historyValue = resultValue; break; } if (resultValue == 0) { Error(3); return; } historyString = lbl_history.Text; operationPressed = false; operation = ""; funcPressed = true; NewFont(); maxChar = false; btn_enter.Focus(); }