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);
    }
Exemplo n.º 2
0
    public void Contains_On_Empty_Collection_ShouldReturnFalse()
    {
        //Arrange
        IProductStock stock = new Instock();

        //Act
        //Assert
        Assert.IsFalse(stock.Contains(new Product("Bakar", 5.5, 15)));
    }
    public void Add_SingleElement_Contains_ShouldReturnTrue()
    {
        //Arrange
        IProductStock stock   = new Instock();
        Product       product = new Product("Pizza", 4.30, 1510);

        //Act
        stock.Add(product);

        //Assert
        var actual = stock.Contains(product);

        Assert.True(actual, "Contains on existing element return true");
    }
    public void Contains_On_Non_ExistingElement_ShouldReturnFalse()
    {
        //Arrange
        IProductStock stock    = new Instock();
        Product       product  = new Product("Pizza", 4.30, 1510);
        Product       product2 = new Product("Rizza", 4.30, 1510);

        //Act
        stock.Add(product);

        //Assert
        var actual = stock.Contains(product2);

        Assert.False(actual, "Contains on non-existing element should return false");
    }
Exemplo n.º 5
0
    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");
    }
Exemplo n.º 6
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);
    }