Exemple #1
0
        public void Execute()
        {
            //
            // Take拡張メソッドは、シーケンスの先頭から指定された件数分を返すメソッド。
            //
            //   ・シーケンスの要素数より多い数を指定した場合、そのシーケンス全てが返る.
            //   ・0以下の値を指定した場合、空のシーケンスが返る.
            //
            var names = new[] {"gsf_zero1", "gsf_zero2", "gsf_zero3", "gsf_zero4", "gsf_zero5"};

            Output.WriteLine("================ Take ======================");
            var top3 = names.Take(3);
            foreach (var item in top3)
            {
                Output.WriteLine(item);
            }

            foreach (var item in names.Take(20))
            {
                Output.WriteLine(item);
            }

            Output.WriteLine("0以下の数値を指定: COUNT={0}", names.Take(-1).Count());

            //
            // TakeWhile拡張メソッドは、指定された条件が満たされる間シーケンスから要素を抽出し
            // 返すメソッド。
            //
            Output.WriteLine("================ TakeWhile ======================");
            var lessThan4 = names.TakeWhile(name => int.Parse(name.Last().ToString()) <= 4);
            foreach (var item in lessThan4)
            {
                Output.WriteLine(item);
            }
        }
Exemple #2
0
        public void PicksUpFromWhereItLeft()
        {
            var allMigrations = new[]
            {
                new TestMigration(1, "test", "CREATE TABLE [Table1] ([Id] int)"),
                new TestMigration(2, "test", "CREATE TABLE [Table2] ([Id] int)"),
                new TestMigration(3, "test", "CREATE TABLE [Table3] ([Id] int)"),
            };

            _migrator.Execute(allMigrations.Take(2));

            var tableNameAfterFirstTwoMigrations = GetTableNames();

            _migrator.Execute(allMigrations);

            var tableNameAfterAllMigrations = GetTableNames();

            Assert.That(tableNameAfterFirstTwoMigrations, Is.EqualTo(new[] { "Table1", "Table2" }));
            Assert.That(tableNameAfterAllMigrations, Is.EqualTo(new[] { "Table1", "Table2", "Table3" }));
        }
        public void StatementPositionTest()
        {
            const string temp = "Test 123123123 ";
            var strings = new[]
                          {
                          	"<%ruleclass Test%>",   // 0
                          	"<%rule Temp()%>",      // 1
                          	temp + "<%= value %>",  // 2 0, 1
                          	"Pre End Text",         // 3 2
                          	"<%= value %>",         // 4 3
                          	"End Text",             // 5 4
                          	"<%end%>",              // 6
                          };

            const string endLine = "\r\n";
            var statementText = string.Join( endLine, strings );

            var ruleClassStatement = ParserHelper.ParseClass( statementText );

            var textStatement1StartPos = string.Join( endLine, strings.Take(2).ToArray() ).Length + endLine.Length;
            var textStatement1EndPos = textStatement1StartPos + temp.Length - 1;

            var ruleMethodStatement = (RuleMethodStatement)ruleClassStatement.RuleMethodStatements[0];
            AssertHelper.AssertStatementPosition( textStatement1StartPos, textStatement1EndPos,
                                                  ruleMethodStatement.Statements[0].StatementPosition );

            // »звратный подсчЄт, дл¤ UnitTest'а плохой вариант, но так впадлу вручную считать
            AssertHelper.AssertStatementPosition( 3, 3, temp.Length + 1, strings[2].Length, textStatement1EndPos + 1,
                                                  textStatement1EndPos + strings[2].Length - temp.Length,
                                                  ruleMethodStatement.Statements[1].StatementPosition );

            TestText( endLine, strings, 3, 2, ruleMethodStatement.Statements[2].StatementPosition );

            TestText( endLine, strings, 5, 1, ruleMethodStatement.Statements[4].StatementPosition );

            AssertHelper.AssertStatementPosition( 1, strings.Length, 1, strings.Last().Length, 0, statementText.Length - 1,
                                                  ruleClassStatement.StatementPosition );
        }
        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");
        }
Exemple #5
0
        public void SlicingArrays()
        {
            var array = new[] { "peanut", "butter", "and", "jelly" };

            Assert.AreEqual(new string[] { FILL_IN_THE_STRING, FILL_IN_THE_STRING}, array.Take(2).ToArray());
            Assert.AreEqual(new string[] { FILL_IN_THE_STRING, FILL_IN_THE_STRING}, array.Skip(1).Take(2).ToArray());
        }