コード例 #1
0
ファイル: AverageTests.cs プロジェクト: ChuangYang/corefx
        public void NullableFloat_WithSelector()
        {
            var source = new []
            {
                new { name = "Tim", num = (float?)5.5f },
                new { name = "John", num = (float?)15.5f },
                new { name = "Bob", num = default(float?) }
            };
            float? expected = 10.5f;

            Assert.Equal(expected, source.Average(e => e.num));
        }
コード例 #2
0
ファイル: AverageTests.cs プロジェクト: ChuangYang/corefx
        public void NullableDecimal_WithSelector()
        {
            var source = new[]
            {
                new{ name = "Tim", num = (decimal?)5.5m},
                new{ name = "John", num = (decimal?)15.5m},
                new{ name = "Bob", num = (decimal?)null}
            };
            decimal? expected = 10.5m;

            Assert.Equal(expected, source.Average(e => e.num));
        }
コード例 #3
0
ファイル: AverageTests.cs プロジェクト: ChuangYang/corefx
        public void Float_WithSelector()
        {
            var source = new[]
            {
                new{ name = "Tim", num = 5.5f},
                new{ name = "John", num = 15.5f},
                new{ name = "Bob", num = 3.0f}
            };
            float expected = 8.0f;

            Assert.Equal(expected, source.Average(e => e.num));
        }
コード例 #4
0
ファイル: AverageTests.cs プロジェクト: ChuangYang/corefx
        public void NullableDouble_WithSelector()
        {
            var source = new[]
            {
                new{ name = "Tim", num = (double?)5.5 },
                new{ name = "John", num = (double?)15.5 },
                new{ name = "Bob", num = default(double?) }
            };
            double? expected = 10.5;

            Assert.Equal(expected, source.Average(e => e.num));
        }
コード例 #5
0
ファイル: AverageTests.cs プロジェクト: ChuangYang/corefx
        public void Decimal_WithSelector()
        {
            var source = new[]
            {
                new{ name = "Tim", num = 5.5m},
                new{ name = "John", num = 15.5m},
                new{ name = "Bob", num = 3.0m}
            };
            decimal expected = 8.0m;

            Assert.Equal(expected, source.Average(e => e.num));
        }
コード例 #6
0
ファイル: AverageTests.cs プロジェクト: ChuangYang/corefx
        public void Double_WithSelector()
        {
            var source = new []
            {
                new { name = "Tim", num = 5.5},
                new { name = "John", num = 15.5},
                new { name = "Bob", num = 3.0}
            };
            double expected = 8.0;

            Assert.Equal(expected, source.Average(e => e.num));
        }
コード例 #7
0
ファイル: AverageTests.cs プロジェクト: ChuangYang/corefx
        public void NullableLong_WithSelector()
        {
            var source = new []
            {
                new { name = "Tim", num = (long?)40L },
                new { name = "John", num = default(long?) },
                new { name = "Bob", num = (long?)30L }
            };
            double? expected = 35;

            Assert.Equal(expected, source.Average(e => e.num));
        }
コード例 #8
0
ファイル: AverageTests.cs プロジェクト: ChuangYang/corefx
        public void Long_FromSelector()
        {
            var source = new []
            {
                new { name = "Tim", num = 40L },
                new { name = "John", num = 50L },
                new { name = "Bob", num = 60L }
            };
            double expected = 50;

            Assert.Equal(expected, source.Average(e => e.num));
        }
コード例 #9
0
ファイル: AverageTests.cs プロジェクト: ChuangYang/corefx
        public void NullableInt_WithSelector()
        {
            var source = new []
            {
                new { name = "Tim", num  = (int?)10 },
                new { name = "John", num =  default(int?) },
                new { name = "Bob", num = (int?)10 }
            };
            double? expected = 10;

            Assert.Equal(expected, source.Average(e => e.num));
        }
コード例 #10
0
ファイル: AverageTests.cs プロジェクト: ChuangYang/corefx
        public void Int_WithSelector()
        {
            var source = new []
            {
                new { name="Tim", num = 10 },
                new { name="John", num = -10 },
                new { name="Bob", num = 15 }
            };
            double expected = 5;

            Assert.Equal(expected, source.Average(e => e.num));
        }