using NUnit.Framework; using Avalonia; using Avalonia.Controls; using Avalonia.Headless; using calculatorEshkeree; namespace TestCalculatorEshkeree; [TestFixture] public class CalculatorTests { private MainWindow _mainWindow; [OneTimeSetUp] public void GlobalSetup() { AppBuilder.Configure() .UseHeadless(new AvaloniaHeadlessPlatformOptions()) .SetupWithoutStarting(); } [SetUp] public void Setup() { _mainWindow = new MainWindow(); } [Test] public void AddTwoNumbers_ShouldReturnCorrectSum_WhenBothNumbersArePositive() { _mainWindow.OnNumberButtonClick(new Button { Content = 2 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "+" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("5", _mainWindow.DisplayText); } [Test] public void AddTwoNumbers_ShouldReturnCorrectSum_WhenFirstNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = -2 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "+" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("1", _mainWindow.DisplayText); } [Test] public void AddTwoNumbers_ShouldReturnCorrectSum_WhenSecondNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = 2 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "+" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = -3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("-1", _mainWindow.DisplayText); } [Test] public void AddTwoNumbers_ShouldReturnCorrectSum_WhenBothNumbersAreNegative() { _mainWindow.OnNumberButtonClick(new Button { Content = -2 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "+" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = -3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("-5", _mainWindow.DisplayText); } [Test] public void AddTwoNumbers_ShouldReturnCorrectSum_WhenBothNumbersAreZeros() { _mainWindow.OnNumberButtonClick(new Button { Content = 0 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "+" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 0 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("0", _mainWindow.DisplayText); } [Test] public void SubtractTwoNumbers_ShouldReturnCorrectSubtraction_WhenBothNumbersArePositive() { _mainWindow.OnNumberButtonClick(new Button { Content = 5 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "-" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("2", _mainWindow.DisplayText); } [Test] public void SubtractTwoNumbers_ShouldReturnCorrectSum_WhenFirstNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = 5 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "-" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = -3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("8", _mainWindow.DisplayText); } [Test] public void SubtractTwoNumbers_ShouldReturnCorrectSum_WhenSecondNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = -5 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "-" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("-8", _mainWindow.DisplayText); } [Test] public void SubtractTwoNumbers_ShouldReturnCorrectSum_WhenBothNumbersAreNegative() { _mainWindow.OnNumberButtonClick(new Button { Content = -2 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "-" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = -3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("1", _mainWindow.DisplayText); } [Test] public void SubtractTwoNumbers_ShouldReturnCorrectSum_WhenBothNumbersAreZeros() { _mainWindow.OnNumberButtonClick(new Button { Content = 0 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "-" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 0 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("0", _mainWindow.DisplayText); } [Test] public void MultiplyTwoNumbers_ShouldReturnCorrectMultiplication_WhenBothNumbersArePositive() { _mainWindow.OnNumberButtonClick(new Button { Content = 2 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "*" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("6", _mainWindow.DisplayText); } [Test] public void MultiplyTwoNumbers_ShouldReturnCorrectSum_WhenFirstNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = 5 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "*" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = -3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("-15", _mainWindow.DisplayText); } [Test] public void MultiplyTwoNumbers_ShouldReturnCorrectSum_WhenSecondNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = -5 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "*" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("-15", _mainWindow.DisplayText); } [Test] public void MultiplyTwoNumbers_ShouldReturnCorrectSum_WhenBothNumbersAreNegative() { _mainWindow.OnNumberButtonClick(new Button { Content = -2 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "*" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = -3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("6", _mainWindow.DisplayText); } [Test] public void MultiplyTwoNumbers_ShouldReturnCorrectSum_WhenBothNumbersAreZeros() { _mainWindow.OnNumberButtonClick(new Button { Content = 0 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "*" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 0 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("0", _mainWindow.DisplayText); } [Test] public void DivideTwoNumbers_ShouldReturnCorrectDivision_WhenBothNumbersArePositive() { _mainWindow.OnNumberButtonClick(new Button { Content = 6 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "/" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("2", _mainWindow.DisplayText); } [Test] public void DivideTwoNumbers_ShouldReturnCorrectDivision_WhenFirstNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = 6 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "/" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = -3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("-2", _mainWindow.DisplayText); } [Test] public void DivideTwoNumbers_ShouldReturnCorrectDivision_WhenSecondNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = -6 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "/" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("-2", _mainWindow.DisplayText); } [Test] public void DivideTwoNumbers_ShouldReturnCorrectDivision_WhenBothNumbersAreNegative() { _mainWindow.OnNumberButtonClick(new Button { Content = -6 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "/" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = -3 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("2", _mainWindow.DisplayText); } [Test] public void DivideTwoNumbers_ShouldReturnCorrectDivision_WhenBothNumbersAreZeros() { _mainWindow.OnNumberButtonClick(new Button { Content = 0 }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "/" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = 0 }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("err", _mainWindow.DisplayText); } [Test] public void CalculateSinOfNumber_ShouldReturnCorrectResult_WhenNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = "45" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "sin" }, null); double expected = Math.Sin(45 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateSinOfNumber_ShouldReturnCorrectResult_WhenNumberIsNegative() { _mainWindow.OnNumberButtonClick(new Button { Content = "-45" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "sin" }, null); double expected = Math.Sin(-45 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateSinOfNumber_ShouldReturnCorrectResult_WhenNumberIsZero() { _mainWindow.OnNumberButtonClick(new Button { Content = "0" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "sin" }, null); double expected = Math.Sin(0 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateCosOfNumber_ShouldReturnCorrectResult_WhenNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = "45" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "cos" }, null); double expected = Math.Cos(45 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateCosOfNumber_ShouldReturnCorrectResult_WhenNumberIsNegative() { _mainWindow.OnNumberButtonClick(new Button { Content = "-45" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "cos" }, null); double expected = Math.Cos(-45 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateCosOfNumber_ShouldReturnCorrectResult_WhenNumberIsZero() { _mainWindow.OnNumberButtonClick(new Button { Content = "0" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "cos" }, null); double expected = Math.Cos(0 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateTgOfNumber_ShouldReturnCorrectResult_WhenNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = "45" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "tg" }, null); double expected = Math.Tan(45 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateTgOfNumber_ShouldReturnCorrectResult_WhenNumberIsNegative() { _mainWindow.OnNumberButtonClick(new Button { Content = "-45" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "tg" }, null); double expected = Math.Tan(-45 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateTgOfNumber_ShouldReturnCorrectResult_WhenNumberIsZero() { _mainWindow.OnNumberButtonClick(new Button { Content = "0" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "tg" }, null); double expected = Math.Tan(0 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateCtgOfNumber_ShouldReturnCorrectResult_WhenNumberIsPositive() { _mainWindow.OnNumberButtonClick(new Button { Content = "45" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "ctg" }, null); double expected = 1 / Math.Tan(45 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateCtgOfNumber_ShouldReturnCorrectResult_WhenNumberIsNegative() { _mainWindow.OnNumberButtonClick(new Button { Content = "-45" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "ctg" }, null); double expected = 1 / Math.Tan(-45 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void CalculateCtgOfNumber_ShouldReturnCorrectResult_WhenNumberIsZero() { _mainWindow.OnNumberButtonClick(new Button { Content = "0" }, null); _mainWindow.OnOperationButtonClick(new Button { Content = "ctg" }, null); double expected = 1 / Math.Tan(0 * Math.PI / 180); Assert.AreEqual(expected.ToString(), _mainWindow.DisplayText); } [Test] public void ConclusionAllNumbers_ShouldReturnCorrectResult_WhenPressedAllNumbers() { _mainWindow.OnNumberButtonClick(new Button { Content = "1" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "2" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "3" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "4" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "5" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "6" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "7" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "8" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "9" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "0" }, null); Assert.AreEqual("1234567890", _mainWindow.DisplayText); } [Test] public void ConclusionBigResult_ShouldReturnCorrectResult_WhenNumbersAreBig() { _mainWindow.OnNumberButtonClick(new Button { Content = "9" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "9" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "9" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "*" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "9" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "9" }, null); _mainWindow.OnNumberButtonClick(new Button { Content = "9" }, null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); _mainWindow.OnEqualButtonClick(new Button(), null); Assert.AreEqual("998001", _mainWindow.DisplayText); } [Test] public void ClearDisplayText_ShouldReturnClearDisplayText_WhenThreeSymbols() { _mainWindow.OnNumberButtonClick(new Button { Content = "123" }, null); _mainWindow.OnClearButtonClick(new Button(), null); Assert.AreEqual("0", _mainWindow.DisplayText); } [Test] public void ClearDisplayText_ShouldReturnClearDisplayText_WhenFourSymbols() { _mainWindow.OnNumberButtonClick(new Button { Content = "1234" }, null); _mainWindow.OnClearButtonClick(new Button(), null); Assert.AreEqual("0", _mainWindow.DisplayText); } }