Beispiel #1
0
        public void should_composing_iterating_sequences()
        {
            var demoObject    = new ImplIteratorUsingYieldDemoClass();
            var numberStorage = new List <int>();

            foreach (int number in demoObject.GetEvenNumber(demoObject.GetOneToTen()))
            {
                numberStorage.Add(number);
            }

            // change the variable value to fix the test.
            var expectedNumberStorage = new List <int> {
                2, 4, 6, 8, 10
            };

            Assert.Equal(expectedNumberStorage, numberStorage);
        }
Beispiel #2
0
        public void should_treat_yield_as_part_of_the_iteration_stream()
        {
            var demoObject    = new ImplIteratorUsingYieldDemoClass();
            var numberStorage = new List <int>();

            foreach (int number in demoObject.GetOneToThreeWithMultipleYields())
            {
                numberStorage.Add(number);
            }

            // change the variable value to fix the test.
            var expectedNumberStorage = new List <int> {
                1, 2, 3
            };

            Assert.Equal(expectedNumberStorage, numberStorage);
        }
Beispiel #3
0
        public void should_using_yield_break_to_stop_iterating_early()
        {
            var demoObject    = new ImplIteratorUsingYieldDemoClass();
            var numberStorage = new List <int>();

            foreach (int number in demoObject.GetOnToThreeButBreakingAtTwo())
            {
                numberStorage.Add(number);
            }

            // change the variable value to fix the test.
            var expectedNumberStorage = new List <int> {
                1, 2
            };

            Assert.Equal(expectedNumberStorage, numberStorage);
        }
Beispiel #4
0
        public void should_implement_iterator_using_yield()
        {
            var demoObject    = new ImplIteratorUsingYieldDemoClass();
            var numberStorage = new List <int>();

            foreach (int number in demoObject.GetOneToTen())
            {
                numberStorage.Add(number);
            }

            // change the variable value to fix the test.
            var expectedNumberStorage = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };

            Assert.Equal(expectedNumberStorage, numberStorage);
        }