public static void Test(Assert assert)
        {
            assert.Expect(4);

            // TEST
            int[] numbersA = { 4, 1, 3 };
            int[] numbersB = { 2, 3, 5 };

            var concatNumbers = numbersA.Concat(numbersB);
            assert.DeepEqual(concatNumbers, new[] { 4, 1, 3, 2, 3, 5 }, "Concat() numbers");

            // TEST
            var names = from p in Person.GetPersons()
                        select p.Name;
            var cities = from p in Person.GetPersons()
                         select p.City;
            var concatNames = names.Concat(cities).ToArray();

            assert.DeepEqual(concatNames,
                            new[] { "Frank", "Zeppa", "John", "Billy", "Dora", "Ian", "Mary", "Nemo",
                                    "Edmonton", "Tokyo", "Lisbon", "Paris", "Budapest", "Rome", "Dortmund", "Ocean"},
                            "Concat() two sequences");

            // TEST
            var a = new[] { "a", "b", "z" };
            var b = new[] { "a", "b", "z" };

            assert.Ok(a.SequenceEqual(b), "SequenceEqual() for equal sequences");

            // TEST
            var c = new[] { "a", "b", "z" };
            var d = new[] { "a", "z", "b" };

            assert.Ok(!c.SequenceEqual(d), "SequenceEqual() for not equal sequences");
        }
        public static void Test(Assert assert)
        {
            assert.Expect(2);

            // TEST
            var numbers = (from n in Enumerable.Range(0, 6)
                           select new
                           {
                               Number = n,
                               IsOdd = n % 2 == 1
                           }).ToArray();
            var numbersExpected = new object[] {
                 new { Number = 0, IsOdd = false},
                 new { Number = 1, IsOdd = true},
                 new { Number = 2, IsOdd = false},
                 new { Number = 3, IsOdd = true},
                 new { Number = 4, IsOdd = false},
                 new { Number = 5, IsOdd = true},
                 };

            assert.DeepEqual(numbers, numbersExpected, "Range() 6 items from 0");

            // TEST
            var repeatNumbers = Enumerable.Repeat(-3, 4).ToArray();
            var repeatNumbersExpected = new[] { -3, -3, -3, -3 };

            assert.DeepEqual(repeatNumbers, repeatNumbersExpected, "Repeat() -3 four times");
        }
Exemplo n.º 3
0
        public static void Test(Assert assert)
        {
            assert.Expect(5);

            // TEST
            var numbers = new[] { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
            var filteredNumbers = (from n in numbers where n <= 6 select n).ToArray();
            assert.DeepEqual(filteredNumbers, new[] { 5, 4, 1, 3, 6, 2, 0 }, "Where elements in integer array are below or equal 6");

            // TEST
            var filteredCounts = (from p in Person.GetPersons() where p.Count < 501 select p.Count).ToArray();
            assert.DeepEqual(filteredCounts, new[] {300, 100, 500, 50 }, "Where elements in Person array have Count below 501");

            // TEST
            filteredCounts = (from p in Person.GetPersons() where p.Count < 501 && p.Group == "A" select p.Count).ToArray();
            assert.DeepEqual(filteredCounts, new[] { 300 }, "Where elements in Person array have Count below 501 ang in group 'A'");

            // TEST
            var persons = Person.GetPersons();
            var filteredPersonByCounts = (from p in Person.GetPersons() where p.Count < 501 select p).ToArray();

            assert.DeepEqual(filteredPersonByCounts, new[] { persons[0], persons[1], persons[3], persons[4] },
                "Where elements in Person array have Count below 501. Returns Person instances");

            // TEST
            var filteredPersonByCountAndIndex = persons.Where((p, index) => p.Count < index * 100).ToArray();

            assert.DeepEqual(filteredPersonByCountAndIndex, new[] { persons[4] },
                "Where elements in Person array have Count meet condition (p.Count < index * 100). Returns Person instances");
        }
Exemplo n.º 4
0
        public static void Test(Assert assert)
        {
            assert.Expect(6);

            // TEST
            int[] numbers = new int[] { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
            int i = 0;

            var aQuery = from n in numbers select ++i;
            assert.Equal(i, 0, "Query is not executed until you enumerate over them");

            // TEST
            aQuery.ToList();
            assert.Equal(i, 10, "Query is  executed after you enumerate over them");

            i = 0;

            // TEST
            var bQuery = (from n in numbers select ++i).Max();
            assert.Equal(i, 10, "Max() executes immediately");

            // TEST
            var smallNumbers = from n in numbers where n <= 3 select n;
            var smallerEvenNumbers = from n in smallNumbers where n % 2 == 0 select n;
            assert.DeepEqual(smallerEvenNumbers.ToArray(), new[] { 2, 0 }, "Query in a query");

            // TEST
            numbers.ForEach((x, index) => numbers[index] = -numbers[index]);
            assert.DeepEqual(numbers.ToArray(), new int[] { -5, -4, -1, -3, -9, -8, -6, -7, -2, 0 }, "ForEach()");

            // TEST
            assert.DeepEqual(smallerEvenNumbers.ToArray(), new[] { -4, -8, -6, -2, 0 }, "Second query run on a modified source");
        }
Exemplo n.º 5
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(3);

            var list = new List<int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });

            assert.DeepEqual(list.GetRange(0, 2).ToArray(), new[] { 1, 2 }, "Bridge532 (0, 2)");
            assert.DeepEqual(list.GetRange(1, 2).ToArray(), new[] { 2, 3 }, "Bridge532 (1, 2)");
            assert.DeepEqual(list.GetRange(6, 3).ToArray(), new[] { 7, 8, 9 }, "Bridge532 (6, 3)");
        }
Exemplo n.º 6
0
        public static void Test(Assert assert)
        {
            assert.Expect(4);

            // TEST
            string[] words = { "count", "tree", "mount", "five", "doubt" };
            bool anyOu = words.Any(w => w.Contains("ou"));
            assert.Ok(anyOu, "Any() to return words containing 'ou'");

            // TEST
            int[] oddNumbers = { 3, 7, 9, 5, 247, 1000001 };
            bool onlyOdd = oddNumbers.All(n => n % 2 == 1);
            assert.Ok(onlyOdd, "All() is odd");

            // TEST
            int[] someNumbers = { 2, 3, 7, 9, 5, 247, 1000001 };
            bool notOnlyOdd = !someNumbers.All(n => n % 2 == 1);
            assert.Ok(notOnlyOdd, "All() is not only odd");

            // TEST
            var productGroups =
                    (from p in Person.GetPersons()
                     group p by p.Group into pGroup
                     where pGroup.Any(p => p.Count >= 500)
                     select new { Group = pGroup.Key, Names = pGroup.Select(x => x.Name).ToArray() }).ToArray();

            object[] productGroupsExpected = { new {Group = "C", Names = new[]{"Zeppa", "Billy"}},
                                                 new {Group = "B", Names = new[]{"John", "Dora", "Ian", "Mary"}},
                                                 new {Group = (string)null, Names = new[]{"Nemo"}}
                                             };

            assert.DeepEqual(productGroups, productGroupsExpected, "Any() to return a grouped array of names only for groups having any item with Count > 500");
        }
