コード例 #1
0
        public void SetSpecialNumbers_WhenSpecialNumberSettersAreCalled()
        {
            // Arrange
            var vm = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(out _);

            // Act
            var testSequence = new[]
            {
                Ca.Nr1, Ca.Nr0, Ca.SetRpa,
                Ca.Nr1, Ca.Nr0, Ca.SetYears,
                Ca.Nr2, Ca.SetInt,
                Ca.Nr1, Ca.Nr5, Ca.Nr0, Ca.Nr0, Ca.Nr0, Ca.Nr0, Ca.SetStart,
                Ca.Nr34, Ca.Nr0, Ca.Alg, Ca.SetRate,
                Ca.Nr1, Ca.Nr0, Ca.Nr0, Ca.Nr0, Ca.Nr0, Ca.SetEnd,
            };

            FinCalcViewModelHelper.ExecuteDummyActions(vm, testSequence);

            // Assert
            vm.RatesPerAnnumNumber.Should().Be(10);
            vm.YearsNumber.Should().Be(10);
            vm.StartNumber.Should().Be(150000);
            vm.InterestNumber.Should().Be(2);
            vm.NominalInterestRateNumber.Should().BeApproximately(1.98, 0.01);
            vm.RateNumber.Should().Be(-340);
            vm.RepaymentRateNumber.Should().BeApproximately(0.28, 0.01);
            vm.EndNumber.Should().Be(10000);
        }
コード例 #2
0
        [InlineData("0,1", new[] { Ca.Dec, Ca.Nr1 })]                         // Decimal
        public void ShowExpectedOutputText_WhenActionsArePerformedAfterCalculationOfEndNumber(string expectedOutputTextAfterAllOperations, Ca[] actions)
        {
            var vm = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(out _);

            this.PerformBasicEndCapitalCalculation(vm);
            FinCalcViewModelHelper.ExecuteDummyActionsAndCheckOutput(actions, expectedOutputTextAfterAllOperations, vm);
        }
コード例 #3
0
        public void E_BookP17()
        {
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(5);
            vm.YearsPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(7);
            vm.InterestPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(0);
            vm.StartPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.EndPressedCommand.Execute(false);
            vm.RatePressedCommand.Execute(false);

            Assert.True(vm.DisplayText == "-255,41");
            Assert.True(Math.Abs(vm.DisplayNumber - -255.41) < this.Tolerance);
            Assert.True(Math.Abs(vm.RateNumber - -255.41) < this.Tolerance);
        }
コード例 #4
0
        public void N_BookP32()
        {
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            vm.DigitPressedCommand.Execute(5);
            vm.DecimalSeparatorPressedCommand.Execute(null);
            vm.DigitPressedCommand.Execute(5);
            vm.InterestPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(1);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.AlgebSignCommand.Execute(null);
            vm.StartPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(5);
            vm.DigitPressedCommand.Execute(5);
            vm.DigitPressedCommand.Execute(0);
            vm.AlgebSignCommand.Execute(null);
            vm.RatePressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(1);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.EndPressedCommand.Execute(false);
            vm.YearsPressedCommand.Execute(false);

            Assert.True(vm.DisplayText == "39,85");
            Assert.True(Math.Abs(vm.DisplayNumber - 39.85) < this.Tolerance);
            Assert.True(Math.Abs(vm.YearsNumber - 39.85) < this.Tolerance);
        }
コード例 #5
0
        public void P_BookP21()
        {
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            vm.DigitPressedCommand.Execute(1);
            vm.OperatorPressedCommand.Execute("*");
            vm.YearsPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(5);
            vm.YearsPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(5);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.AlgebSignCommand.Execute(null);
            vm.StartPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(1);
            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.RatePressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(0);
            vm.EndPressedCommand.Execute(false);
            vm.InterestPressedCommand.Execute(false);

            Assert.True(vm.DisplayText == "1,455");
            Assert.True(Math.Abs(vm.DisplayNumber - 1.455) < this.Tolerance);
            Assert.True(Math.Abs(vm.InterestNumber - 1.455) < this.Tolerance);
            Assert.True(Math.Abs(vm.NominalInterestRateNumber - 1.455) < this.Tolerance);
        }
