public void Find_Product_WrongIndex_ShouldThrow() { //Arrange IProductStock stock = new Instock(); Product product = new Product("Salam", 2.50, 50); //Act stock.Add(product); //Assert Assert.Throws <IndexOutOfRangeException>(() => stock.Find(-5) , "Accessing index -5 should not be possible"); Assert.Throws <IndexOutOfRangeException>(() => stock.Find(1) , "Accessing index 1 when 1 element present should not be possile"); }
public void FindAtIndex_On_100_000_Elements_ShouldWorkFast() { // Arrange IProductStock stock = new Instock(); const int count = 100000; List <Product> people = new List <Product>(); for (int i = 0; i < count; i++) { people.Add(new Product(i.ToString(), i, i)); stock.Add(people[i]); } // Act Stopwatch sw = Stopwatch.StartNew(); Random rand = new Random(); for (int i = 0; i < 50000; i++) { int rnd = rand.Next(0, count - 1); Assert.AreEqual(people[rnd], stock.Find(rnd)); } // Assert sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 200); }
public void Find_Product_On_ExistingProduct_ShouldWorkCorrectly() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("Balsam", 5.3, 12); Product product2 = new Product("Korab", 12.6, 1255); Product product3 = new Product("Meduza", 53.1, 55); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); //Assert Assert.AreSame(product3, stock.Find(2)); Assert.AreNotSame(product1, stock.Find(1)); Assert.AreSame(product1, stock.Find(0)); }
public void Add_MultipleElements_ShouldWorkCorrectly() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("Salam", 2.50, 50); Product product2 = new Product("Bekon", 2.65, 43); Product product3 = new Product("Mayoneza", 1.30, 13); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); //Assert Assert.AreEqual(product1, stock.Find(0)); Assert.AreEqual(product2, stock.Find(1)); Assert.AreEqual(product3, stock.Find(2)); }
public void Add_Single_Product_ShouldBeAt_0_Index() { //Arrange IProductStock stock = new Instock(); Product product = new Product("Salam", 2.50, 50); //Act stock.Add(product); //Assert Assert.AreEqual(product, stock.Find(0), "Added item should be on index 0"); }
public static void Main() { var stock = new Instock(); var productA = new Product("A", 50, 100); var productC = new Product("C", 100, 10); var productB = new Product("B", 50, 3); stock.Add(productA); stock.Add(productC); stock.Add(productB); var contains = stock.Contains(productC); var find = stock.Find(0); stock.ChangeQuantity("C", -10); var byLabel = stock.FindByLabel("C"); var firstCountByAscLabel = stock.FindFirstByAlphabeticalOrder(2); var byPriceRange = stock.FindAllInRange(30, 500); var byPrice = stock.FindAllByPrice(50); var firstMostExpensive = stock.FindFirstMostExpensiveProducts(2); }