Exemplo n.º 1
0
        public void ProcessBuySell_ShouldNotSelectLowestBuy_WhenAfterBestSell()
        {
            decimal[] sharePrices    = { 1.50m, 2m, 3m, 4m, 3m, 1m, 1.1m };
            decimal   lowestBuyPrice = sharePrices.Min();

            var result = ProcessBuySell.CalculateBestProfit(sharePrices);

            Assert.AreNotEqual(result.SellPrice, lowestBuyPrice);
        }
Exemplo n.º 2
0
        public void ProcessBuySell_ShouldShowZeroes_WhenNoProfitsCalculated()
        {
            decimal[] sharePrices  = { 5.50m, 5m, 4m, 3m, 2m, 1m };
            decimal   expectedZero = 0;

            var result = ProcessBuySell.CalculateBestProfit(sharePrices);

            Assert.AreEqual(result.BuyPrice, expectedZero);
            Assert.AreEqual(result.SellPrice, expectedZero);
        }
Exemplo n.º 3
0
        public void ProcessBuySell_ShouldCalculateResult_WhenValuesSupplied()
        {
            decimal[] sharePrices  = { 1.50m, 2m, 3m, 4m, 3m, 1m, 1.1m };
            decimal   expectedBuy  = 1.5m;
            decimal   expectedSell = 4m;

            int expectedBuyDay  = 1;
            int expectedSellDay = 4;

            var result = ProcessBuySell.CalculateBestProfit(sharePrices);

            Assert.AreEqual(result.BuyPrice, expectedBuy);
            Assert.AreEqual(result.SellPrice, expectedSell);
            Assert.AreEqual(result.BuyDay, expectedBuyDay);
            Assert.AreEqual(result.SellDay, expectedSellDay);
        }
Exemplo n.º 4
0
        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            lblResults.Text = string.Empty;

            try
            {
                decimal[] pricesLastMonth = ReadInputFile.ReadPrices(lblSelectedFile.Text).ToArray();

                var results = ProcessBuySell.CalculateBestProfit(pricesLastMonth);

                lblResults.Text = $"{results.BuyDay}({results.BuyPrice}),{results.SellDay}({results.SellPrice})";
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Your entry was not valid: {ex.Message}");
            }
        }