コード例 #6
0
        public void Kn_Manual_LoanQuestion1()
        {
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            vm.DigitPressedCommand.Execute(1);
            vm.DigitPressedCommand.Execute(2);
            vm.OperatorPressedCommand.Execute("*");
            vm.YearsPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(1);
            vm.DigitPressedCommand.Execute(0);
            vm.YearsPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(4);
            vm.OperatorPressedCommand.Execute("*");
            vm.InterestPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(1);
            vm.DigitPressedCommand.Execute(5);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.StartPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(2);
            vm.OperatorPressedCommand.Execute("*");
            vm.RatePressedCommand.Execute(false);
            vm.EndPressedCommand.Execute(false);

            Assert.True(vm.DisplayText == "-113.187,55");
            Assert.True(Math.Abs(vm.DisplayNumber - -113187.5488186329) < this.Tolerance);
            Assert.True(Math.Abs(vm.EndNumber - -113187.5488186329) < this.Tolerance);
        }
コード例 #7
0
        public void CalculateAndDisplayE_GivenAllNeededVariables(bool advance, double m, double n, double p, double k0, double kn, double expectedE)
        {
            // Arrange
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            // Since I am sharing the test data with the plain calculation tests I have to manually adjust this value:
            expectedE *= -1;

            // Act
            if (advance)
            {
                FinCalcViewModelHelper.ExecuteDummyAction(vm, Ca.ToggleAdv);
            }

            FinCalcViewModelHelper.SetFinancialValue(vm, m, CommandWord.SetRatesPerAnnum);
            FinCalcViewModelHelper.SetFinancialValue(vm, n, CommandWord.SetYears);
            FinCalcViewModelHelper.SetFinancialValue(vm, p, CommandWord.SetNominalInterestRate);
            FinCalcViewModelHelper.SetFinancialValue(vm, k0, CommandWord.SetStart);
            FinCalcViewModelHelper.SetFinancialValue(vm, kn, CommandWord.SetEnd);
            vm.RatePressedCommand.Execute(false);

            // Assert
            vm.DisplayNumber.Should().BeApproximately(expectedE, this.Tolerance);
        }
コード例 #8
0
        internal static void ExecuteDummyActionsAndCheckOutput(Ca[] actions, string expectedOutputTextAfterAllOperations, double expectedNumberAfterAllOperations, double precision, FinCalcViewModel vm = null)
        {
            // Arrange
            vm = vm ?? MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(out _);

            // Act
            ExecuteDummyActions(vm, actions);

            // Assert
            vm.DisplayText.Should().Be(expectedOutputTextAfterAllOperations);
            vm.DisplayNumber.Should().BeApproximately(expectedNumberAfterAllOperations, precision);
        }
コード例 #9
0
        public void ActivateSecondFunctionTrigger_WhenActiveOperatorIsAdd()
        {
            // Arrange
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            // Act
            vm.OperatorPressedCommand.Execute("*");

            // Assert
            vm.SecondFunctionTrigger.Should().BeTrue();
        }
コード例 #10
0
        internal static void ExecuteDummyActionsAndCheckOutput(Ca[] actions, string expectedOutputTextAfterAllOperations, FinCalcViewModel vm = null)
        {
            // Arrange
            vm = vm ?? MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(out _);

            // Act
            ExecuteDummyActions(vm, actions);

            // Assert
            if (expectedOutputTextAfterAllOperations == null)
            {
                return;
            }

            vm.DisplayText.Should().Be(expectedOutputTextAfterAllOperations);
        }
コード例 #11
0
        public void SetSpecialNumbers_WhenVmIsCreated()
        {
            // Arrange
            var vm = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(out _);

            // Act
            // Assert
            vm.RatesPerAnnumNumber.Should().NotBe(0);
            vm.YearsNumber.Should().Be(0);
            vm.StartNumber.Should().Be(0);
            vm.InterestNumber.Should().Be(0);
            vm.NominalInterestRateNumber.Should().Be(0);
            vm.RateNumber.Should().Be(0);
            vm.RepaymentRateNumber.Should().Be(0);
            vm.EndNumber.Should().Be(0);
        }
コード例 #12
0
        public void CalculateAndDisplayN_GivenAllNeededVariables(double m, double p, double k0, double e, double kn, double expectedN)
        {
            // Arrange
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            // Act
            FinCalcViewModelHelper.SetFinancialValue(vm, m, CommandWord.SetRatesPerAnnum);
            FinCalcViewModelHelper.SetFinancialValue(vm, p, CommandWord.SetNominalInterestRate);
            FinCalcViewModelHelper.SetFinancialValue(vm, k0, CommandWord.SetStart);
            FinCalcViewModelHelper.SetFinancialValue(vm, e, CommandWord.SetRate);
            FinCalcViewModelHelper.SetFinancialValue(vm, kn, CommandWord.SetEnd);
            vm.YearsPressedCommand.Execute(false);

            // Assert
            vm.DisplayNumber.Should().BeApproximately(expectedN, this.Tolerance);
        }
