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(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");
        }
        public static void TestStatic(Assert assert)
        {
            assert.Expect(16);

            assert.Equal(Static.Foo(1), "Foo(int x)", "Static Foo(int x)");
            assert.Equal(Static.Foo("string"), "Foo(string s)", "Static Foo(string s)");
            assert.Equal(Static.Foo(1.1), "Foo(double d)", "Static Foo(double d)");
            assert.Equal(Static.Foo(1, 2), "Foo(int x, int y)", "Static Foo(int x, int y)");
            assert.Equal(Static.Foo(1, 1.1), "Foo(int x, double y)", "Static Foo(int x, double y)");
            assert.Equal(Static.Foo(1.1, 1), "Foo(double x, int y)", "Static Foo(double x, int y)");

            assert.Equal(Static.FooReturnType(1), 'C', "Static char FooReturnType(int y)");
            assert.Equal(Static.FooReturnType(1.1), "string FooReturnType(double d)", "Static string FooReturnType(double d)");

            assert.Equal(Static.FooOptionalParameters(1), "FooOptionalParameters(int x)", "Static FooOptionalParameters(int x)");
            assert.Equal(Static.FooOptionalParameters(1, 2), "FooOptionalParameters(int x, int y = 5)", "Static FooOptionalParameters(int x, int y = 5)");

            assert.Equal(Static.FooMultipleOptionalParameters(1, 2), "FooMultipleOptionalParameters(int x, int y = 5)", "Static FooMultipleOptionalParameters(int x, int y = 5)");
            assert.Equal(Static.FooMultipleOptionalParameters(1, z: 2), "FooMultipleOptionalParameters(int x, int y = 5, int z = 10)", "Static FooMultipleOptionalParameters(int x, int y = 5, int z = 10)");
            assert.Equal(Static.FooMultipleOptionalParameters(1, 2, 3), "FooMultipleOptionalParameters(int x, int y = 5, int z = 10)", "Static FooMultipleOptionalParameters(int x, int y = 5, int z = 10)");
            assert.Equal(Static.FooMultipleOptionalParameters(1, z: 2, y: 3), "FooMultipleOptionalParameters(int x, int y = 5, int z = 10)", "Static FooMultipleOptionalParameters(int x, int y = 5, int z = 10)");

            assert.Equal(Static.FooNamedArgument(x: 1), "FooNamedArgument(int x)", "Static FooNamedArgument(int x)");
            assert.Equal(Static.FooNamedArgument(d: 1), "FooNamedArgument(double d)", "Static FooNamedArgument(double d)");
        }
        public static void ThrownExceptions(Assert assert)
        {
            assert.Expect(12);

            // #230
            assert.Throws(TryCatchWithNotCaughtTypedException, "catch me", "A.Typed exception is not Caught");
            assert.Ok(IsATry, "A. exception not caught - try section called");
            assert.Ok(!IsACatch, "A. exception not caught - catch section not called");

            // #229
            assert.Throws(TryCatchWithNotCaughtTypedExceptionAndArgument, "catch me", "[#229] B. Typed exception is not Caught; and argument");
            assert.Ok(IsBTry, "[#229] B. exception not caught - try section called");
            assert.Ok(!IsBCatch, "B. exception not caught - catch section not called");

            // #231
            assert.Throws(TryCatchWithRethrow, "catch me", "[#231] C. Rethrow");
            assert.Ok(IsCTry, "C. exception caught and re-thrown - try section called");
            assert.Ok(IsCCatch, "C. exception caught and re-thrown - catch section called");

            assert.Throws(TryCatchWithRethrowEx, new Func<object, bool>((error) =>
            {
                return error.ToString() == "catch me";
            }), "D. Rethrow with parameter");
            assert.Ok(IsDTry, "D. exception caught and re-thrown  - try section called");
            assert.Ok(IsDCatch, "D. exception caught and re-thrown  - catch section called");
        }
Exemple #5
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");
        }
