Esempio n. 1
0
        public void BasicFx_Calculate_CallsBasicServiceMax()
        {
            // Arrange
            var svc   = Substitute.ForPartsOf <BasicService>();
            var sb    = new StringBuilder();
            var count = 0;

            svc.When(x => x.Max(Arg.Any <IEnumerable <StockPrice> >()))
            .Do(info => {
                sb.Append(ToString(info.ArgAt <IEnumerable <StockPrice> >(0)));
                count++;
            });
            var fx          = new BasicFx(svc);
            var stockPrices = new[]
            {
                sp(1, 1),
                sp(2, 2),
                sp(3, 3)
            };

            // Act
            fx.Calculate(stockPrices);

            // Assert
            Assert.AreEqual(3, count);  // Gets called for each StockPrice.
            Assert.AreEqual(
                "(2, 2)(3, 3);(3, 3);empty;",
                sb.ToString());
        }
Esempio n. 2
0
        public void BasicFx_Calculate_CallsChooseBestOrder()
        {
            // Arrange
            var svc   = Substitute.ForPartsOf <BasicService>();
            var sb    = new StringBuilder();
            var count = 0;

            svc.When(x => x.ChooseBestOrder(Arg.Any <Order>(), Arg.Any <Order>()))
            .Do(info => {
                sb.Append(ToString(info.ArgAt <Order>(0)));
                sb.Append(ToString(info.ArgAt <Order>(1)));
                sb.Append(';');
                count++;
            });
            var fx          = new BasicFx(svc);
            var stockPrices = new[]
            {
                sp(1, 1),
                sp(2, 2),
                sp(3, 3)
            };

            // Act
            fx.Calculate(stockPrices);

            // Assert
            Assert.AreEqual(2, count);  // Doesn't get called for the last StockPrice.
            Assert.AreEqual(
                "(null)(1,1,3,3);(1,1,3,3)(2,2,3,3);",
                sb.ToString());
        }
Esempio n. 3
0
        public void BasicFx_Calculate_Decending()
        {
            // Arrange
            var fx          = new BasicFx();
            var stockPrices = new[]
            {
                sp(1, 94.35m),
                sp(2, 94.06m),
                sp(3, 93.51m),
                sp(4, 93.50m),  // Buy
                sp(5, 93.50m),  // Sell -- The maximum possible profit is zero.
                sp(6, 93.23m),
                sp(7, 93.06m),
                sp(8, 92.85m),
                sp(9, 92.31m),
                sp(10, 91.99m)
            };

            // Act
            var order = fx.Calculate(stockPrices);

            // Assert
            Assert.IsNotNull(order);
            Assert.AreEqual(sp(4, 93.50m), order.Buy);
            Assert.AreEqual(sp(5, 93.50m), order.Sell);
        }
Esempio n. 4
0
        public void BasicFx_Calculate_ThrowsOnNullStockPrices()
        {
            // Arrange
            var fx = new BasicFx();

            // Act
            fx.Calculate(null);
        }
Esempio n. 5
0
        public void BasicFx_Calculate_ThrowsWhenStockPricesCountLessThanTwo()
        {
            // Arrange
            var fx          = new BasicFx();
            var stockPrices = new[]
            {
                sp(1, 1)
            };

            // Act
            fx.Calculate(stockPrices);
        }
Esempio n. 6
0
        public void BasicFx_Calculate_TwoPotentialBuyDates()
        {
            // Arrange
            var fx          = new BasicFx();
            var stockPrices = new[]
            {
                sp(1, 91.00m),
                sp(2, 90.00m), // Don't buy. Too early.
                sp(3, 90.00m), // Buy
                sp(4, 92.00m),
                sp(5, 95.00m)  // Sell
            };

            // Act
            var order = fx.Calculate(stockPrices);

            // Assert
            Assert.IsNotNull(order);
            Assert.AreEqual(sp(3, 90.00m), order.Buy);
            Assert.AreEqual(sp(5, 95.00m), order.Sell);
        }
Esempio n. 7
0
        public void BasicFx_Calculate_Returns()
        {
            // Arrange
            var fx          = new BasicFx();
            var stockPrices = new[]
            {
                sp(1, 1),
                sp(2, 2),
                sp(3, 3)
            };

            // Act
            var result = fx.Calculate(stockPrices);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(
                sp(1, 1),
                result.Buy);
            Assert.AreEqual(
                sp(3, 3),
                result.Sell);
        }
Esempio n. 8
0
 public void BasicFx_CtorSvc_ThrowsOnNullSvc()
 {
     // Act
     var fx = new BasicFx(null);
 }