コード例 #1
0
        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]);
        }
コード例 #2
0
ファイル: LINQTestJ.cs プロジェクト: yaelkeemink/Minor-net
        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]);
        }
コード例 #3
0
        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]);
        }
コード例 #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]);
        }
コード例 #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]);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: LINQTestJ.cs プロジェクト: yaelkeemink/Minor-net
        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]);
        }
コード例 #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]);
        }
コード例 #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]);
        }
コード例 #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]);
        }
コード例 #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]);
        }