public void ShortestNameExtensionMethodTest()
        {
            var tree   = BinairytreeTestHelper.CreateTreeWithNames();
            var result = tree.GroupBy(a => a.Count())
                         .OrderBy(name => name.Key)
                         .First()
                         .Where(name => !name.Contains("a"))
                         .ToList();

            Assert.AreEqual("Pim", result[0]);
            Assert.AreEqual("Rob", result[1]);
        }
Exemplo n.º 2
0
        public void TestJWithExtensionMethod()
        {
            var tree   = BinairytreeTestHelper.CreateTreeWithNames();
            var result = tree.Where(name => name.StartsWith("J"))
                         .Select(name => name.Count())
                         .OrderByDescending(name => name)
                         .ToList();

            Assert.AreEqual(8, result[0]);
            Assert.AreEqual(6, result[1]);
            Assert.AreEqual(5, result[2]);
            Assert.AreEqual(5, result[3]);
            Assert.AreEqual(3, result[4]);
        }
        public void ShortestNameComprehensiveMethodTest()
        {
            var tree   = BinairytreeTestHelper.CreateTreeWithNames();
            var sorted = from name in tree
                         group name by name.Count() into nameGroups
                         orderby nameGroups.Key
                         select nameGroups;

            var result = sorted.First()
                         .Where(a => !a.Contains("a"))
                         .ToList();

            Assert.AreEqual("Pim", result[0]);
            Assert.AreEqual("Rob", result[1]);
        }
Exemplo n.º 4
0
        public void AmountOfNamesExtensionMethod()
        {
            var tree = BinairytreeTestHelper.CreateTreeWithNames();

            var result = tree.GroupBy(name => name.Count())
                         .Select(name => name.Count())
                         .ToList();

            Assert.AreEqual(4, result[0]);
            Assert.AreEqual(4, result[1]);
            Assert.AreEqual(1, result[2]);
            Assert.AreEqual(6, result[3]);
            Assert.AreEqual(5, result[4]);
            Assert.AreEqual(3, result[5]);
            Assert.AreEqual(1, result[6]);
        }
Exemplo n.º 5
0
        public void AllNamesWithRJustSmallLettersExtensionMethod()
        {
            var tree   = BinairytreeTestHelper.CreateTreeWithNames();
            var result = tree.Where(name => name.Contains("r"))
                         .ToList();

            Assert.AreEqual("Gert", result[0]);
            Assert.AreEqual("Jeroen", result[1]);
            Assert.AreEqual("Joery", result[2]);
            Assert.AreEqual("Lars", result[3]);
            Assert.AreEqual("Martijn", result[4]);
            Assert.AreEqual("Martin", result[5]);
            Assert.AreEqual("Robert-Jan", result[6]);
            Assert.AreEqual("Rory", result[7]);
            Assert.AreEqual("Wouter", result[8]);
        }
        public void LegeLijstjeTest()
        {
            var tree = BinairytreeTestHelper.CreateTreeWithNames();

            tree.Add("ad");
            var sorted = from name in tree
                         group name by name.Count() into nameGroups
                         orderby nameGroups.Key
                         select nameGroups;

            var result = sorted.First()
                         .Where(a => !a.Contains("a"))
                         .ToList();

            Assert.IsTrue(0 == result.Count);
        }
Exemplo n.º 7
0
        public void TestJWithComprehensive()
        {
            var tree   = BinairytreeTestHelper.CreateTreeWithNames();
            var sorted = from name in tree
                         where name.StartsWith("J")
                         orderby name.Count() descending
                         select name.Count();

            var result = sorted.ToList();

            Assert.AreEqual(8, result[0]);
            Assert.AreEqual(6, result[1]);
            Assert.AreEqual(5, result[2]);
            Assert.AreEqual(5, result[3]);
            Assert.AreEqual(3, result[4]);
        }
Exemplo n.º 8
0
        public void AllNamesWithRJustSmallLettersComprehensionMethod()
        {
            var tree   = BinairytreeTestHelper.CreateTreeWithNames();
            var sorted = from name in tree
                         where name.Contains("r")
                         select name;
            var result = sorted.ToList();

            Assert.AreEqual("Gert", result[0]);
            Assert.AreEqual("Jeroen", result[1]);
            Assert.AreEqual("Joery", result[2]);
            Assert.AreEqual("Lars", result[3]);
            Assert.AreEqual("Martijn", result[4]);
            Assert.AreEqual("Martin", result[5]);
            Assert.AreEqual("Robert-Jan", result[6]);
            Assert.AreEqual("Rory", result[7]);
            Assert.AreEqual("Wouter", result[8]);
        }
Exemplo n.º 9
0
        public void AmountOfNamesComprehensive()
        {
            var tree = BinairytreeTestHelper.CreateTreeWithNames();

            var sorted = from name in tree
                         group name by name.Count()
                         into names
                         select names.Count();

            var result = sorted.ToList();

            Assert.AreEqual(4, result[0]);
            Assert.AreEqual(4, result[1]);
            Assert.AreEqual(1, result[2]);
            Assert.AreEqual(6, result[3]);
            Assert.AreEqual(5, result[4]);
            Assert.AreEqual(3, result[5]);
            Assert.AreEqual(1, result[6]);
        }
Exemplo n.º 10
0
        public void AlleVoorlettersVanNamenMetRExtensionMethod()
        {
            var tree   = BinairytreeTestHelper.CreateTreeWithNames();
            var result = tree.Where(name => name.Contains("R") || name.Contains("r"))
                         .Select(a => a.Substring(0, 1))
                         .ToList();

            Assert.AreEqual("G", result[0]);
            Assert.AreEqual("J", result[1]);
            Assert.AreEqual("J", result[2]);
            Assert.AreEqual("L", result[3]);
            Assert.AreEqual("M", result[4]);
            Assert.AreEqual("M", result[5]);
            Assert.AreEqual("R", result[6]);
            Assert.AreEqual("R", result[7]);
            Assert.AreEqual("R", result[8]);
            Assert.AreEqual("R", result[9]);
            Assert.AreEqual("W", result[10]);
        }
Exemplo n.º 11
0
        public void AlleVoorlettersVanNamenMetRComprehensionMethod()
        {
            var tree   = BinairytreeTestHelper.CreateTreeWithNames();
            var sorted = from name in tree
                         where name.Contains("r") || name.Contains("R")
                         select name.Substring(0, 1);

            var result = sorted.ToList();

            Assert.AreEqual("G", result[0]);
            Assert.AreEqual("J", result[1]);
            Assert.AreEqual("J", result[2]);
            Assert.AreEqual("L", result[3]);
            Assert.AreEqual("M", result[4]);
            Assert.AreEqual("M", result[5]);
            Assert.AreEqual("R", result[6]);
            Assert.AreEqual("R", result[7]);
            Assert.AreEqual("R", result[8]);
            Assert.AreEqual("R", result[9]);
            Assert.AreEqual("W", result[10]);
        }