Exemple #6
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(12);

            Func<object> item11 = () => 11;
            assert.Equal(item11.IsNullOrUndefined(), false, "Bridge655 IsNullOrUndefined11");
            assert.Equal(item11(), 11, "Bridge655 item11");

            Func<int, int> item12 = (i) => i;
            assert.Equal(item12.IsNullOrUndefined(), false, "Bridge655 IsNullOrUndefined12");
            assert.Equal(item12(12), 12, "Bridge655 item12");

            Func<object> item21 = () => 21;
            assert.Equal(item21.IsNullOrUndefined(21), false, "Bridge655 IsNullOrUndefined21 false");
            assert.Equal(item21.IsNullOrUndefined(0), true, "Bridge655 IsNullOrUndefined21 true");
            assert.Equal(item21(), 21, "Bridge655 item21");

            Func<int, string, int> item22 = (i, s) => i + s.Length;
            assert.Equal(item22.IsNullOrUndefined("22"), "false", "Bridge655 IsNullOrUndefined22 false");
            assert.Equal(item22.IsNullOrUndefined(string.Empty), "true", "Bridge655 IsNullOrUndefined22 true");
            assert.Equal(item22(19, "two"), 22, "Bridge655 item22");

            Action<int, string> item32 = (i, s) => { var b = i == s.Length; };
            assert.Equal(item32.IsNullOrUndefined("32"), "false", "Bridge655 IsNullOrUndefined32 false");
            assert.Equal(item32.IsNullOrUndefined(string.Empty), "true", "Bridge655 IsNullOrUndefined32 true");
        }
Exemple #7
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(6);

            var s1 = string.Join(",", new[] { "a", "b" });
            assert.Equal(s1, "a,b", "Join1");

            var animals = new List<Animal>();
            animals.Add(new Animal("Squirrel", "Rodent"));
            animals.Add(new Animal("Gray Wolf", "Carnivora"));
            animals.Add(new Animal("Capybara", "Rodent"));

            string s2 = String.Join(" ", animals);
            assert.Equal(s2, "Squirrel Gray Wolf Capybara", "Join2");

            object[] values = { null, "Cobb", 4189, 11434, .366 };
            string s31 = String.Join("|", values);
            assert.Equal(s31, "|Cobb|4189|11434|0.366", "Join31");

            values[0] = String.Empty;
            string s32 = String.Join("|", values);
            assert.Equal(s32, "|Cobb|4189|11434|0.366", "Join32");

            string[] sArr = new string[10];
            for (int i = 0; i < 10; i++)
                sArr[i] = String.Format("{0,-3}", i * 5);

            string s4 = String.Join(":", sArr);
            assert.Equal(s4, "0  :5  :10 :15 :20 :25 :30 :35 :40 :45 ", "Join4");

            var val = new string[] { "apple", "orange", "grape", "pear" };
            var s5 = string.Join(", ", val, 1, 2);
            assert.Equal(s5, "orange, grape", "Join5");
        }
Exemple #8
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(1);

            var ted = new Bridge566B();
            assert.Equal(ted.Data, "Ted", "#566 Ted");
        }
Exemple #9
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(1);

            object o = Script.Undefined;
            assert.Throws(() => { var s = (string)o; }, "Unable to cast type 'null' to type String");
        }
        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");
        }
        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");
        }
Exemple #12
0
        public static void TesForeach(Assert assert)
        {
            assert.Expect(2);

            string[] keys = new[] { "1", "2", "3" };
            Action[] handlers = new Action[3];
            int i = 0;
            string result = "";

            foreach (var itm in keys)
                handlers[i++] = () => result += itm;

            foreach (var handler in handlers)
            {
                handler();
            }

            assert.Equal(result, "123", "Bridge563 No block foreach loop");

            i = 0;
            result = "";

            foreach (var itm in keys)
            {
                handlers[i++] = () => result += itm;
            }

            foreach (var handler in handlers)
            {
                handler();
            }

            assert.Equal(result, "123", "Bridge563 block foreach loop");
        }
Exemple #13
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(1);

            int[] numbers = { 1, 2, 3 };

            int sum = 0;

            foreach (int a in numbers)
            {
                sum = sum + a;
            }

            foreach (int a in numbers)
            {
                sum = sum + a;
            }

            foreach (int a in numbers)
            {
                sum = sum + a;
            }

            foreach (int a in numbers)
            {
                sum = sum + a;
            }

            assert.Equal(sum, 24, "Bridge502 sum");
        }
