public void InterestCalculator_Incorrect(int interestPercent, double principleAmount, int yearAmount)
        {
            var calculator = new InterestCalculator();

            calculator.SetInterestPercent(interestPercent);
            var result = calculator.Calculate(principleAmount, yearAmount);
        }
        public void InterestCalculator_Correct(int interestPercent, double principleAmount, int yearAmount, string expected)
        {
            var calculator = new InterestCalculator();

            calculator.SetInterestPercent(interestPercent);
            var result = calculator.Calculate(principleAmount, yearAmount);

            var expectedResult = expected.Split(',').Select(it => double.Parse(it));

            result.Should().BeEquivalentTo(expectedResult);
        }
        //[DataRow("4999.99", "74.99")]
        public void CalculateThreePercentInterest(string bankBalance, string interestToBePaid)
        {
            // Arrange.
            var bankBalanceAsDecimal      = decimal.Parse(bankBalance);
            var interestToBePaidAsDecimal = decimal.Parse(interestToBePaid);
            var InterestCalculator        = new InterestCalculator();

            // Act.
            var interestPaid = InterestCalculator.Calculate(bankBalanceAsDecimal);

            // Assert.
            Assert.AreEqual(interestToBePaidAsDecimal, interestPaid);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Hello! Please enter your bank balance to see your interest rate: ");
                var input = Console.ReadLine();

                decimal parsedInput = 0.00m;

                if (decimal.TryParse(input, out parsedInput))
                {
                    var calculator = new InterestCalculator();
                    var interest   = calculator.Calculate(parsedInput);

                    Console.WriteLine($"Thank you. Your calculated interest is {string.Format("{0:C}", interest)}");
                }
            }
        }
        public void InterestCalculator_Test()
        {
            var interestCalculator = new InterestCalculator();
            var result             = interestCalculator.Calculate(12, 10000, 3);

            var expected = new List <InterestCalculateResult>()
            {
                new InterestCalculateResult {
                    Remaining = 10000, Interest = 1200, Summary = 11200
                },
                new InterestCalculateResult {
                    Remaining = 11200, Interest = 1344, Summary = 12544
                },
                new InterestCalculateResult {
                    Remaining = 12544, Interest = 1505.28, Summary = 14049.28
                }
            };

            result.Should().BeEquivalentTo(expected);
        }
