public void FindFirstMostExpensiveProducts_Should_Return_CorrectEnumeration() { //Arrange IProductStock stock = new Instock(); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); Product product1 = new Product("SalamShpekov", 3.50, 50); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); //Assert List <Product> expected = new List <Product>() { product1, product2 }; CollectionAssert.AreEqual(expected, stock.FindFirstMostExpensiveProducts(2)); expected = new List <Product>() { product1 }; CollectionAssert.AreEqual(expected, stock.FindFirstMostExpensiveProducts(1)); }
static void Main(string[] args) { var instock = new Instock(); instock.Add(new Product("bob1", 23.1, 2)); instock.Add(new Product("bob2", 23.5, 2)); instock.Add(new Product("bob3", 21.2, 2)); System.Console.WriteLine(string.Join(" - ", instock.FindAllInRange(21.3, 24).Select(a => a.Label))); }
public void FindByLabel_NoExistingProduct_ShouldThrow() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); //Assert Assert.Throws <ArgumentException>(() => stock.FindByLabel("BoroTreti")); }
public void Add_MultipleElements_Should_Increase_Count() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("Getter", 20.5, 15); Product product2 = new Product("OtherPRoduct", 206.1, 67); Product product3 = new Product("50CentPoster", 50, 50); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); //Assert Assert.AreEqual(3, stock.Count, "Count should increase with every item."); }
public void FindAllByQuantity_On_100000_Elements_ShouldWorkFast() { // Arrange IProductStock stock = new Instock(); const int count = 100000; Dictionary <int, List <Product> > products = new Dictionary <int, List <Product> >(); for (int i = 0; i < count; i += 400) { for (int j = 0; j < 400; j++) { Product p = new Product((i + j).ToString(), j, j); if (!products.ContainsKey(j)) { products[j] = new List <Product>(); } stock.Add(p); products[j].Add(p); } } Stopwatch sw = Stopwatch.StartNew(); // Act // Assert for (int i = 0; i < 100; i++) { CollectionAssert.AreEqual(products[i], stock.FindAllByQuantity(i)); } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 100); }
public void ChangeQuantity_100000_OnSameProduct_ShouldWorkFast() { // Arrange IProductStock stock = new Instock(); const int count = 100000; List <Product> products = new List <Product>(100000); for (int i = 0; i < count; i++) { Product p = new Product(i.ToString(), i, i); stock.Add(p); products.Add(p); } // Act & Assert Stopwatch sw = Stopwatch.StartNew(); Random rand = new Random(); for (int i = 0; i < 50000; i++) { int qty = rand.Next(50, 10000); stock.ChangeQuantity(products[576].Label, qty); Assert.AreEqual(products[576].Quantity, qty); } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 200); }
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); }
static void Main(string[] args) { Instock products = new Instock(); var pr1 = new Product("salam", 10, 2); var pr2 = new Product("masla", 10, 1); var pr3 = new Product("bob", 10, 3); products.Add(pr1); products.Add(pr2); products.Add(pr3); var res = products.FindAllByPrice(10); System.Console.WriteLine( ); }
public void Contains_100000_Elements_ShouldExecuteFast() { // Arrange IProductStock stock = new Instock(); const int count = 100000; LinkedList <Product> products = new LinkedList <Product>(); for (int i = 0; i < count; i++) { products.AddLast(new Product(i.ToString(), i, i)); stock.Add(products.Last.Value); } // Act Stopwatch sw = Stopwatch.StartNew(); LinkedListNode <Product> node = products.First; while (node != null) { Assert.True(stock.Contains(node.Value)); node = node.Next; } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 250); }
public void FindAllInPriceRange_OnLargeRange_ShouldWorkFast() { // Arrange IProductStock org = new Instock(); const int count = 100_000; int expected = 0; Random random = new Random(); for (int i = 0; i < count; i++) { int price = random.Next(10, 50000); if (price > 105 && price <= 10000) { expected++; } org.Add(new Product(i.ToString(), price, i)); } Stopwatch sw = Stopwatch.StartNew(); // Act IEnumerable <Product> FindInPriceRange() => org.FindAllInRange(105, 10000); // Assert Assert.AreEqual(expected, FindInPriceRange().Count()); sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 300); }
public void FindByLabel_Shoul_WorkFast_On_100000_Products() { // Arrange IProductStock stock = new Instock(); const int count = 100000; List <KeyValuePair <string, Product> > names = new List <KeyValuePair <string, Product> >(100000); for (int i = 0; i < count; i++) { Product p = new Product(i.ToString(), i, i); stock.Add(p); names.Add(new KeyValuePair <string, Product>(p.Label, p)); } // Act Stopwatch sw = Stopwatch.StartNew(); // Assert for (int i = 0; i < count; i++) { Assert.True(stock.FindByLabel(names[i].Key) == names[i].Value); } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 230); }
public void FindAllByPrice_On100000ElementsWithRandomPrice_ShouldWorkFast() { // Arrange IProductStock stock = new Instock(); const int count = 100_000; List <Product> expected = new List <Product>(); Random random = new Random(); for (int i = 0; i < count; i++) { int price = random.Next(5, 30); Product p = new Product(i.ToString(), price, 25); if (price == 21) { expected.Add(p); } stock.Add(p); } Stopwatch sw = Stopwatch.StartNew(); // Act IEnumerable <Product> FindAllByPrice() => stock.FindAllByPrice(21); // Assert CollectionAssert.AreEqual(expected, FindAllByPrice()); sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 25); }
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 FindFirstMostExpensiveProducts_ShouldReturn_OrderedEnumeration() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); Product product4 = new Product("Ketchup", 1.80, 73); Product product5 = new Product("Jelqzo", 0.70, 20); Product product6 = new Product("Belina", .75, 50); Product product7 = new Product("Sirene", .77, 50); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); stock.Add(product4); stock.Add(product5); stock.Add(product6); stock.Add(product7); //Assert List <Product> expected = new List <Product>() { product1, product2, product4, product3, product7, product6, product5 }; List <Product> actual = stock.FindFirstMostExpensiveProducts(stock.Count).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void Enumerator_ShouldReturn_ProductsInInsertionOrder_After_Adding_Multiple() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); Product product4 = new Product("Ketchup", 1.80, 73); Product product5 = new Product("Jelqzo", 0.70, 20); Product product6 = new Product("Belina", .75, 50); Product product7 = new Product("Sirene", .77, 50); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); stock.Add(product4); stock.Add(product5); stock.Add(product6); stock.Add(product7); //Assert List <Product> expected = new List <Product>() { product1, product2, product3, product4, product5, product6, product7, }; List <Product> actual = stock.Take(stock.Count).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void FindAllByQuantity_On_WrongArgument_ShouldReturnEmpty_Enumeration() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); Product product4 = new Product("Ketchup", 1.80, 73); Product product5 = new Product("Jelqzo", 0.70, 20); Product product6 = new Product("Belina", .75, 50); Product product7 = new Product("Sirene", .77, 50); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); stock.Add(product4); stock.Add(product5); stock.Add(product6); stock.Add(product7); stock.ChangeQuantity("Sirene", 5); stock.ChangeQuantity("SalamShpekov", 5); stock.ChangeQuantity("Belina", 5); //Assert List <Product> expected = new List <Product>(); List <Product> actual = stock.FindAllByQuantity(500).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void ChangeQuantity_On_Multiple_Elements_ShouldWorkCorrectly() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 560); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); Product product4 = new Product("Ketchup", 1.80, 73); Product product5 = new Product("Jelqzo", 0.70, 130); Product product6 = new Product("Belina", .75, 240); Product product7 = new Product("Sirene", .77, 30); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); stock.Add(product4); stock.Add(product5); stock.Add(product6); stock.Add(product7); stock.ChangeQuantity(product4.Label, 50); stock.ChangeQuantity(product7.Label, 50); stock.ChangeQuantity(product3.Label, 50); //Assert List <Product> expected = new List <Product>() { product4, product7, product3 }; List <Product> actual = stock.FindAllByQuantity(50).ToList(); CollectionAssert.AreEqual(expected, actual); }
static void Main(string[] args) { IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 560); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); Product product4 = new Product("Ketchup", 1.80, 73); Product product5 = new Product("Jelqzo", 0.70, 130); Product product6 = new Product("Belina", .75, 240); Product product7 = new Product("Sirene", .77, 30); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); stock.Add(product4); stock.Add(product5); stock.Add(product6); stock.Add(product7); stock.ChangeQuantity(product4.Label, 50); stock.ChangeQuantity(product7.Label, 50); stock.ChangeQuantity(product3.Label, 50); //Assert List <Product> expected = new List <Product>() { product4, product7, product3 }; List <Product> actual = stock.FindAllByQuantity(50).ToList(); ; }
public void FindAllByPriceRange_On_ExistingRange_ShouldReturn_Correct_Enumeration() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); Product product4 = new Product("Ketchup", 1.80, 73); Product product5 = new Product("Jelqzo", 0.70, 20); Product product6 = new Product("Belina", .75, 50); Product product7 = new Product("Sirene", .77, 50); List <Product> expected = new List <Product>() { product7, product6 }; //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); stock.Add(product4); stock.Add(product5); stock.Add(product6); stock.Add(product7); //Assert List <Product> actual = stock.FindAllInRange(0.70, 0.77).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void FindFirstByAlphabeticalOrder_Should_ReturnCorrectEnumeration() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("Abra", 3.50, 50); Product product2 = new Product("Bobar", 2.65, 43); Product product3 = new Product("Caza", 1.30, 13); Product product4 = new Product("Darfield", 1.80, 73); Product product5 = new Product("Eil*", 0.70, 20); Product product6 = new Product("Flen", .75, 50); Product product7 = new Product("Giilqzo", .77, 50); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); stock.Add(product4); stock.Add(product5); stock.Add(product6); stock.Add(product7); //Assert List <Product> expected = new List <Product>() { product1, product2, product3, product4, product5, product6, product7 }; List <Product> actual = stock.FindFirstByAlphabeticalOrder(stock.Count).ToList(); CollectionAssert.AreEqual(expected, actual); }
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 FindByPrice_On_Non_ExistantPrice_ShouldReturn_Empty_Enumeration() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); //Assert List <Product> actual = stock.FindAllByPrice(0.70).ToList(); CollectionAssert.AreEqual(new List <Product>(), actual); }
public void FindFirstMostExpensiveProducts_On_WrongArgumentPassed_ShouldThrow() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); //Assert Assert.AreEqual(3, stock.Count); Assert.Throws <ArgumentException>(() => { stock.FindFirstMostExpensiveProducts(5).First(); }); }
public void FindFirstByAlphabetical_On_WrongArgumentShouldThrow() { //Arrange IProductStock stock = new Instock(); Product product5 = new Product("Jelqzo", 0.70, 20); Product product6 = new Product("Belina", .75, 50); Product product7 = new Product("Sirene", .77, 50); //Act stock.Add(product5); stock.Add(product6); stock.Add(product7); //Assert Assert.Throws <ArgumentException>(() => { stock.FindFirstByAlphabeticalOrder(5).FirstOrDefault(); }); }
public void FindByPrice_UnderFloatingPoint_PrecisionSurcumstances_ShouldNotFail() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); //Assert List <Product> actual = stock.FindAllByPrice(1.2999999).ToList(); CollectionAssert.AreEqual(new List <Product>(), actual); }
public void FindAllByPriceRange_LowerEndExclusive_HigherEndInclusive_ShouldWorkCorrectly() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("Kurban", 2.0, 2); //Act stock.Add(product1); stock.Add(product2); //Assert List <Product> expected = new List <Product>() { product1 }; List <Product> actual = stock.FindAllInRange(2.0, 3.50).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void FindByLabel_Should_Work_Correctly() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); stock.ChangeQuantity("SalamShpekov", 3); //Assert Assert.IsTrue(stock.Contains(product1)); Assert.AreSame(product2, stock.FindByLabel("BekonNov") , "FindByLabel on existing element should return the element itself"); }
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 void ChangeQuantity_On_ExistingProduct_ShouldWorkCorrectly() { //Arrange IProductStock stock = new Instock(); Product product1 = new Product("SalamShpekov", 3.50, 50); Product product2 = new Product("BekonNov", 2.65, 43); Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13); //Act stock.Add(product1); stock.Add(product2); stock.Add(product3); stock.ChangeQuantity("SalamShpekov", 3); int expected = 3; int actual = stock.FindByLabel("SalamShpekov").Quantity; //Assert Assert.AreEqual(3, stock.Count); Assert.AreEqual(expected, actual); }
public void Add_Many_Count_ShouldWork() { // Arrange IProductStock stock = new Instock(); const int count = 100_000; // Act & Assert for (int i = 0; i < count; i++) { Assert.AreEqual(i, stock.Count); stock.Add(new Product(i.ToString(), i, i)); } }