Exemple #14
0
        public static void TestCloneCompare(Assert assert)
        {
            assert.Expect(13);

            var v1 = new Version(1, 2, 3, (4 << 16) + 5);

            var o = v1.Clone();
            assert.Ok(o != null, "v1 Cloned");

            var v2 = o as Version;
            assert.Ok(v2 != null, "v1 Cloned as Version");

            assert.Equal(v2.Major, 1, "v2.Major 1");
            assert.Equal(v2.Minor, 2, "v2.Minor 2");
            assert.Equal(v2.Build, 3, "v2.Build 3");
            assert.Equal(v2.Revision, 262149, "v2.Revision  (4 << 16) + 5 = 262149");
            assert.Equal(v2.MajorRevision, 4, "v2.MajorRevision 4");
            assert.Equal(v2.MinorRevision, 5, "v2.MinorRevision 5");

            var v3 = new Version(1, 2, 2, (4 << 16) + 5);
            assert.Equal(v1.CompareTo(v3), 1, "v1.CompareTo(v3)");

            var v4 = new Version(1, 3, 3, (4 << 16) + 5);
            assert.Equal(v1.CompareTo(v4), -1, "v1.CompareTo(v4)");

            assert.Equal(v1.CompareTo(o), 0, "v1.CompareTo(o)");
            assert.Equal(v1.CompareTo(v2), 0, "v1.CompareTo(v2)");
            assert.NotEqual(v1.CompareTo(null), 0, "v1.CompareTo(null)");
        }
Exemple #15
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(6);

            SByte i8_1 = -2;
            SByte i8_2 = (SByte)(i8_1 >> 4);
            Byte u8_1 = 0xFE;
            Byte u8_2 = (Byte)(u8_1 >> 4);

            Int16 i16_1 = -2;
            Int16 i16_2 = (Int16)(i16_1 >> 8);
            UInt16 u16_1 = 0xFFFE;
            UInt16 u16_2 = (UInt16)(u16_1 >> 8);

            Int32 i32_1 = -2;
            Int32 i32_2 = i32_1 >> 16;
            UInt32 u32_1 = 0xFFFFFFFE;
            UInt32 u32_2 = u32_1 >> 16;

            assert.Equal(i8_2, -1, "Bridge592 i8_2");
            assert.Equal(u8_2, 0xF, "Bridge592 u8_2");
            assert.Equal(i16_2, -1, "Bridge592 i16_2");
            assert.Equal(u16_2, 0xFF, "Bridge592 u16_2");
            assert.Equal(i32_2, -1, "Bridge592 i32_2");
            assert.Equal(u32_2, 0xFFFF, "Bridge592 u32_2");
        }
Exemple #16
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(1);

            var o = JSON.Parse<bool>("true");
            assert.Equal(o, true, "Bridge544 bool");
        }
Exemple #17
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(7);

            var t1 = new Type();
            assert.Ok(t1 != null, "#565 t1");

            var t2 = new ValueType();
            assert.Ok(t2 != null, "#565 t2");

            var t3 = new IntPtr();
            assert.Ok(t3.GetType() == typeof(IntPtr) , "#565 t3");

            var t4 = new UIntPtr();
            assert.Ok(t4.GetType() == typeof(UIntPtr), "#565 t4");

            var t5 = new ParamArrayAttribute();
            assert.Ok(t5 != null, "#565 t5");

            var t6 = new RuntimeTypeHandle();
            assert.Ok(t6.GetType() == typeof(RuntimeTypeHandle), "#565 t6");

            var t7 = new RuntimeFieldHandle();
            assert.Ok(t7.GetType() == typeof(RuntimeFieldHandle), "#565 t7");
        }