Esempio n. 6
0
        public void Calculate__100000LumpSum_2000MonthlyInvestment_ZeroPercent__CalculatesFirst10YearsCorrectly()
        {
            var interest = _interestCalculator.Calculate(100000m, 2000, 0);

            var firstTenYears = interest.Take(11).ToList();

            Assert.AreEqual(100000m, firstTenYears[0]);
            Assert.AreEqual(124000m, firstTenYears[1]);
            Assert.AreEqual(148000m, firstTenYears[2]);
            Assert.AreEqual(172000m, firstTenYears[3]);
            Assert.AreEqual(196000m, firstTenYears[4]);
            Assert.AreEqual(220000m, firstTenYears[5]);
            Assert.AreEqual(244000m, firstTenYears[6]);
            Assert.AreEqual(268000m, firstTenYears[7]);
            Assert.AreEqual(292000m, firstTenYears[8]);
            Assert.AreEqual(316000m, firstTenYears[9]);
            Assert.AreEqual(340000m, firstTenYears[10]);
        }
 public void CalculatorShouldThrowExceptionIfBalanceIsNegative()
 {
     var InterestCalculator = new InterestCalculator();
     var interestPaid       = InterestCalculator.Calculate(-1);
 }
 public IEnumerable <InterestCalculateResult> Calculate(double amount, int years)
 {
     return(interestCalculator.Calculate(interest, amount, years));
 }
        static void Main(string[] args)
        {
            string[] strings =
            {
                "(){}",
                ")"
            };

            foreach (var s in strings)
            {
                string results = BracketDelimiter.IsBalanced(s) ? "succes" : "niet oké";
                Debug.WriteLine(results);
            }

            var resultTot = PostfixCalculator.Calculate("12 10-2+25*10/");

            Console.WriteLine(resultTot);

            //BracketDelimiter.IsBalanced("(){}");

            //BracketDelimiter.IsBalanced("()");
            //BracketDelimiter.IsBalanced("((");

            //BracketDelimiter.IsBalanced("{()}");
            //BracketDelimiter.IsBalanced("{()");
            //BracketDelimiter.IsBalanced("''");

            ////var resultS =  BracketDelimiter.IsBalanced("<?<??>?>");
            //var resultSS = BracketDelimiter.IsBalanced("for(int i = 0; i< 100; i++){}");

            //Console.WriteLine(resultSS);
            Console.ReadLine();
            return;


            OddNumberPrinter.ExecuteEven(2);
            OddNumberPrinter.ExecuteOdd(3);



            var result = InterestCalculator.Calculate(2, 1, 5000);

            List <string> items = new List <string> {
                "a", "b", "c", "d", "e", "f", "g"
            };

            Permutation.Permutations(items);
            Console.WriteLine(Permutation.GetPermutationCount);

            //Printer.PrintAsc();
            //Console.WriteLine(NaturalCounter.Execute(5));
            //DigitSeperator.Execute(255);
            //Console.WriteLine(DigitCounter.Execute(12345));
            //OddNumberPrinter.Execute(20);
            ItterativeIndex ittIdIndex = new ItterativeIndex();

            int value = ittIdIndex.IndexOf(new int[] { 1, 2, 3, 4, 5 }, 5, 0);


            IsPrime.Execute(37, 37 / 2);
            IsPalindrome.Execute("ABBA");
            Console.WriteLine(
                FactorialCalculator.Execute(8));
            //ForLoopProblem.Problem();

            char startPeg   = 'A';  // start tower in output
            char endPeg     = 'C';  // end tower in output
            char tempPeg    = 'B';  // temporary tower in output
            int  totalDisks = 1200; // number of disks

            //TowersOfHanoi.Solve(totalDisks, startPeg, endPeg, tempPeg);


            int[,] random = new int[, ]
            {
                { 200, 400 },
                { 2000, 4176 },
                { 20000, 40000 },
                { 50000, 50000 }
            };

            //var c = _2DArraySum.GetHighestSum(random);

            var getHighestSummedArray = new _2DArraySumAsClass <int[, ]>();

            Console.WriteLine("Highest value" + getHighestSummedArray.GetHighestSum(random));


            //Create linked list
            LinkedListExercise linkedListExercise = new LinkedListExercise();

            //Add data
            linkedListExercise.Employees.AddLast(new Employee("Bob", 5));
            linkedListExercise.Employees.AddLast(new Employee("Alice", 5000));

            //ShallowCopy with IClonable
            var shallowCopy = linkedListExercise.ShallowCopy();
            //Shallow copy with Collection<T>() ctor
            var shallowCopyCollection = linkedListExercise.ShallowCopyCollection();
            //Deep copy
            var deepCopy = linkedListExercise.DeepCopy();


            //var bucketSort = new BucketSort();
            //bucketSort.Execute(new[] { 8, 2, 122, 1, 99, 3, 4, 2 });

            //BubbleSort bubbleSort = new BubbleSort();
            //var res = bubbleSort.Execute(new int[]{8,2, 122, 1});

            //var x = new Solution3();
            //x.Slow(100);
            //x.Fast(100);

            //var binarySearch = new BinarySearch();
            //var array = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            //int pos = binarySearch.Execute(array, 10);

            //var input = "8,1,6;3,5,7;4,9,2";
            //var array = (from x in input.Split(',', ';') select int.Parse(x)).ToArray();
            //var magic = new MagicSquare();
            //magic.Execute(3);

            //magic.ExecuteCorrect(3);
            //MagicSquare.RunMagicSquare(3);


            //Binary Search recurisve.
            //int[] testArray = { 1,2,3,4,5,6,7,8,9,10,11,12};
            //var length = testArray.Length;
            //var searchFor = 10;

            //Console.WriteLine(BinarySearch.RecursiveV2(searchFor, testArray, 0, length));
            //Console.WriteLine($"Self made {BinarySearch.BinarySearchRecursiveSelf(testArray, 0, length, searchFor)}");


            //Console.WriteLine(
            //    ADS.Core.Lesson_2.Converter.DecimalToBin(10));

            //Console.WriteLine("Bin 2 dec " + ADS.Core.Lesson_2.Converter.Bin2dec(1100));
            //Console.WriteLine(ADS.Core.Lesson_2.Converter.BinToDecimal("10101"));


            //Console.WriteLine(Palindrome.IsPalindrome("racecar"));

            // Console.WriteLine(ReverseString.ExecuteV1("ban"));
            // Console.WriteLine(ReverseString.Execute("ban"));

            // ArrayCombiner arrayCombiner = new ArrayCombiner();
            //var x = arrayCombiner.Execute(new int[] { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 },
            //     new int[] { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 });

            //ArrayListCombiner arrayListCombiner = new ArrayListCombiner();

            // var y = arrayListCombiner.Merge(new List<int> { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 },
            //    new List<int> { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 });


            // Create first polynomial
            var polynomial1 = new Polynomial();

            polynomial1.Add(new Term(1, 2));
            polynomial1.Add(new Term(2, 2));
            polynomial1.Add(new Term(3, 0));


            // Create second polynomial
            var polynomial2 = new Polynomial();

            polynomial2.Add(new Term(-1, 3));
            polynomial2.Add(new Term(1, 1));
            polynomial2.Add(new Term(1, 2));

            Stopwatch x = new Stopwatch();

            x.Start();
            Polynomial polyX        = polynomial1.SumWorking(polynomial2);
            var        termsWorking = polyX.GetAllTerms();

            x.Stop();
            Console.WriteLine(x.ElapsedTicks + "TICKS");
            x.Reset();

            x.Start();

            Polynomial polyOptimized = polynomial1.OptimizedAlgorithm(polynomial2);
            var        optimzedTerms = polyX.GetAllTerms();

            x.Stop();
            Console.WriteLine(x.ElapsedTicks + "TICKS");
            x.Reset();

            // Determine the sum
            Polynomial polynomialSum = polynomial1.Sum(polynomial2);
            var        terms         = polynomialSum.GetAllTerms();

            for (int i = 0; i < polynomialSum.GetAllTerms().Count; i++)
            {
                Console.Write($"{terms[i].toString()}\t");
            }

            //TowersOfHanoi.Solve(64);
            //TowersOfHanoi.TowerHanoi(3);
            //-> coeff = 1 - X^ > ex3
            //2X^3
            //-5^0

            //var c = BinarySearch.binarySearchFloris(new int[] { 1,2,3,4,5,6,7,8,9,10 }, 2);

            Hangman hangman = new Hangman();

            hangman.ChooseWord();

            bool val = true;

            while (val)
            {
                string input = Console.ReadLine();
                hangman.GuessWord(input);

                if (input == "exit")
                {
                    val = false;
                }
            }

            int[] arr1 = new int[] { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 };
            int[] arr2 = new int[] { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 };

            int[] execute = ArrayCombiner.combineArray(arr2, arr1);

            //var intList = new ArrayList();
            //intList[1] as int? = 2;

            var res12 = ArrayListCombiner.Merge(new ArrayList()
            {
                1, 2, 3, 4
            }, new ArrayList()
            {
                1, 2, 3, 4
            });

            int max = MaxRec.Execute(new int[] { 1, 2, 3, 4, 1204 });


            Console.WriteLine();

            //Console.WriteLine(Converter.BinToDecimal("1011"));
            Console.ReadLine();
        }
Esempio n. 10
0
 public IEnumerable <double> Calculate(double principleAmount, int yearAmount) => calculator.Calculate(principleAmount, yearAmount).ToList();