public void CalculateSimpleMovingAverageFromBasicPriceHistory() { int productId = 2, conditionId = 2; var mockRepository = CreateBasicMockRepository(productId, conditionId); var sut = new PriceHistoryService(mockRepository) as IPriceHistoryService; var results = sut.CreateBasicPriceHistory(productId, conditionId); sut.AddSimpleMovingAverage(results, 5); var smas = results.Select(ph => ph.SMA.HasValue ? Math.Round(ph.SMA.Value, 3) : ph.SMA); smas.AssertSequenceIsEqual(null, null, null, null, 12.694, 12.804, 12.894, 12.812, 13.168, 13.12, 13.21, 13.63, 14.036, 14.48, 13.786, 13.588); }
public void CalculateSimpleMovingAverageWhenIntervalBiggerThanNumberOfPricesDoesntSetSMAs() { var mockRepository = A.Fake<ISoldOutRepository>(); A.CallTo(() => mockRepository.GetSearchResultsByProductID(A<int>.Ignored, A<int>.Ignored, A<bool>.Ignored)).Returns(CreateListOfTwoSearchResults()); var sut = new PriceHistoryService(mockRepository) as IPriceHistoryService; var results = sut.CreateBasicPriceHistory(1, 2); sut.AddSimpleMovingAverage(results, 5); Assert.AreEqual(results.Count, 2); foreach (var result in results) Assert.IsNull(result.SMA); }