Exemple #18
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(10);

            var array1 = new Int8Array(1);
            Bridge550.TestMethod(array1, "Int8Array", assert);

            var array2 = new Uint8Array(1);
            Bridge550.TestMethod(array2, "Uint8Array", assert);

            var array3 = new Uint8ClampedArray(1);
            Bridge550.TestMethod(array3, "Uint8ClampedArray", assert);

            var array4 = new Int16Array(1);
            Bridge550.TestMethod(array4, "Int16Array", assert);

            var array5 = new Uint16Array(1);
            Bridge550.TestMethod(array5, "Uint16Array", assert);

            var array6 = new Int32Array(1);
            Bridge550.TestMethod(array6, "Int32Array", assert);

            var array7 = new Uint32Array(1);
            Bridge550.TestMethod(array7, "Uint32Array", assert);

            var array8 = new Float32Array(1);
            Bridge550.TestMethod(array8, "Float32Array", assert);

            var array9 = new Float64Array(1);
            Bridge550.TestMethod(array9, "Float64Array", assert);

            var array10 = new DataView(array9.Buffer);
            Bridge550.TestMethod(array10, "DataView", assert);
        }
        public static void TestInstance(Assert assert)
        {
            assert.Expect(17);

            var i = new Instance();

            assert.Ok(i != null, "i created");
            assert.Equal(i.Foo(1), "Foo(int x)", "Instance Foo(int x)");
            assert.Equal(i.Foo("string"), "Foo(string s)", "Instance Foo(string s)");
            assert.Equal(i.Foo(1.1), "Foo(double d)", "Instance Foo(double d)");
            assert.Equal(i.Foo(1, 2), "Foo(int x, int y)", "Instance Foo(int x, int y)");
            assert.Equal(i.Foo(1, 1.1), "Foo(int x, double y)", "Instance Foo(int x, double y)");
            assert.Equal(i.Foo(1.1, 1), "Foo(double x, int y)", "Instance Foo(double x, int y)");

            assert.Equal(i.FooReturnType(1), 'C', "Instance char FooReturnType(int y)");
            assert.Equal(i.FooReturnType(1.1), "string FooReturnType(double d)", "Instance string FooReturnType(double d)");

            assert.Equal(i.FooOptionalParameters(1), "FooOptionalParameters(int x)", "Instance FooOptionalParameters(int x)");
            assert.Equal(i.FooOptionalParameters(1, 2), "FooOptionalParameters(int x, int y = 5)", "Instance FooOptionalParameters(int x, int y = 5)");

            assert.Equal(i.FooMultipleOptionalParameters(1, 2), "FooMultipleOptionalParameters(int x, int y = 5)", "Instance FooMultipleOptionalParameters(int x, int y = 5)");
            assert.Equal(i.FooMultipleOptionalParameters(1, z: 2), "FooMultipleOptionalParameters(int x, int y = 5, int z = 10)", "Instance FooMultipleOptionalParameters(int x, int y = 5, int z = 10)");
            assert.Equal(i.FooMultipleOptionalParameters(1, 2, 3), "FooMultipleOptionalParameters(int x, int y = 5, int z = 10)", "Instance FooMultipleOptionalParameters(int x, int y = 5, int z = 10)");
            assert.Equal(i.FooMultipleOptionalParameters(1, z: 2, y: 3), "FooMultipleOptionalParameters(int x, int y = 5, int z = 10)", "Instance FooMultipleOptionalParameters(int x, int y = 5, int z = 10)");

            assert.Equal(i.FooNamedArgument(x: 1), "FooNamedArgument(int x)", "Static FooNamedArgument(int x)");
            assert.Equal(i.FooNamedArgument(d: 1), "FooNamedArgument(double d)", "Static FooNamedArgument(double d)");
        }
