public void ForEachArray()
        {
            var arr = new[] { 1, 2, 3, 4 };
            int count = 0;
            arr.ForEach(item => count += item);

            Assert.AreEqual(10, count);
        }
예제 #2
0
        public void ForEach_WithCollectionOf10_Iterates10Times()
        {
            var totalIterations = 0;
            var listOfNumbers = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            listOfNumbers.ForEach(number => totalIterations++);

            Assert.That(totalIterations, Is.EqualTo(10));
        }
예제 #3
0
        public void ForEach()
        {
            int sum = 0;
            IEnumerable<int> numbers = new [] {1, 2, 3, 5, 8};

            numbers.ForEach(n => sum += n);

            Assert.That(sum, Is.EqualTo(19));
        }
예제 #4
0
        public void ForEach_WithCollectionOf1_Iterates1Time()
        {
            var totalIterations = 0;
            var listOfNumbers = new[] { 1 };

            listOfNumbers.ForEach(number => totalIterations++);

            Assert.That(totalIterations, Is.EqualTo(1));
        }
        public void ForEach_should_enumerate_the_collection()
        {
            int sum = 0;
            var values = new[] { 1, 1, 1 };

            values.ForEach(x => sum += x);

            sum.Should().Be(3);
        }
        public void ForEach_with_function_executes_function_over_every_element()
        {
            var executeWith = new List<int>();
            var elements = new[] {1, 2, 3, 4};

            elements.ForEach(executeWith.Add);

            Assert.That(executeWith, Is.EquivalentTo(elements));
        }
예제 #7
0
        public void WhenForEachExecuted_ThenCallsActionForEach()
        {
            var strings = new[] { "foo", "bar" };
            var called = new List<string>();

            strings.ForEach(s => called.Add(s));

            Assert.Equal(strings, called);
        }
        public void ForEach_WithCollection_IteratesEachItem()
        {
            // arrange
            IEnumerable<int> numbers = new[]{5, 4, 3};
            string concatenated = string.Empty;

            // act
            numbers.ForEach(number => concatenated += number);

            // assert
            Assert.AreEqual("543", concatenated);
        }
예제 #9
0
        public void ForEach_WithIEnumerable_PerformsAction()
        {
            // Arrange
            var values = new[] { "William", "Sarah", "Abigail", "Jessica" };

            //Act
            var result = string.Empty;
            values.ForEach(x => result += x);

            // Assert
            Assert.That(result, Is.EqualTo(string.Join(string.Empty, values)));
        }
예제 #10
0
        public void Should_CallActionForEachItem_WhenForEachIsInvoked()
        {
            // arrange
            var items = new[] {1, 2, 3, 4, 5};
            var visitedItems = new List<int>();

            // act
            items.ForEach(visitedItems.Add);

            // assert
            visitedItems.Should().BeEquivalentTo(items);
        }
예제 #11
0
 public void SaveOrLoad(Serializer serializer)
 {
     if (serializer.IsLoading)
     {
         Images.Clear();
     }
     var objectEntries = new[]
     {
         LoadAndSaveEntry.Create(reader => reader.ReadUInt32(), writer => writer.WriteUInt32(0), 8),
         LoadAndSaveEntry.Create(reader => reader.ReadUInt32(), writer => writer.WriteUInt32(0), 8),
         LoadAndSaveEntry.Create(reader =>
             {
                 Walk = new Point(reader.ReadInt16(), reader.ReadInt16());
             }, writer =>
             {
                 writer.WriteInt16(Walk.X);
                 writer.WriteInt16(Walk.Y);
             }, 8),
         LoadAndSaveEntry.Create(reader => Number = reader.ReadUInt16(), writer => writer.Write(Number), 8),
         LoadAndSaveEntry.Create(reader =>
             {
                 Position = new Point(reader.ReadInt16(), reader.ReadInt16());
             }, writer =>
             {
                 writer.WriteInt16(Position.X);
                 writer.WriteInt16(Position.Y);
             }, 8),
         LoadAndSaveEntry.Create(reader => Width = reader.ReadUInt16(), writer => writer.WriteUInt16(Width), 8),
         LoadAndSaveEntry.Create(reader => Height = reader.ReadUInt16(), writer => writer.WriteUInt16(Height), 8),
         LoadAndSaveEntry.Create(reader => ActorDir = reader.ReadByte(), writer => writer.WriteByte(ActorDir), 8),
         LoadAndSaveEntry.Create(reader => ParentState = reader.ReadByte(), writer => writer.WriteByte(ParentState), 8),
         LoadAndSaveEntry.Create(reader => Parent = reader.ReadByte(), writer => writer.WriteByte(Parent), 8),
         LoadAndSaveEntry.Create(reader => State = reader.ReadByte(), writer => writer.WriteByte(State), 8),
         LoadAndSaveEntry.Create(reader => reader.ReadByte(), writer => writer.WriteByte(0), 8),
         LoadAndSaveEntry.Create(reader => Flags = (DrawBitmaps)reader.ReadByte(), writer => writer.WriteByte((byte)Flags), 46),
     };
     objectEntries.ForEach(e => e.Execute(serializer));
 }