예제 #1
0
        public void TakeWhileWithIndex()
        {
            var ints = new[] { 1, 2, 3, 4, 5 }.TakeWhile((x, i) => i < 3).ToArray();

            QUnit.AreEqual(ints.Length, 3);
            QUnit.AreEqual(ints[0], 1);
            QUnit.AreEqual(ints[1], 2);
            QUnit.AreEqual(ints[2], 3);
        }
예제 #2
0
        public void ElementAtOrDefault()
        {
            var items = new[] { 0, 1, 2 };

            QUnit.AreEqual(items.ElementAtOrDefault(0), 0);
            QUnit.AreEqual(items.ElementAtOrDefault(1), 1);
            QUnit.AreEqual(items.ElementAtOrDefault(2), 2);
            QUnit.AreEqual(items.ElementAtOrDefault(3), 0);
        }
예제 #3
0
        public void SkipWhile()
        {
            var ints = new[] { 1, 2, 3, 4, 5 }.SkipWhile(x => x < 3).ToArray();

            QUnit.AreEqual(ints.Length, 3);
            QUnit.AreEqual(ints[0], 3);
            QUnit.AreEqual(ints[1], 4);
            QUnit.AreEqual(ints[2], 5);
        }
예제 #4
0
        public void Take()
        {
            var ints = new[] { 8, 3, 5, 1 }.Take(3).ToArray();

            QUnit.AreEqual(ints.Length, 3);
            QUnit.AreEqual(ints[0], 8);
            QUnit.AreEqual(ints[1], 3);
            QUnit.AreEqual(ints[2], 5);
        }
예제 #5
0
        public void SelectWithIndex()
        {
            var array = new[] { "1", "2", "3" };
            var two   = array.Select((x, i) => x + "a" + i).ToArray();

            QUnit.AreEqual(two[0], "1a0");
            QUnit.AreEqual(two[1], "2a1");
            QUnit.AreEqual(two[2], "3a2");
        }
예제 #6
0
        public void DupsDontChangeCount()
        {
            var dictionary = new Dictionary <string, int>();

            dictionary["one"] = 1;
            dictionary["one"] = 2;
            QUnit.AreEqual(dictionary["one"], 2);
            QUnit.AreEqual(dictionary.Count, 1);
        }
예제 #7
0
        public void Set()
        {
            var dictionary = new Dictionary <string, int>();

            dictionary["one"] = 1;
            dictionary["two"] = 2;
            QUnit.AreEqual(dictionary["one"], 1);
            QUnit.AreEqual(dictionary["two"], 2);
        }
예제 #8
0
        public void Property()
        {
            Expression <Func <ClassWithMembers, string> > lambda = x => x.StringProperty;
            var memberExpression = (MemberExpression)lambda.Body;

            QUnit.AreEqual(memberExpression.Expression, lambda.Parameters[0]);
            QUnit.IsTrue(memberExpression.Member is PropertyInfo);
            QUnit.AreEqual(memberExpression.Member.Name, "StringProperty");
        }
예제 #9
0
        public void DefaultIfEmptyExplicitDefault()
        {
            var s = new string[0].DefaultIfEmpty("default").Single();

            QUnit.AreEqual(s, "default");

            var i = new int[0].DefaultIfEmpty(5).Single();

            QUnit.AreEqual(i, 5);
        }
예제 #10
0
        public void DefaultIfEmpty()
        {
            var s = new string[0].DefaultIfEmpty().Single();

            QUnit.AreEqual(s, null);

            var i = new int[0].DefaultIfEmpty().Single();

            QUnit.AreEqual(i, 0);
        }
예제 #11
0
        public void Reverse()
        {
            var ints    = new[] { 1, 2, 3 };
            var reverse = ints.Reverse().ToArray();

            QUnit.AreEqual(reverse.Length, 3);
            QUnit.AreEqual(reverse[0], 3);
            QUnit.AreEqual(reverse[1], 2);
            QUnit.AreEqual(reverse[2], 1);
        }