Exemple #20
0
        public static void TestConstructors(Assert assert)
        {
            assert.Expect(42);

            var v1 = new Version();

            assert.Ok(v1 != null, "v1 created");
            assert.Equal(v1.Major, 0, "v1.Major 0");
            assert.Equal(v1.Minor, 0, "v1.Minor 0");
            assert.Equal(v1.Build, -1, "v1.Build -1");
            assert.Equal(v1.Revision, -1, "v1.Revision -1");
            assert.Equal(v1.MajorRevision, -1, "v1.MajorRevision -1");
            assert.Equal(v1.MinorRevision, -1, "v1.MinorRevision -1");

            var v2 = new Version("2.4.1128.2");
            assert.Ok(v2 != null, "v2 created");
            assert.Equal(v2.Major, 2, "v2.Major 2");
            assert.Equal(v2.Minor, 4, "v2.Minor 4");
            assert.Equal(v2.Build, 1128, "v2.Build 1128");
            assert.Equal(v2.Revision, 2, "v2.Revision 2");
            assert.Equal(v2.MajorRevision, 0, "v2.MajorRevision 0");
            assert.Equal(v2.MinorRevision, 2, "v2.MinorRevision 2");

            var v3 = new Version("2.4.1128.65537");
            assert.Ok(v3 != null, "v3 created");
            assert.Equal(v3.Major, 2, "v3.Major 2");
            assert.Equal(v3.Minor, 4, "v3.Minor 4");
            assert.Equal(v3.Build, 1128, "v3.Build 1128");
            assert.Equal(v3.Revision, 65537, "v3.Revision 65537");
            assert.Equal(v3.MajorRevision, 1, "v3.MajorRevision 1");
            assert.Equal(v3.MinorRevision, 1, "v3.MinorRevision 1");

            var v4 = new Version(20, 10);
            assert.Ok(v4 != null, "v4 created");
            assert.Equal(v4.Major, 20, "v4.Major 20");
            assert.Equal(v4.Minor, 10, "v4.Minor 10");
            assert.Equal(v4.Build, -1, "v4.Build -1");
            assert.Equal(v4.Revision, -1, "v4.Revision -1");
            assert.Equal(v4.MajorRevision, -1, "v4.MajorRevision -1");
            assert.Equal(v4.MinorRevision, -1, "v4.MinorRevision -1");

            var v5 = new Version(200, 100, 300);
            assert.Ok(v5 != null, "v5 created");
            assert.Equal(v5.Major, 200, "v5.Major 200");
            assert.Equal(v5.Minor, 100, "v5.Minor 100");
            assert.Equal(v5.Build, 300, "v5.Build 300");
            assert.Equal(v5.Revision, -1, "v5.Revision -1");
            assert.Equal(v5.MajorRevision, -1, "v5.MajorRevision -1");
            assert.Equal(v5.MinorRevision, -1, "v5.MinorRevision -1");

            var v6 = new Version(2000, 1000, 3000, (345 << 16) + 4000);
            assert.Ok(v6 != null, "v6 created");
            assert.Equal(v6.Major, 2000, "v6.Major 2000");
            assert.Equal(v6.Minor, 1000, "v6.Minor 1000");
            assert.Equal(v6.Build, 3000, "v6.Build 3000");
            assert.Equal(v6.Revision, 22613920, "v6.Revision (345 << 16) + 4000 = 22613920");
            assert.Equal(v6.MajorRevision, 345, "v6.MajorRevision 345");
            assert.Equal(v6.MinorRevision, 4000, "v6.MinorRevision 4");
        }
Exemple #21
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(2);

            var inst = new Bridge597A();
            assert.Equal(inst.Get(), "0:a", "Bridge597 Without instance member access");
            assert.Equal(inst.GetWithMember(), "HI!:0:a", "Bridge597 With instance member access");
        }
        public static void Bridge315(Assert assert)
        {
            assert.Expect(1);

            var q = "a,b,c,a".ToUpperCase().Split(",").Aggregate("", (workingSentence, next) => next + " " + workingSentence);

            assert.Equal(q, "A C B A ", "Enumerable.Aggregate");
        }
Exemple #23
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(2);

            assert.Equal(Bridge537B.TestB1(), 2, "Bridge537 TestB1");

            assert.Equal(Bridge537B.TestB2(), 1, "Bridge537 TestB2");
        }
Exemple #24
0
        // [#84] Does not compile
        public static void SimpleTryCatch(Assert assert)
        {
            assert.Expect(1);

            var result = TryCatch("Good");

            assert.Equal(result, "Good", "TryCatch() executes");
        }
Exemple #25
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");
        }
Exemple #26
0
        public static void TestExplicitInterfaceMethodAndProperty(Assert assert)
        {
            assert.Expect(3);

            ISimple b = new B();
            assert.Ok(b != null, "Instance of B created through ISimple interface explicitly");
            assert.Equal(b.GetString(), "explicit B.ISimple", "b.GetString() = explicit B.ISimple");
            assert.Equal(b.Data, 2, "a.Data = 2");
        }
Exemple #27
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(2);

            var s = new Bridge608A("test");
            object o = "test";
            assert.Ok(s.Equals(o), "Bridge608 Object");
            assert.Ok(s.Equals("test"), "Bridge608 String");
        }
        public static void Test(Assert assert)
        {
            assert.Expect(3);

            assert.Equal(TestMethodParametersClass.MethodDefault(), 5, "Default parameter - 5");
            assert.Equal(TestMethodParametersClass.MethodDefault(10), 10, "Default parameter - 10");

            assert.Equal(TestMethodParametersClass.MethodParams(new[] { 1, 2, 3 }), 6, "params int[]");
        }
        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");
        }
        public static void SimpleTryCatchFinally(Assert assert)
        {
            assert.Expect(1);

            var data = new Data();
            TryCatchFinally(data);

            assert.Equal(data.Count, 2, "TryCatchFinally() executes");
        }