public void Can_Do_Stuff()
        {
            // Arrange - Set up what i`m going to work with
            IEnumerable<int> numbers = new[] {0, 1, 2, 3, 4, 5};

            // Act - Do the Stuff
            var avg = numbers.Sum()/numbers.Count(n => n != 0);

            // Assert - Validate it worked
            Assert.AreEqual(avg, 3);
            Assert.AreEqual(numbers.Sum(), 15);
            Assert.IsTrue(numbers.Count() == 6);
            Assert.IsTrue(numbers.Count(n => n != 0) == 5);
        }
 public void AdjustWidths_ColumnsThatFitAreUnchanged()
 {
     var columns = new[] {80, 97, 110, 102};
     var sum = columns.Sum();
     var actual = AccessibleListView.AdjustWidths(columns, sum);
     EnumerableExtensions.EnumerateSame(columns, actual);
 }
        public void MultipleFramesNeverAllPinsDown_GetScore_ShouldReturnSumOfAllPinsDown()
        {
            // Given
            var bowlSequence = new[] {4, 4, 4, 4, 4, 4};
            ExecuteBowlSequence(bowlSequence);

            // When
            var score = scorer.GetScore();

            // Then
            score.Should().Be(bowlSequence.Sum());
        }
Example #4
0
 public void SingleFromSelector()
 {
     var source = new[]
     {
         new { name="Tim", num=9.5f },
         new { name="John", num=10.5f },
         new { name="Bob", num=3.5f }
     };
     Assert.Equal(23.5f, source.Sum(e => e.num));
 }
Example #5
0
 public void NullableDecimalFromSelector()
 {
     var source = new[]
     {
         new { name="Tim", num=(decimal?)20.51m },
         new { name="John", num=default(decimal?) },
         new { name="Bob", num=(decimal?)2.33m }
     };
     Assert.Equal(22.84m, source.Sum(e => e.num));
 }
Example #6
0
 public void DecimalFromSelector()
 {
     var source = new[]
     {
         new {name="Tim", num=20.51m},
         new {name="John", num=10m},
         new {name="Bob", num=2.33m}
     };
     Assert.Equal(32.84m, source.Sum(e => e.num));
 }
Example #7
0
 public void NullableDoubleFromSelector()
 {
     var source = new[]
     {
         new { name="Tim", num=(double?)9.5 },
         new { name="John", num=default(double?) },
         new { name="Bob", num=(double?)8.5 }
     };
     Assert.Equal(18.0, source.Sum(e => e.num).Value);
 }
Example #8
0
        public void NullableInt64FromSelector()
        {
            var source = new[]{
                new { name="Tim", num=(long?)10L },
                new { name="John", num=(long?)int.MaxValue },
                new { name="Bob", num=default(long?) }
            };

            Assert.Equal(int.MaxValue + 10L, source.Sum(e => e.num));
        }
Example #9
0
        public void Int64FromSelector()
        {
            var source = new[]{
                new { name="Tim", num=10L },
                new { name="John", num=(long)int.MaxValue },
                new { name="Bob", num=40L }
            };

            Assert.Equal(int.MaxValue + 50L, source.Sum(e => e.num));
        }
Example #10
0
 public void NullableInt32FromSelector()
 {
     var source = new[]
     {
         new { name="Tim", num=(int?)10 },
         new { name="John", num=default(int?) },
         new { name="Bob", num=(int?)-30 }
     };
     Assert.Equal(-20, source.Sum(e => e.num));
 }
Example #11
0
 public void Int32FromSelector()
 {
     var source = new[]
     {
         new { name="Tim", num=10 },
         new { name="John", num=50 },
         new { name="Bob", num=-30 }
     };
     Assert.Equal(30, source.Sum(e => e.num));
 }
Example #12
0
 public void NullableSingleFromSelector()
 {
     var source = new[]{
         new { name="Tim", num=(float?)9.5f },
         new { name="John", num=default(float?) },
         new { name="Bob", num=(float?)8.5f }
     };
     Assert.Equal(18.0f, source.Sum(e => e.num).Value);
 }
        public void MultipleFramesOneFrameIsSpare_GetScore_ShouldReturnSumOfAllPinsDownPlusFirstBowlAfterSpare()
        {
            // Given
            var bowlSequence = new[] {4, 6, 2, 4};
            ExecuteBowlSequence(bowlSequence);

            // When
            var score = scorer.GetScore();

            // Then
            score.Should().Be(bowlSequence.Sum() + 2);
        }
        public void MultipleFramesOneFrameIsSpareStraddlingFrames_GetScore_ShouldReturnSumOfAllPinsDown()
        {
            // Given
            var bowlSequence = new[] { 3, 6, 4, 4 };
            ExecuteBowlSequence(bowlSequence);

            // When
            var score = scorer.GetScore();

            // Then
            score.Should().Be(bowlSequence.Sum());
        }
Example #15
0
 public Stack<double> Calculate(Stack<double> stack)
 {
     var operands = new[] {stack.Pop(), stack.Pop()};
     stack.Push(operands.Sum());
     return stack;
 }