コード例 #13
0
        public void PercentageCalculationExamples()
        {
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            // 200 * 5
            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.OperatorPressedCommand.Execute("*");
            vm.DigitPressedCommand.Execute(5);
            vm.EndPressedCommand.Execute(false);
            Assert.True(vm.DisplayText == "10,00");
            Assert.True(Math.Abs(vm.DisplayNumber - 10) < this.Tolerance);

            // 200 + 5
            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.OperatorPressedCommand.Execute("+");
            vm.DigitPressedCommand.Execute(5);
            vm.EndPressedCommand.Execute(false);
            Assert.True(vm.DisplayText == "210,00");
            Assert.True(Math.Abs(vm.DisplayNumber - 210) < this.Tolerance);

            // 200 - 5
            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.OperatorPressedCommand.Execute("-");
            vm.DigitPressedCommand.Execute(5);
            vm.EndPressedCommand.Execute(false);
            Assert.True(vm.DisplayText == "190,00");
            Assert.True(Math.Abs(vm.DisplayNumber - 190) < this.Tolerance);

            // 200 / 5 <-- not documented and not very useful
            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.OperatorPressedCommand.Execute("/");
            vm.DigitPressedCommand.Execute(5);
            vm.EndPressedCommand.Execute(false);
            Assert.True(vm.DisplayText == "4.000,00");
            Assert.True(Math.Abs(vm.DisplayNumber - 4000) < this.Tolerance);
        }
コード例 #14
0
        public void InterestSecondFunctionExample()
        {
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            vm.DigitPressedCommand.Execute("4");
            vm.OperatorPressedCommand.Execute("*");
            vm.InterestPressedCommand.Execute(false);
            Assert.True(vm.DisplayText == "4,074");
            Assert.True(Math.Abs(vm.DisplayNumber - 4.074154292) < this.Tolerance);
            Assert.True(Math.Abs(vm.InterestNumber - 4.074154292) < this.Tolerance);

            vm.OperatorPressedCommand.Execute("*");
            vm.InterestPressedCommand.Execute(true);
            Assert.True(vm.DisplayText == "4,000");
            Assert.True(Math.Abs(vm.DisplayNumber - 4) < this.Tolerance);
            Assert.True(Math.Abs(vm.NominalInterestRateNumber - 4) < this.Tolerance);
        }
コード例 #15
0
        public void E_Manual_IncomeDrawDownQuestion2()
        {
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            vm.OperatorPressedCommand.Execute("*");
            vm.StartPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(1);
            vm.OperatorPressedCommand.Execute("*");
            vm.YearsPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(5);
            vm.YearsPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(1);
            vm.DecimalSeparatorPressedCommand.Execute(null);
            vm.DigitPressedCommand.Execute(4);
            vm.DigitPressedCommand.Execute(5);
            vm.DigitPressedCommand.Execute(4);
            vm.DigitPressedCommand.Execute(6);
            vm.DigitPressedCommand.Execute(1);
            vm.DigitPressedCommand.Execute(7);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(9);
            vm.InterestPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(2);
            vm.DigitPressedCommand.Execute(5);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.DigitPressedCommand.Execute(0);
            vm.AlgebSignCommand.Execute(null);
            vm.StartPressedCommand.Execute(false);
            vm.DigitPressedCommand.Execute(0);
            vm.EndPressedCommand.Execute(false);
            vm.RatePressedCommand.Execute(false);

            Assert.True(vm.DisplayText == "11.827,95");
            Assert.True(Math.Abs(vm.DisplayNumber - 11827.95) < this.Tolerance);
            Assert.True(Math.Abs(vm.RateNumber - 11827.95) < this.Tolerance);
        }
コード例 #16
0
        public void ResetInputState_WhenPressedAfterSpecialFunction(Ca[] preOperations, Ca mainOperation, Ca[] postOperations, string expectedOutputTextAfterAllOperations)
        {
            // Arrange
            var mockObjects = MockFactories.GetMockObjects();
            var vm          = MockFactories.FinCalcViewModelWithCalculatorImplementationFactory(mockObjects);

            if (preOperations == null)
            {
                preOperations = System.Array.Empty <Ca>();
            }

            if (postOperations == null)
            {
                postOperations = System.Array.Empty <Ca>();
            }

            // Act
            FinCalcViewModelHelper.ExecuteDummyActions(vm, preOperations.Concat(new[] { mainOperation }).Concat(postOperations).ToArray());

            // Assert
            vm.DisplayText.Should().Be(expectedOutputTextAfterAllOperations);
        }