Exemplo n.º 7
0
        public static void Test(Assert assert)
        {
            // TEST
            int[] a = { 1, 2 };
            int[] b = { 1, 2 };

            var result = a.Intersect(b).ToArray();

            assert.Expect(8);

            // TEST
            int[] numbers = { 1, 2, 3, 3, 1, 5, 4, 2, 3 };

            var uniqueNumbers = numbers.Distinct().ToArray();
            assert.DeepEqual(uniqueNumbers, new[] { 1, 2, 3, 5, 4 }, "Distinct() to remove duplicate elements");

            // TEST
            var distinctPersonGroups = (from p in Person.GetPersons() select p.Group).Distinct().ToArray();
            assert.DeepEqual(distinctPersonGroups, new[] { "A", "C", "B", null }, "Distinct() to remove duplicate Group elements");

            // TEST
            int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
            int[] numbersB = { 1, 3, 5, 7, 8 };

            var uniqueNumbersAB = numbersA.Union(numbersB).ToArray();
            assert.DeepEqual(uniqueNumbersAB, new[] { 0, 2, 4, 5, 6, 8, 9, 1, 3, 7 }, "Union() to get unique number sequence");

            // TEST
            var nameChars = from p in Person.GetPersons() select p.Name[0];
            var cityChars = from p in Person.GetPersons() select p.City[0];
            var uniqueFirstChars = nameChars.Union(cityChars).ToArray();

            assert.DeepEqual(uniqueFirstChars, new[] { (int)'F', (int)'Z', (int)'J', (int)'B', (int)'D', (int)'I', (int)'M', (int)'N',
                                                        (int)'E', (int)'T', (int)'L', (int)'P', (int)'R', (int)'O' },
                "Union to get unique first letters of Name and City");

            // TEST
            var commonNumbersCD = numbersA.Intersect(numbersB).ToArray();
            assert.DeepEqual(commonNumbersCD, new[] { 5, 8 }, "Intersect() to get common number sequence");

            // TEST
            nameChars = from p in Person.GetPersons() select p.Name[0];
            cityChars = from p in Person.GetPersons() select p.City[0];

            var commonFirstChars = nameChars.Intersect(cityChars).ToArray();
            assert.DeepEqual(commonFirstChars, new[] { (int)'B', (int)'D' }, "Intersect() to get common first letters of Name and City");

            // TEST
            var exceptNumbersCD = numbersA.Except(numbersB).ToArray();
            assert.DeepEqual(exceptNumbersCD, new[] { 0, 2, 4, 6, 9 },
                "Except() to get numbers from first sequence and does not contain the second sequence numbers");

            // TEST
            var exceptFirstChars = nameChars.Except(cityChars).ToArray();
            assert.DeepEqual(exceptFirstChars, new[] { (int)'F', (int)'Z', (int)'J', (int)'I', (int)'M', (int)'N' },
                "Except() to get letters from Name sequence and does not contain City letters");
        }
Exemplo n.º 8
0
        private static void TestCreateLabel(Assert assert)
        {
            assert.Expect(6);

            var view = Test.GetView();

            var label = view.CreateLabelElement("someLabel", "Title", "10px", true, HTMLColor.Blue);
            assert.Ok(label != null, "label created");

            view.Root.AppendChild(label);
            var foundLabel = Document.GetElementById<LabelElement>("someLabel");

            assert.Ok(foundLabel != null, "foundLabel");
            assert.DeepEqual(foundLabel.InnerHTML, "Title", "foundLabel.innerHtml = 'Title'");
            assert.DeepEqual(foundLabel.Style.Color, HTMLColor.Blue, "foundLabel.Style.Color = Blue");
            assert.DeepEqual(foundLabel.Style.Margin, "10px", "foundLabel.Style.Margin = '10px'");
            assert.DeepEqual(foundLabel.Style.FontWeight, "bold", "foundLabel.Style.FontWeight = 'bold'");
        }
Exemplo n.º 9
0
        public static void Test(Assert assert)
        {
            assert.Expect(8);

            // TEST
            var words = new string[] { "ab2", "ac", "a", "ab12", "", "ab", "bac", "z" };
            var sortedWords = (from word in words
                               orderby word
                               select word).ToArray();
            assert.DeepEqual(sortedWords, new[] { "", "a", "ab", "ab12", "ab2", "ac", "bac", "z" }, "Order by words");

            // TEST
            var sortedWordsByLength = (from word in words
                                       orderby word.Length
                                       select word).ToArray();
            assert.DeepEqual(sortedWordsByLength, new[] { "", "a", "z", "ac", "ab", "ab2", "bac", "ab12" }, "Order by word length");

            // TEST
            var sortedPersonsByName = (from p in Person.GetPersons()
                                       orderby p.Name
                                       select p.Name).ToArray();
            assert.DeepEqual(sortedPersonsByName, new[] { "Billy", "Dora", "Frank", "Ian", "John", "Mary", "Nemo", "Zeppa" }, "Order by person names");

            // TODO test with System.StringComparison

            // TEST
            var doubles = new double[] { 1.0, -0.7, 2.1, 0.9, 1.4, 2.9 };
            var sortedDoubles = (from d in doubles
                                 orderby d descending
                                 select d).ToArray();
            assert.DeepEqual(sortedDoubles, new[] { 2.9, 2.1, 1.4, 1.0, 0.9, -0.7 }, "Order by descending double");

            // TEST
            var sortedPersonsByCountDesc = (from p in Person.GetPersons()
                                            orderby p.Count descending
                                            select p.Count).ToArray();
            assert.DeepEqual(sortedPersonsByCountDesc, new[] { 3000, 700, 700, 550, 500, 300, 100, 50 }, "Order by person count descending");

            // TEST
            var sortedWordsByLengthAndLetters = (from word in words
                                                 orderby word.Length, word
                                                 select word).ToArray();
            assert.DeepEqual(sortedWordsByLengthAndLetters, new[] { "", "a", "z", "ab", "ac", "ab2", "bac", "ab12" }, "Order by word length then by letters");

            // TEST
            var sortedWordsByLengthAndLettersLambda = words.OrderBy(x => x.Length).ThenByDescending(x => x).ToArray();
            assert.DeepEqual(sortedWordsByLengthAndLettersLambda, new[] { "", "z", "a", "ac", "ab", "bac", "ab2", "ab12" }, "Order by word length then by letters as lambda");

            // TEST
            // var numbers = new[] { 2, 4, 6, 1, 5, 7, 9, 0, 8, 3};
            var numbers = new[] { 2, 4, 6, 1, 5 };
            var numbersReversed = numbers.Reverse<int>().ToArray();
            assert.DeepEqual(numbersReversed, new[] { 5, 1, 6, 4, 2 }, "Reverse() numbers");
        }
Exemplo n.º 10
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(1);

            var s = "ab|abc&ab&abc|de&ef&";

            var r = s.Split('|', '&');
            var expected = new[] { "ab", "abc", "ab", "abc", "de", "ef", "" };

            assert.DeepEqual(r, expected, "#578 Split(params char[] separator)");
        }
Exemplo n.º 11
0
        private static void TestCreatePersonUIElements(Assert assert)
        {
            assert.Expect(2);

            var application = Test.GetApplication();

            application.RenderPerson();

            var lblPersonName = Document.GetElementById<LabelElement>("lblPersonName");
            assert.Ok(lblPersonName != null, "lblPersonName created");
            assert.DeepEqual(lblPersonName.InnerHTML, "Frank", "lblPersonName = 'Frank'");
        }
Exemplo n.º 12
0
        public static void CaughtExceptions(Assert assert)
        {
            assert.Expect(3);

            TryCatchWithCaughtException();
            assert.Ok(true, "Exception catch");

            TryCatchWithCaughtTypedException();
            assert.Ok(true, "Typed exception catch");

            var exceptionMessage = TryCatchWithCaughtArgumentException();
            assert.DeepEqual(exceptionMessage, "catch me", "Typed exception catch with exception message");
        }
Exemplo n.º 13
0
        public static void Bridge329(Assert assert)
        {
            assert.Expect(5);

            DateTime d1;
            var b1 = DateTime.TryParse("2001-01-01", out d1, true);
            assert.Ok(b1, "TryParse parsed '2001 - 01 - 01'");
            assert.Equal(d1.GetUtcFullYear(), 2001, "TryParse works Year");
            assert.Equal(d1.GetUtcMonth(), 1, "TryParse works Month");
            assert.Equal(d1.GetUtcDay(), 1, "TryParse works Day");

            var d2 = DateTime.Parse("2001-01-01", true);
            assert.DeepEqual(d2.ToString(), d1.ToString(), "TryParse And Parse give the same result");
        }
Exemplo n.º 14
0
        // DateTime functions
        public static void DateTimes(Assert assert)
        {
            assert.Expect(2);

            // TEST
            // [#83] by C#
            var str = "2015-03-24T10:48:09.1500225+03:00";
            var bridgeDate = DateTime.Parse(str);
            var bridgeDate1 = new DateTime(str);

            assert.DeepEqual(bridgeDate, bridgeDate1, "[#83] C# bridgeDate = bridgeDate1");

            // TEST
            // [#83] by JavaScript code. This is to check the same issue as above and just to check another way of calling QUnit from JavaScript
            Script.Write<dynamic>(@"var str = ""2015-03-24T10:48:09.1500225+03:00"",
            bridgeDate = Bridge.Date.parse(str),
            jsDate = new Date(Date.parse(str)),
            format = ""yyyy-MM-dd hh:mm:ss"";
            assert.deepEqual(Bridge.Date.format(bridgeDate, format), Bridge.Date.format(jsDate, format), ""[#83] js"")");
        }
Exemplo n.º 15
0
        public static void Test(Assert assert)
        {
            assert.Expect(8);

            // TEST
            var numbers = new[] { 1, 3, 5, 7, 9 };
            var firstTwo = numbers.Take(2).ToArray();
            assert.DeepEqual(firstTwo, new[] { 1, 3 }, "Take() the first two array elements");

            // TEST
            var lastThree = numbers.TakeFromLast(3).ToArray();
            assert.DeepEqual(lastThree, new[] { 5, 7, 9 }, "TakeFromLast() the last three array elements");

            // TEST
            var exceptTwoLast = numbers.TakeExceptLast(2).ToArray();
            assert.DeepEqual(exceptTwoLast, new[] { 1, 3, 5 }, "TakeExceptLast() the first array elements except the last two");

            // TEST
            var takeWhileLessTwo = numbers.TakeWhile((number) => number < 2).ToArray();
            assert.DeepEqual(takeWhileLessTwo, new[] { 1 }, "TakeWhile() less two");

            // TEST
            var takeWhileSome = numbers.TakeWhile((number, index) => number - index <= 4).ToArray();
            assert.DeepEqual(takeWhileSome, new[] { 1, 3, 5, 7 }, "TakeWhile() by value and index");

            // TEST
            var skipThree = numbers.Skip(3).ToArray();
            assert.DeepEqual(skipThree, new[] { 7, 9 }, "Skip() the first three");

            // TEST
            var skipWhileLessNine = numbers.SkipWhile(number => number < 9).ToArray();
            assert.DeepEqual(skipWhileLessNine, new[] { 9 }, "SkipWhile() less then 9");

            // TEST
            var skipWhileSome = numbers.SkipWhile((number, index) => number <= 3 && index < 2).ToArray();
            assert.DeepEqual(skipWhileSome, new[] { 5, 7, 9 }, "SkipWhile() by value and index");
        }
        public static void Test(Assert assert)
        {
            assert.Expect(20);

            int[] numbers = { 2, 2, 3, 5, 5, -1, 2, -1 };
            string[] words = { "one", "two", "three" };
            double[] doubles = { 1.7, 2.3, 1.9, 4.1, 2.9 };

            // TEST
            int uniqueNumbers = numbers.Distinct().Count();
            assert.DeepEqual(uniqueNumbers, 4, "Count() distinct numbers");

            // TEST
            int oddNumbers = numbers.Count(n => n % 2 == 1);
            assert.DeepEqual(oddNumbers, 3, "Count() odd numbers");

            // TEST
            var groupJoin = (from g in Group.GetGroups()
                             join p in Person.GetPersons() on g.Name equals p.Group into pg
                             select new { Group = g.Name, PersonCount = pg.Count() })
                             .ToArray();

            var groupJoinExpected = new object[] {
                        new { Group = "A", PersonCount = 1 },
                        new { Group = "B", PersonCount = 4 },
                        new { Group = "C", PersonCount = 2 },
                        new { Group = "D", PersonCount = 0 }
                 };

            assert.DeepEqual(groupJoin, groupJoinExpected, "Count() within joint collections");

            // TEST
            var grouped = (from p in Person.GetPersons()
                           group p by p.Group into g
                           select new { Group = g.Key, PersonCount = g.Count() })
                            .ToArray();

            var groupedExpected = new object[] {
                        new { Group = "A", PersonCount = 1 },
                        new { Group = "C", PersonCount = 2 },
                        new { Group = "B", PersonCount = 4 },
                        new { Group = (string)null, PersonCount = 1 }
                 };

            assert.DeepEqual(grouped, groupedExpected, "Count() within group");

            // TEST
            double numSum = numbers.Sum();
            assert.DeepEqual(numSum, 17, "Sum() numbers");

            // TEST
            double totalChars = words.Sum(w => w.Length);
            assert.DeepEqual(totalChars, 11, "Sum() total chars");

            // TEST
            var groupedSum = (from p in Person.GetPersons()
                              group p by p.Group into g
                              select new { Group = g.Key, Sum = g.Sum(x => x.Count) })
                           .ToArray();

            var groupedSumExpected = new object[] {
                        new { Group = "A", Sum = 300 },
                        new { Group = "C", Sum = 600 },
                        new { Group = "B", Sum = 2000 },
                        new { Group = (string)null, Sum = 3000 }
                 };

            assert.DeepEqual(groupedSum, groupedSumExpected, "Sum() within group");

            // TEST
            int minNum = numbers.Min();
            assert.DeepEqual(minNum, -1, "Min() number");

            // TEST
            int shortestWordLength = words.Min(w => w.Length);
            assert.DeepEqual(shortestWordLength, 3, "Min() for shortest word");

            // TEST
            var groupedMin = (from p in Person.GetPersons()
                              group p by p.Group into g
                              select new { Group = g.Key, Min = g.Min(x => x.Count) })
                          .ToArray();

            var groupedMinExpected = new object[] {
                        new { Group = "A", Min = 300 },
                        new { Group = "C", Min = 100 },
                        new { Group = "B", Min = 50 },
                        new { Group = (string)null, Min = 3000 }
                 };

            assert.DeepEqual(groupedMin, groupedMinExpected, "Min() within group");

            // TEST
            var groupedMinWithLet = (from p in Person.GetPersons()
                                     group p by p.Group into g
                                     let minCount = g.Min(x => x.Count)
                                     select new { Group = g.Key, Name = g.Where(x => x.Count == minCount).Select(x => x.Name).ToArray() })
                             .ToArray();

            var groupedMinWithLetExpected = new object[] {
                        new { Group = "A", Name = new[]{ "Frank"} },
                        new { Group = "C", Name = new[]{ "Zeppa"} },
                        new { Group = "B", Name = new[]{ "Dora"} },
                        new { Group = (string)null, Name = new[]{ "Nemo"} }
                 };

            assert.DeepEqual(groupedMinWithLet, groupedMinWithLetExpected, "Min() within group with let");

            // TEST
            int maxNum = numbers.Max();
            assert.DeepEqual(maxNum, 5, "Max() number");

            // TEST
            int longestWordLength = words.Max(w => w.Length);
            assert.DeepEqual(longestWordLength, 5, "Max() for longest word");

            // TEST
            var groupedMax = (from p in Person.GetPersons()
                              group p by p.Group into g
                              select new { Group = g.Key, Max = g.Max(x => x.Count) })
                          .ToArray();

            var groupedMaxExpected = new object[] {
                        new { Group = "A", Max = 300 },
                        new { Group = "C", Max = 500 },
                        new { Group = "B", Max = 700 },
                        new { Group = (string)null, Max = 3000 }
                 };

            assert.DeepEqual(groupedMax, groupedMaxExpected, "Max() within group");

            // TEST
            var groupedMaxWithLet = (from p in Person.GetPersons()
                                     group p by p.Group into g
                                     let maxCount = g.Max(x => x.Count)
                                     select new { Group = g.Key, Name = g.Where(x => x.Count == maxCount).Select(x => x.Name).ToArray() })
                             .ToArray();

            var groupedMaxWithLetExpected = new object[] {
                        new { Group = "A", Name = new[]{ "Frank"} },
                        new { Group = "C", Name = new[]{ "Billy"} },
                        new { Group = "B", Name = new[]{ "John", "Mary"} },
                        new { Group = (string)null, Name = new[]{ "Nemo"} }
                 };

            assert.DeepEqual(groupedMaxWithLet, groupedMaxWithLetExpected, "Max() within group with let");

            // TEST
            double averageNum = numbers.Average();
            assert.DeepEqual(averageNum, 2.125, "Average() number");

            // TEST
            var averageWordLengths = new[] { "1", "22", "333", "4444", "55555" };
            double averageWordLength = averageWordLengths.Average(w => w.Length);
            assert.DeepEqual(averageWordLength, 3, "Average() for word lengths");

            // TEST
            var groupedAverage = (from p in Person.GetPersons()
                                  group p by p.Group into g
                                  select new { Group = g.Key, Average = g.Average(x => x.Count) })
                         .ToArray();

            var groupedAverageExpected = new object[] {
                        new { Group = "A", Average = 300 },
                        new { Group = "C", Average = 300 },
                        new { Group = "B", Average = 500 },
                        new { Group = (string)null, Average = 3000 }
                 };

            assert.DeepEqual(groupedAverage, groupedAverageExpected, "Average() within group");

            // TEST
            var doublesForAggregate = new[] { 1.0, 2.0, 3.0, 4.0, 5.0 };
            double product = doublesForAggregate.Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor);
            assert.DeepEqual(product, 120, "Aggregate() within doubles");

            // TEST
            var startBalance = 100.0;
            var attemptedWithdrawals = new[] { 20, 10, 40, 50, 10, 70, 30 };

            var endBalance =
                attemptedWithdrawals.Aggregate(startBalance,
                    (balance, nextWithdrawal) =>
                        ((nextWithdrawal <= balance) ? (balance - nextWithdrawal) : balance));

            assert.DeepEqual(endBalance, 20, "Aggregate() balance");
        }
Exemplo n.º 17
0
        // String functions
        public static void Strings(Assert assert)
        {
            //In PhantomJS some correct tests failed. We will skip them in this environment.
            var isPhantomJs = Utilities.BrowserHelper.IsPhantomJs();

            var expectedCount = isPhantomJs ? 28 : 48;
            assert.Expect(expectedCount);

            // TEST ToLower, ToLowerCase, ToLocaleLowerCase
            var s = "HELLO".ToLower();
            assert.DeepEqual(s, "hello", "'HELLO'.ToLower()");

            s = "HELLO".ToLowerCase();
            assert.DeepEqual(s, "hello", "'HELLO'.ToLowerCase()");

            s = "HELLO".ToLocaleLowerCase();
            assert.DeepEqual(s, "hello", "'HELLO'.ToLocaleLowerCase()");

            // TEST ToUpper, ToUpperCase, ToLocaleUpperCase
            s = "hello".ToUpper();
            assert.DeepEqual(s, "HELLO", "'hello'.ToUpper()");

            s = "hello".ToUpperCase();
            assert.DeepEqual(s, "HELLO", "'hello'.ToUpperCase()");

            s = "HELLO".ToLocaleUpperCase();
            assert.DeepEqual(s, "HELLO", "'hello'.ToLocaleUpperCase()");

            s = "Hello Bridge.NET";
            // TEST String(string) constructor
            assert.DeepEqual(new String(s), s, "new String('" + s + "')");

            // TEST String(char, count) constructor
            assert.DeepEqual(new String('-', 4), "----", "new String('-',4)");

            // TEST IndexOfAny
            char[] anyOf = new char[] { 'x', 'b', 'i' };
            string sAnyOf = "['x','b','i']";

            assert.DeepEqual(s.IndexOfAny(anyOf), 8, "'" + s + "'.IndexOfAny(" + sAnyOf + ")");
            assert.Throws(() => s.IndexOfAny(anyOf, 18, 8), "'" + s + "'.IndexOfAny(" + sAnyOf + ")");
            assert.Throws(() => s.IndexOfAny(null), "'" + s + "'.IndexOfAny(null)");

            s = string.Empty;
            assert.DeepEqual(s.IndexOfAny(anyOf), -1, "String.Empty.IndexOfAny(" + sAnyOf + ")");

            s = null;
            assert.DeepEqual(s.IndexOfAny(anyOf), -1, "null.IndexOfAny(" + sAnyOf + ")");

            // TEST IndexOf
            s = "Hello Bridge.NET";

            assert.DeepEqual(s.IndexOf('e'), 1, "'" + s + "'.IndexOf('e')");
            assert.DeepEqual(s.IndexOf("e."), 11, "'" + s + "'.IndexOf('e.')");
            assert.DeepEqual(s.IndexOf('e', 6, 8), 11, "'" + s + "'.IndexOf('e', 6, 8)");
            assert.Throws(() => s.IndexOf(null), "'" + s + "'.IndexOf(null)");

            if (!isPhantomJs)
            {
                assert.DeepEqual(s.IndexOf("E", 6, 8, StringComparison.CurrentCultureIgnoreCase), 11, "'" + s + "'.IndexOf('E', 6, 8, StringComparison.CurrentCultureIgnoreCase)");
            }

            s = string.Empty;
            assert.DeepEqual(s.IndexOf('e'), -1, "String.Empty.IndexOf('e')");

            s = null;
            assert.DeepEqual(s.IndexOf('e'), -1, "null.IndexOf('e')");

            // TEST Compare
            string s1 = "Animal";
            string s2 = "animal";

            assert.DeepEqual(string.Compare(s1, s2, true), 0, "String.Compare('" + s1 + "', '" + s2 + "', true)");

            if (!isPhantomJs)
            {
                assert.DeepEqual(string.Compare(s1, s2, false), 1, "String.Compare('" + s1 + "', '" + s2 + "', false)");
            }

            if (!isPhantomJs)
            {
                string[] threeIs = new string[3];
                threeIs[0] = "\u0069";
                threeIs[1] = "\u0131";
                threeIs[2] = "\u0049";

                StringComparison[] scValues = {
                StringComparison.CurrentCulture,
                StringComparison.CurrentCultureIgnoreCase,
                StringComparison.InvariantCulture,
                StringComparison.InvariantCultureIgnoreCase,
                StringComparison.Ordinal,
                StringComparison.OrdinalIgnoreCase };

                int[] expected = { -1, -1, 1, -1, 0, 1, -1, -1, 1, -1, 0, 1, -1, 1, 1, 0, 0, 0 };
                int expectedIndex = 0;

                foreach (StringComparison sc in scValues)
                {
                    Test(0, 1, sc, threeIs, expected, expectedIndex++, assert);
                    Test(0, 2, sc, threeIs, expected, expectedIndex++, assert);
                    Test(1, 2, sc, threeIs, expected, expectedIndex++, assert);
                }
            }

            // TEST Contains
            s = "Hello Bridge.NET";

            assert.DeepEqual(s.Contains("Bridge"), true, "'" + s + "'.Contains('Bridge')");
            assert.DeepEqual(s.Contains(String.Empty), true, "'" + s + "'.Contains(String.Empty)");
            assert.DeepEqual(String.Empty.Contains("Bridge"), false, "String.Empty.Contains('Bridge')");
            assert.Throws(() => s.Contains(null), "null.Contains('Bridge')");

            // TEST Concat
            s = string.Concat(s, "2", "3", "4");
            assert.DeepEqual(s, "Hello Bridge.NET234", "string.Concat()");

            s = string.Concat(null,true,3,false);
            assert.DeepEqual(s, "true3false", "string.Concat()");

            s = string.Concat(new string[] { "1", "2", "3", "4", "5" });
            assert.DeepEqual(s, "12345", "string.Concat()");

            s = string.Concat(new object[] { 1, null, 2, null, 3 });
            assert.DeepEqual(s, "123", "string.Concat()");
        }
Exemplo n.º 18
0
 protected static void Test(int x,
                             int y,
                             StringComparison comparison,
                             string[] testI,
                             int[] expected,
                             int expectedIndex,
                             Assert assert)
 {
     int cmpValue = 0;
     cmpValue = String.Compare(testI[x], testI[y], comparison);
     assert.DeepEqual(cmpValue, expected[expectedIndex], "String.Compare('" + testI[x] + "', '" + testI[y] + "'," + comparison + ")");
 }
Exemplo n.º 19
0
        // StringBuilder functions
        public static void StringBuilders(Assert assert)
        {
            assert.Expect(21);

            // TEST constructors
            StringBuilder sb = new StringBuilder();
            var sb1 = new StringBuilder(128);
            assert.DeepEqual(sb.ToString(), string.Empty, "StringBuilder() .ctor");
            assert.DeepEqual(sb.ToString(), sb1.ToString(), "StringBuilder(capacity) .ctor");

            sb = new StringBuilder("foo");
            sb1 = new StringBuilder("foo", 2);
            assert.DeepEqual(sb.ToString(), "foo", "StringBuilder(string) .ctor");
            assert.DeepEqual(sb.ToString(), sb1.ToString(), "StringBuilder(string, capacity) .ctor");

            sb = new StringBuilder("foo bar", 4, 3);
            assert.DeepEqual(sb.ToString(), "bar", "StringBuilder(string) .ctor");

            // TEST properties

            // Capacity
            sb = new StringBuilder(128);
            assert.DeepEqual(sb.Capacity, 128, ".Capacity");
            sb = new StringBuilder("foo", 2);
            assert.DeepEqual(sb.Capacity, 16, ".Capacity");
            sb.Capacity = 10;
            assert.DeepEqual(sb.Capacity, 10, ".Capacity");

            // Length
            assert.DeepEqual(sb.Length, "foo".Length, ".Length");

            // TEST methods

            // Clear
            sb.Clear();
            assert.DeepEqual(sb.Length, 0, ".Clear()");
            assert.DeepEqual(sb.ToString(), string.Empty, ".Clear()");

            // Append
            sb.Append("foo");
            sb.Append("foo bar", 3, 4);
            sb.Append(true);
            sb.Append('=');
            sb.Append(123);
            assert.DeepEqual(sb.ToString(), "foo bartrue=123", ".Append()");

            // AppendLine
            sb.AppendLine();
            assert.DeepEqual(sb.ToString(), "foo bartrue=123\r\n", ".AppendLine()");
            sb.AppendLine("foo bar");
            assert.DeepEqual(sb.ToString(), "foo bartrue=123\r\nfoo bar\r\n", ".AppendLine(string)");

            // AppendFormat
            sb.AppendFormat("({0}, {1})", "foo", false);
            assert.DeepEqual(sb.ToString(), "foo bartrue=123\r\nfoo bar\r\n(foo, false)", ".AppendFormat(format, args)");

            // Insert
            sb.Insert(0, 56.7);
            assert.DeepEqual(sb.ToString(), "56.7foo bartrue=123\r\nfoo bar\r\n(foo, false)", ".Insert()");

            // Remove
            sb.Remove(4, 7);
            assert.DeepEqual(sb.ToString(), "56.7true=123\r\nfoo bar\r\n(foo, false)", ".Remove(start, length)");

            // Replace
            sb.Replace("foo bar", "bar foo");
            assert.DeepEqual(sb.ToString(), "56.7true=123\r\nbar foo\r\n(foo, false)", ".Replace(string, string)");
            sb.Replace('\r', '\n');
            assert.DeepEqual(sb.ToString(), "56.7true=123\n\nbar foo\n\n(foo, false)", ".Replace(char, char)");
            sb.Replace('f', 'F', 23, 6);
            assert.DeepEqual(sb.ToString(), "56.7true=123\n\nbar foo\n\n(Foo, false)", ".Replace(char, char, start, length)");
            sb.Replace("Foo", "foo", 23, 6);
            assert.DeepEqual(sb.ToString(), "56.7true=123\n\nbar foo\n\n(foo, false)", ".Replace(string, string, start, length)");
        }
Exemplo n.º 20
0
        //public class A
        //{
        //    public string Name { get; set; }
        //}
        public static void Test(Assert assert)
        {
            assert.Expect(8);

            // TEST
            var numbers = new[] { 1, 3, 5, 7 };
            var numberPlusOne = (from n in numbers select n + 1).ToArray();
            assert.DeepEqual(numberPlusOne, new[] { 2, 4, 6, 8 }, "A sequence of ints one higher than the numbers[]");

            // TEST
            var persons = Person.GetPersons();
            var names = (from p in persons select p.Name).ToArray();
            assert.DeepEqual(names, new[] { "Frank", "Zeppa", "John", "Billy", "Dora", "Ian", "Mary", "Nemo" }, "Selects names as instance field");

            // TEST
            string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

            var textNumbers = (from n in numbers select strings[n]).ToArray();
            assert.DeepEqual(textNumbers, new[] { "one", "three", "five", "seven" }, "Selects names as items of another array");

            // TEST
            var anonimNames = (from p in persons select new { Name = p.Name }).ToArray();

            object[] anonimNamesToCompare = {
                                                new { Name = "Frank" }, new { Name = "Zeppa" }, new { Name = "John" },
                                                new { Name = "Billy" }, new { Name = "Dora" }, new { Name = "Ian" },
                                                new { Name = "Mary" }, new { Name = "Nemo" } };

            assert.DeepEqual(anonimNames, anonimNamesToCompare, "Selects names as an anonymous type");

            // TEST
            numbers = new[] { 0, 1, 3, 3 };

            var numberssInPlace = numbers
                                    .Select((n, index) => new
                                        {
                                            Number = n,
                                            IsIndex = n == index
                                        })
                                    .ToArray();

            object[] anonimNumbersToCompare = { new { Number = 0, IsIndex = true },
                                                  new { Number = 1, IsIndex = true },
                                                  new { Number = 3, IsIndex = false },
                                                  new { Number = 3, IsIndex = true }
                                              };

            assert.DeepEqual(numberssInPlace, anonimNumbersToCompare, "Selects numbers as an anonymous type");

            // TEST
            var numbersA = new[] { 1, 5, 2 };
            var numbersB = new[] { 3, 4, 2 };
            var simplePairs =
                (from a in numbersA
                 from b in numbersB
                 where a < b
                 select new { A = a, B = b }
                ).ToArray();

            object[] expectedSimplePairs = { new { A = 1, B = 3 }, new { A = 1, B = 4 }, new { A = 1, B = 2 }, new { A = 2, B = 3 }, new { A = 2, B = 4 } };

            assert.DeepEqual(simplePairs, expectedSimplePairs, "Join two numeric arrays with one where clause");

            // TEST
            numbersA = new[] { 1, 5, 2, 4, 3 };
            numbersB = new[] { 3, 4, 2, 5, 1 };

            var pairs =
                (from a in numbersA
                where a > 1
                from b in numbersB
                where b < 4 && a > b
                select new { Sum = a + b }
                ).ToArray();

            object[] expectedPairs = { new { Sum = 8}, new { Sum = 7}, new { Sum = 6}, new { Sum = 3},
                                     new { Sum = 7}, new { Sum = 6}, new { Sum = 5},
                                     new { Sum = 5}, new { Sum = 4},};

            assert.DeepEqual(pairs, expectedPairs, "Join two numeric arrays with two where clauses");

            // TEST
            numbersA = new[] { 1, 5, 2, 4, 3 };
            numbersB = new[] { 3, 4, 2, 5, 1 };

            var manyNumbers = numbersA
                .SelectMany((a, aIndex) => numbersB.Where(b => a == b && b > aIndex).Select(b => new { A = a, B = b, I = aIndex }))
                .ToArray();

            object[] expectedManyNumbers = { new { A = 1, B = 1, I = 0 },
                                           new { A = 5, B = 5, I = 1 },
                                           new { A = 4, B = 4, I = 3 }};

            assert.DeepEqual(manyNumbers, expectedManyNumbers, "SelectMany() two number arrays");
        }
Exemplo n.º 21
0
        // Check instance methods and constructors
        public static void TestInstanceConstructorsAndMethods(Assert assert)
        {
            assert.Expect(18);

            // Check parameterless constructor
            var a = new Point();

            assert.DeepEqual(a.x, 0, "x 0");
            assert.DeepEqual(a.y, 0, "y 0");

            var r = new Rectangle();

            assert.DeepEqual(r.l.x, 0, "r.l.x 0");
            assert.DeepEqual(r.l.y, 0, "r.l.y 0");
            assert.DeepEqual(r.t.x, 0, "r.t.x 0");
            assert.DeepEqual(r.t.y, 0, "r.t.y 0");

            r = new Rectangle(10, 20);

            assert.DeepEqual(r.l.x, 10, "r.l.x 10");
            assert.DeepEqual(r.l.y, 20, "r.l.y 20");
            assert.DeepEqual(r.t.x, 0, "r.t.x 0");
            assert.DeepEqual(r.t.y, 0, "r.t.y 0");

            r = new Rectangle(30, 40, 50, 60);

            assert.DeepEqual(r.l.x, 30, "r.l.x 30");
            assert.DeepEqual(r.l.y, 40, "r.l.y 40");
            assert.DeepEqual(r.t.x, 50, "r.t.x 50");
            assert.DeepEqual(r.t.y, 60, "r.t.y 60");

            var i = a.Test1();

            assert.DeepEqual(i, 500, "i 500");
            a.x = 300;
            i = a.Test1();
            assert.DeepEqual(i, 800, "i 800");

            a.y = 400;

            var b = new Point()
            {
                x = 5,
                y = 7
            };
            var c = b.Test2(a);

            assert.DeepEqual(c.x, 305, "c.x 305");
            assert.DeepEqual(c.y, 407, "c.y 407");
        }
Exemplo n.º 22
0
        //Check default parameters, method parameters, default values
        public static void TestMethodParameters(Assert assert)
        {
            assert.Expect(16);

            //Check default parameters
            var ra = new ClassA();
            int r = ra.Method5(5);

            assert.DeepEqual(r, 5, "r 5");
            r = ra.Method5(i: 15);
            assert.DeepEqual(r, 15, "r 15");
            r = ra.Method5(5, 6);
            assert.DeepEqual(r, 11, "r 11");
            r = ra.Method5(k: 6);
            assert.DeepEqual(r, -44, "r -44");

            //Check referencing did not change data
            var a = new ClassA();
            var b = a.Method1();
            var c = b.Related;

            a.Method2(b);
            assert.Ok(b != null, "b not null");
            assert.DeepEqual(b.Number, 2, "b Number 2");
            assert.Ok(b.Related != null, "b.Related not null");
            assert.DeepEqual(b.Related.Number, 2, "b.Related Number 2");

            assert.Ok(c != null, "c not null");
            assert.DeepEqual(c.Number, 1, "c Number 1");
            assert.Ok(c.Related == null, "c.Related null");

            //Check value local parameter
            var input = 1;
            var result = a.Method4(input, 4);

            assert.DeepEqual(input, 1, "input 1");
            assert.DeepEqual(result, 5, "result 5");

            // TEST
            //[#86]
            var di = ClassA.GetDefaultInt();
            assert.DeepEqual(di, 0, "di 0");

            // TEST
            //Check  "out parameter"
            //[#85]
            int i;
            var tryResult = ClassA.TryParse("", out i);

            assert.Ok(tryResult, "tryResult");
            assert.DeepEqual(i, 3, "i 3");
        }
Exemplo n.º 23
0
        //Check instance methods and constructors
        public static void TestInstanceConstructorsAndMethods(Assert assert)
        {
            assert.Expect(26);

            //Check parameterless constructor
            var a = new ClassA();

            // TEST
            assert.DeepEqual(a.NumberA, 10, "NumberA 10");
            assert.DeepEqual(a.StringA, "Str", "StringA Str");
            assert.DeepEqual(a.BoolA, true, "BoolA true");
            assert.Ok(a.DoubleA == Double.PositiveInfinity, "DoubleA Double.PositiveInfinity");
            assert.DeepEqual(a.DecimalA, -1, "DecimalA Decimal.MinusOne");
            assert.Ok(a.Data != null, "Data not null");
            assert.DeepEqual(a.Data.Number, 700, "Data.Number 700");

            // TEST
            //Check constructor with parameter
            assert.Throws(TestSet1FailureHelper.TestConstructor1Failure, "Related should not be null", "Related should not be null");

            // TEST
            //Check constructor with parameter
            assert.Throws(TestSet1FailureHelper.TestConstructor2Failure, "Should pass six parameters", "Should pass six parameters");

            a = new ClassA(150, "151", true, 1.53d, 1.54m, new ClassA.Aux1() { Number = 155 });

            assert.DeepEqual(a.NumberA, 150, "NumberA 150");
            assert.DeepEqual(a.StringA, "151", "StringA 151");
            assert.DeepEqual(a.BoolA, true, "BoolA true");
            assert.DeepEqual(a.DoubleA, 1.53, "DoubleA Double.PositiveInfinity");
            assert.DeepEqual(a.DecimalA, 1.54, "DecimalA 154");
            assert.Ok(a.Data != null, "Data not null");
            assert.DeepEqual(a.Data.Number, 155, "Data.Number 155");

            // TEST
            //Check instance methods
            var b = a.Method1();

            assert.Ok(b != null, "b not null");
            assert.DeepEqual(b.Number, 2, "b Number 2");
            assert.Ok(b.Related != null, "b.Related not null");
            assert.DeepEqual(b.Related.Number, 1, "b.Related Number 1");

            a.Data = b;
            assert.DeepEqual(a.Method3(), "2 Has related 1", "Method3 2 Has related 1");
            a.Data = null;
            assert.DeepEqual(a.Method3(), "no data", "Method3 no data");

            // TEST
            //Check [#68]
            var c68 = new Class68();

            assert.DeepEqual(c68.x, 0, "c68.x 0");
            assert.DeepEqual(c68.y, 1, "c68.y 1");

            // TEST
            //Check local vars do not get overridden by fields
            c68.Test();

            assert.DeepEqual(c68.x, 0, "c68.x 0");
            assert.DeepEqual(c68.y, 1, "c68.y 1");
        }
Exemplo n.º 24
0
        // Check static methods and constructor
        public static void TestStaticConstructorsAndMethods(Assert assert)
        {
            assert.Expect(7);

            assert.DeepEqual(Point.StaticInt, 500, "Point.StaticInt 500");
            assert.DeepEqual(Point.StaticString, "Initialized", "Point.StaticString Initialized");
            assert.DeepEqual(Point.StatitIntNotInitialized, 0, "Point.StatitIntNotInitialized 0");
            assert.DeepEqual(Point.StatitStringNotInitialized, null, "Point.StatitStringNotInitialized null");
            assert.DeepEqual(Point.CONST_CHAR, (int)'W', "Point.CONST_CHAR W");

            Point.StatitIntNotInitialized = -1;
            assert.DeepEqual(Point.StatitIntNotInitialized, -1, "Point.StatitIntNotInitialized -1");

            var i = Point.Test3();
            assert.DeepEqual(i, 499, "i 499");
        }
Exemplo n.º 25
0
        // Bridge[#273]
        public static void N273(Assert assert)
        {
            assert.Expect(4);

            // TEST
            var items = new List<int>() { 0, 1, 2, 3, 4 };

            var r = items.Slice(-1).ToArray();
            assert.DeepEqual(r, new[] { 4 }, "Slices start = -1");

            r = items.Slice(1).ToArray();
            assert.DeepEqual(r, new[] { 1, 2, 3, 4 }, "Slices start = 1");

            r = items.Slice(-3, 4).ToArray();
            assert.DeepEqual(r, new[] { 2, 3 }, "Slices start = -3, end = 3");

            r = items.Slice(1, 3).ToArray();
            assert.DeepEqual(r, new[] { 1, 2 }, "Slices start = 1, end = 2");
        }
Exemplo n.º 26
0
        // Bridge[#169]
        public static void N169(Assert assert)
        {
            assert.Expect(2);

            // TEST
            Bridge169.M1();
            assert.DeepEqual(Bridge169.Number, 1, "M1()");

            // TEST
            Bridge169.M2();
            assert.DeepEqual(Bridge169.Number, 2, "M2()");
        }
Exemplo n.º 27
0
        public static void Test(Assert assert)
        {
            assert.Expect(5);

            // TEST
            var persons =
                   (from p in Person.GetPersons()
                    join g in Group.GetGroups() on p.Group equals g.Name
                    select new { Name = p.Name, Limit = g.Limit }).ToArray();

            var personsExpected = new object[] {
                 new { Name = "Frank", Limit = 1000},
                 new { Name = "Zeppa", Limit = 800},
                 new { Name = "John", Limit = 400},
                 new { Name = "Billy", Limit = 800},
                 new { Name = "Dora", Limit = 400},
                 new { Name = "Ian", Limit = 400},
                 new { Name = "Mary", Limit = 400}
                 };

            assert.DeepEqual(persons, personsExpected, "Join Persons and Groups");

            // TEST
            var personsByLambda = Person.GetPersons()
                                    .Join(Group.GetGroups(),
                                          p => p.Group,
                                          g => g.Name,
                                          (p, g) => new { Name = p.Name, Limit = g.Limit })
                                    .ToArray();

            var personsByLambdaExpected = new object[] {
                 new { Name = "Frank", Limit = 1000},
                 new { Name = "Zeppa", Limit = 800},
                 new { Name = "John", Limit = 400},
                 new { Name = "Billy", Limit = 800},
                 new { Name = "Dora", Limit = 400},
                 new { Name = "Ian", Limit = 400},
                 new { Name = "Mary", Limit = 400}
            };

            assert.DeepEqual(personsByLambda, personsByLambdaExpected, "Join Persons and Groups by lambda");

            // TEST
            var groupJoin = (from g in Group.GetGroups()
                             join p in Person.GetPersons() on g.Name equals p.Group into pg
                             select new { Group = g.Name, Persons = pg.Select(x => x.Name).ToArray() })
                             .ToArray();

            var groupJoinExpected = new object[] {
                new { Group = "A", Persons = new [] {"Frank"} },
                new { Group = "B", Persons = new [] {"John", "Dora", "Ian", "Mary"} },
                new { Group = "C", Persons = new [] {"Zeppa", "Billy"} },
                new { Group = "D", Persons = new string [] {} }
            };

            assert.DeepEqual(groupJoin, groupJoinExpected, "Grouped join Persons and Groups");

            // TEST
            var groupJoinWithDefault =
                            (from g in Group.GetGroups()
                             join p in Person.GetPersons() on g.Name equals p.Group into pg
                             from ep in pg.DefaultIfEmpty() // DefaultIfEmpty preserves left-hand elements that have no matches on the right side
                             select new
                             {
                                 GroupName = g.Name,
                                 PersonName = ep != null ? ep.Name : string.Empty,
                             }
                            ).ToArray();

            var groupJoinWithDefaultExpected = new object[] {
                new { GroupName = "A", PersonName = "Frank" },
                new { GroupName = "B", PersonName = "John" },
                new { GroupName = "B", PersonName = "Dora" },
                new { GroupName = "B", PersonName = "Ian" },
                new { GroupName = "B", PersonName = "Mary" },
                new { GroupName = "C", PersonName = "Zeppa" },
                new { GroupName = "C", PersonName = "Billy" },
                new { GroupName = "D", PersonName = string.Empty }
            };

            assert.DeepEqual(groupJoinWithDefault, groupJoinWithDefaultExpected, "Grouped join Persons and Groups with DefaultIfEmpty");

            // TEST
            var groupJoinWithDefaultAndComplexEquals =
                           (from g in Group.GetGroups()
                            join p in Person.GetPersons() on new { Name = g.Name, Digit = 1 } equals new { Name = p.Group, Digit = 1 } into pg
                            from ep in pg.DefaultIfEmpty() // DefaultIfEmpty preserves left-hand elements that have no matches on the right side
                            orderby ep != null ? ep.Name : null descending
                            select new
                            {
                                GroupName = g != null ? g.Name : null,
                                PersonName = ep != null ? ep.Name : null,
                            }
                           ).ToArray();

            var groupJoinWithDefaultAndComplexEqualsExpected = new object[] {
                new { GroupName = "C", PersonName = "Zeppa" },
                new { GroupName = "B", PersonName = "Mary" },
                new { GroupName = "B", PersonName = "John" },
                new { GroupName = "B", PersonName = "Ian" },
                new { GroupName = "A", PersonName = "Frank" },
                new { GroupName = "B", PersonName = "Dora" },
                new { GroupName = "C", PersonName = "Billy" },
                new { GroupName = "D", PersonName = (string)null }
            };

            assert.DeepEqual(groupJoinWithDefaultAndComplexEquals, groupJoinWithDefaultAndComplexEqualsExpected, "Issue #209. Grouped join Persons and Groups with DefaultIfEmpty, complex equals and ordering");
        }
Exemplo n.º 28
0
        //Check static methods and constructor
        public static void TestStaticConstructorsAndMethods(Assert assert)
        {
            assert.Expect(13);

            // TEST
            //Check static fields initialization
            assert.DeepEqual(ClassA.StatitIntNotInitialized, 0, "#74 StatitInt not initialized");
            assert.DeepEqual(ClassA.StatitStringNotInitialized, null, "#74 StatitString not initialized");
            assert.DeepEqual(ClassA.CONST_CHAR, 81, "#74 CONST_CHAR Q");
            assert.DeepEqual(ClassA.CONST_DECIMAL, 3.123456789324324324, "#74 CONST_DECIMAL 3.123456789324324324m");

            // TEST
            //Check static constructor
            assert.DeepEqual(ClassA.StaticInt, -340, "StatitInt initialized");
            assert.DeepEqual(ClassA.StaticString, "Defined string", "StatitString initialized");

            // TEST
            //Check static methods
            var a = ClassA.StaticMethod1(678, "ASD", double.NaN);

            assert.DeepEqual(ClassA.StatitIntNotInitialized, 678, "StatitIntNotInitialized 678");
            assert.DeepEqual(ClassA.StatitStringNotInitialized, "ASD", "ClassA.StatitStringNotInitialized ASD");
            assert.DeepEqual(a.DoubleA, double.NaN, "DoubleA double.NaN");

            a = ClassA.StaticMethod2((object)678, "QWE", 234);
            assert.DeepEqual(ClassA.StatitIntNotInitialized, 1678, "StatitIntNotInitialized 1678");
            assert.DeepEqual(ClassA.StatitStringNotInitialized, "QWE", "ClassA.StatitStringNotInitialized QWE");
            assert.DeepEqual(a.DoubleA, 234, "DoubleA 234");

            assert.Throws(TestSet1FailureHelper.StaticMethod2Failure, "Unable to cast type String to type Bridge.Int", "Cast exception should occur");
        }
Exemplo n.º 29
0
        // Bridge[#272]
        public static void N272(Assert assert)
        {
            assert.Expect(3);

            // TEST
            assert.DeepEqual(Bridge272.Test(1), Bridge272.MyEnum.Abc, "Casted MyEnum.Abc");
            assert.DeepEqual(Bridge272.Test(3), Bridge272.MyEnum.Ghi, "Casted MyEnum.Ghi");
            assert.DeepEqual(Bridge272.Test(4), 4, "Casted MyEnum.Abc");
        }
Exemplo n.º 30
0
        public static void Test(Assert assert)
        {
            assert.Expect(26);

            // TEST
            var persons = Person.GetPersons();
            var person3 = (from p in Person.GetPersons() where p.ID == 3 select p).First();

            assert.DeepEqual(person3, Person.GetPersons()[2], "First() with ID = 3");
            assert.DeepEqual(persons.First(x => x.ID == 3), Person.GetPersons()[2], "First() with ID = 3 by lambda");
            assert.DeepEqual(persons.Where(x => x.ID == 3).First(), Person.GetPersons()[2], "First() with Where() with ID = 3 by lambda");
            assert.DeepEqual(persons.First(x => x.Group == "C"), Person.GetPersons()[1], "First() with Group = 'C' by lambda");
            assert.Throws(TestLinqElementOperators.ThrowExceptionOnFirst1, "First() should throw exception if no element found");
            assert.Throws(TestLinqElementOperators.ThrowExceptionOnFirst2, "First() should throw exception on empty collection");

            // TEST
            assert.DeepEqual(persons.FirstOrDefault(x => x.ID == -1), null, "FirstOrDefault() unexisting element by lambda");
            assert.DeepEqual(persons.Where(x => x.ID == -1).FirstOrDefault(), null, "FirstOrDefault() with Where() unexisting element by lambda");
            assert.DeepEqual(persons.FirstOrDefault(x => x.Name == "Nemo"), persons[7], "FirstOrDefault() with Name = 'Nemo' by lambda");
            assert.DeepEqual(persons.Where(x => x.Name == "Nemo").FirstOrDefault(), persons[7], "FirstOrDefault() with Where() with Name = 'Nemo' by lambda");
            assert.DeepEqual((new object [] { }).FirstOrDefault(), null, "FirstOrDefault() within zero-length array by lambda");

            // TEST
            var lastPerson = (from p in Person.GetPersons() select p).Last();

            assert.DeepEqual(lastPerson, Person.GetPersons()[7], "Last() person");
            assert.DeepEqual(persons.Last(x => x.ID == 4), Person.GetPersons()[3], "Last() with ID = 4 by lambda");
            assert.DeepEqual(persons.Last(x => x.Group == "B"), Person.GetPersons()[6], "Last() with Group = 'B' by lambda");
            assert.Throws(TestLinqElementOperators.ThrowExceptionOnLast1, "Last() should throw exception if no element found");
            assert.Throws(TestLinqElementOperators.ThrowExceptionOnLast2, "Last() should throw exception on empty collection");

            // TEST
            assert.DeepEqual(persons.LastOrDefault(x => x.ID == -1), null, "LastOrDefault() unexisting element by lambda");
            assert.DeepEqual(persons.Where(x => x.ID == -1).LastOrDefault(), null, "LastOrDefault() with Where() unexisting element by lambda");
            assert.DeepEqual(persons.LastOrDefault(x => x.Name == "Nemo"), persons[7], "LastOrDefault() with Name = 'Nemo' by lambda");
            assert.DeepEqual((new object[] { }).LastOrDefault(), null, "LastOrDefault() within zero-length array by lambda");

            // TEST
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
            int elementAt1 = (from n in numbers where n > 5 select n).ElementAt(1);

            assert.DeepEqual(elementAt1, 8, "ElementAt() should return 8");
            assert.Throws(TestLinqElementOperators.ThrowExceptionOnElementAt1, "ElementAt() should throw exception if no element found");
            assert.Throws(TestLinqElementOperators.ThrowExceptionOnElementAt2, "ElementAt() should throw exception on empty collection");

            // TEST
            int elementAt1OrDefault = numbers.ElementAtOrDefault(1);
            assert.DeepEqual(elementAt1OrDefault, 4, "ElementAtOrDefault() should return 4");

            // TEST
            int elementAt2OrDefault = (from n in numbers where n > 5 select n).ElementAtOrDefault(2);
            assert.DeepEqual(elementAt2OrDefault, 6, "ElementAtOrDefault() should return 6");

            // TEST
            int elementAt100OrDefault = (from n in numbers where n > 5 select n).ElementAtOrDefault(100);
            assert.DeepEqual(elementAt100OrDefault, 0, "ElementAtOrDefault() should return 0");
        }