示例#1
0
 public void MaxInt32()
 {
     var ten = Enumerable.Range(1, 10).ToArray();
     var minusTen = new[] { -100, -15, -50, -10 };
     var thousand = new[] { -16, 0, 50, 100, 1000 };
     Assert.Equal(10, ten.Max());
     Assert.Equal(-10, minusTen.Max());
     Assert.Equal(1000, thousand.Max());
     Assert.Equal(int.MaxValue, thousand.Concat(Enumerable.Repeat(int.MaxValue, 1)).Max());
 }
示例#2
0
 public void MaxInt64()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (long)i).ToArray();
     var minusTen = new[] { -100L, -15, -50, -10 };
     var thousand = new[] { -16L, 0, 50, 100, 1000 };
     Assert.Equal(42, Enumerable.Repeat(42L, 1).Max());
     Assert.Equal(10, ten.Max());
     Assert.Equal(-10, minusTen.Max());
     Assert.Equal(1000, thousand.Max());
     Assert.Equal(long.MaxValue, thousand.Concat(Enumerable.Repeat(long.MaxValue, 1)).Max());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<long>().Max());
 }
示例#3
0
 public void MaxInt32()
 {
     var ten = Enumerable.Range(1, 10).ToArray();
     var minusTen = new[] { -100, -15, -50, -10 };
     var thousand = new[] { -16, 0, 50, 100, 1000 };
     Assert.Equal(42, Enumerable.Repeat(42, 1).Max());
     Assert.Equal(10, ten.Max());
     Assert.Equal(-10, minusTen.Max());
     Assert.Equal(1000, thousand.Max());
     Assert.Equal(int.MaxValue, thousand.Concat(Enumerable.Repeat(int.MaxValue, 1)).Max());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<int>().Max());
 }
示例#4
0
 public void MaxSingle()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (float)i).ToArray();
     var minusTen = new[] { -100F, -15, -50, -10 };
     var thousand = new[] { -16F, 0, 50, 100, 1000 };
     Assert.Equal(42F, Enumerable.Repeat(42F, 1).Max());
     Assert.Equal(10F, ten.Max());
     Assert.Equal(-10F, minusTen.Max());
     Assert.Equal(1000F, thousand.Max());
     Assert.Equal(float.MaxValue, thousand.Concat(Enumerable.Repeat(float.MaxValue, 1)).Max());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<float>().Max());
 }
示例#5
0
 public void MaxDecimal()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (decimal)i).ToArray();
     var minusTen = new[] { -100M, -15, -50, -10 };
     var thousand = new[] { -16M, 0, 50, 100, 1000 };
     Assert.Equal(42M, Enumerable.Repeat(42M, 1).Max());
     Assert.Equal(10M, ten.Max());
     Assert.Equal(-10M, minusTen.Max());
     Assert.Equal(1000M, thousand.Max());
     Assert.Equal(decimal.MaxValue, thousand.Concat(Enumerable.Repeat(decimal.MaxValue, 1)).Max());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<decimal>().Max());
 }
示例#6
0
 public void MaxInt64WithSelectorAccessingProperty()
 {
     var source = new[]{
         new { name="Tim", num=10L },
         new { name="John", num=-105L },
         new { name="Bob", num=long.MaxValue }
     };
     Assert.Equal(long.MaxValue, source.Max(e => e.num));
 }
示例#7
0
        public void MaxInt32WithSelectorAccessingProperty()
        {
            var source = new[]{
                new { name="Tim", num=10 },
                new { name="John", num=-105 },
                new { name="Bob", num=30 }
            };

            Assert.Equal(30, source.Max(e => e.num));
        }
示例#8
0
 public void MaxDateTime()
 {
     var ten = Enumerable.Range(1, 10).Select(i => new DateTime(2000, 1, i)).ToArray();
     var newYearsEve = new[]
     {
         new DateTime(2000, 12, 1),
         new DateTime(2000, 12, 31),
         new DateTime(2000, 1, 12)
     };
     var threeThousand = new[]
     {
         new DateTime(3000, 1, 1),
         new DateTime(100, 1, 1),
         new DateTime(200, 1, 1),
         new DateTime(1000, 1, 1)
     };
     Assert.Equal(new DateTime(2000, 1, 10), ten.Max());
     Assert.Equal(new DateTime(2000, 12, 31), newYearsEve.Max());
     Assert.Equal(new DateTime(3000, 1, 1), threeThousand.Max());
     Assert.Equal(DateTime.MaxValue, threeThousand.Concat(Enumerable.Repeat(DateTime.MaxValue, 1)).Max());
 }
示例#9
0
 public void MaxNullableDecimal()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (decimal?)i).ToArray();
     var minusTen = new[] { default(decimal?), -100M, -15, -50, -10 };
     var thousand = new[] { default(decimal?), -16M, 0, 50, 100, 1000 };
     Assert.Equal(42M, Enumerable.Repeat((decimal?)42, 1).Max());
     Assert.Equal(10M, ten.Max());
     Assert.Equal(-10M, minusTen.Max());
     Assert.Equal(1000M, thousand.Max());
     Assert.Equal(decimal.MaxValue, thousand.Concat(Enumerable.Repeat((decimal?)decimal.MaxValue, 1)).Max());
 }
示例#10
0
 public void MaxNullableSingle()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (float?)i).ToArray();
     var minusTen = new[] { default(float?), -100F, -15, -50, -10 };
     var thousand = new[] { default(float?), -16F, 0, 50, 100, 1000 };
     Assert.Equal(10F, ten.Max());
     Assert.Equal(-10F, minusTen.Max());
     Assert.Equal(1000F, thousand.Max());
     Assert.Equal(float.MaxValue, thousand.Concat(Enumerable.Repeat((float?)float.MaxValue, 1)).Max());
 }
示例#11
0
 public void MaxDoubleWithSelectorAccessingField()
 {
     var source = new[]{
         new { name="Tim", num=40.5 },
         new { name="John", num=-10.25 },
         new { name="Bob", num=100.45 }
     };
     Assert.Equal(100.45, source.Max(e => e.num));
 }
示例#12
0
 public void MaxDoubleWithSelector()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (double)i).ToArray();
     var minusTen = new[] { -100D, -15, -50, -10 };
     var thousand = new[] { -16D, 0, 50, 100, 1000 };
     Assert.Equal(42D, Enumerable.Repeat(42D, 1).Max(x => x));
     Assert.Equal(10D, ten.Max(x => x));
     Assert.Equal(-10D, minusTen.Max(x => x));
     Assert.Equal(1000D, thousand.Max(x => x));
     Assert.Equal(double.MaxValue, thousand.Concat(Enumerable.Repeat(double.MaxValue, 1)).Max(x => x));
 }
        public void should_get_maximum_element_using_max()
        {
            var sequence = new[] { 1, 2, 3, 4, 5 };

            int maxNumber = sequence.Max();

            // please update variable value to fix the test.
            const int expectedMaxNumber = 0;

            Assert.Equal(expectedMaxNumber, maxNumber);
        }
示例#14
0
 public void MaxDateTimeWithSelector()
 {
     var ten = Enumerable.Range(1, 10).Select(i => new DateTime(2000, 1, i)).ToArray();
     var newYearsEve = new[]
     {
         new DateTime(2000, 12, 1),
         new DateTime(2000, 12, 31),
         new DateTime(2000, 1, 12)
     };
     var threeThousand = new[]
     {
         new DateTime(3000, 1, 1),
         new DateTime(100, 1, 1),
         new DateTime(200, 1, 1),
         new DateTime(1000, 1, 1)
     };
     Assert.Equal(new DateTime(2000, 1, 10), ten.Max(x => x));
     Assert.Equal(new DateTime(2000, 12, 31), newYearsEve.Max(x => x));
     Assert.Equal(new DateTime(3000, 1, 1), threeThousand.Max(x => x));
     Assert.Equal(DateTime.MaxValue, threeThousand.Concat(Enumerable.Repeat(DateTime.MaxValue, 1)).Max(x => x));
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<DateTime>().Max(x => x));
 }
示例#15
0
 public void NaNFirstSingleWithSelector()
 {
     var nanThenOne = Enumerable.Range(1, 10).Select(i => (float)i).Concat(Enumerable.Repeat(float.NaN, 1)).ToArray();
     var nanThenMinusTen = new[] { -1F, -10, float.NaN, 10, 200, 1000 };
     var nanThenMinValue = new[] { float.MinValue, 3000F, 100, 200, float.NaN, 1000 };
     Assert.False(float.IsNaN(nanThenOne.Max(x => x)));
     Assert.False(float.IsNaN(nanThenMinusTen.Max(x => x)));
     Assert.False(float.IsNaN(nanThenMinValue.Max(x => x)));
     var nanWithNull = new[] { default(float?), float.NaN, default(float?) };
     Assert.True(float.IsNaN(nanWithNull.Max(x => x).Value));
 }
示例#16
0
 public void MaxStringWithSelectorAccessingProperty()
 {
     var source = new[]{
         new { name="Tim", num=420.5m },
         new { name="John", num=900.25m },
         new { name="Bob", num=10.45m }
     };
     Assert.Equal("Tim", source.Max(e => e.name));
 }
示例#17
0
 public void MaxDecimalWithSelector()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (decimal)i).ToArray();
     var minusTen = new[] { -100M, -15, -50, -10 };
     var thousand = new[] { -16M, 0, 50, 100, 1000 };
     Assert.Equal(42M, Enumerable.Repeat(42M, 1).Max(x => x));
     Assert.Equal(10M, ten.Max(x => x));
     Assert.Equal(-10M, minusTen.Max(x => x));
     Assert.Equal(1000M, thousand.Max(x => x));
     Assert.Equal(decimal.MaxValue, thousand.Concat(Enumerable.Repeat(decimal.MaxValue, 1)).Max(x => x));
 }
示例#18
0
 public void MaxNullableInt64()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (long?)i).ToArray();
     var minusTen = new[] { default(long?), -100L, -15, -50, -10 };
     var thousand = new[] { default(long?), -16L, 0, 50, 100, 1000 };
     Assert.Equal(10, ten.Max());
     Assert.Equal(-10, minusTen.Max());
     Assert.Equal(1000, thousand.Max());
     Assert.Equal(long.MaxValue, thousand.Concat(Enumerable.Repeat((long?)long.MaxValue, 1)).Max());
     Assert.Null(Enumerable.Repeat(default(long?), 100).Max());
 }
示例#19
0
 public void MaxNullableInt32WithSelector()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (int?)i).ToArray();
     var minusTen = new[] { default(int?), -100, -15, -50, -10 };
     var thousand = new[] { default(int?), -16, 0, 50, 100, 1000 };
     Assert.Equal(42, Enumerable.Repeat((int?)42, 1).Max(x => x));
     Assert.Equal(10, ten.Max(x => x));
     Assert.Equal(-10, minusTen.Max(x => x));
     Assert.Equal(1000, thousand.Max(x => x));
     Assert.Equal(int.MaxValue, thousand.Concat(Enumerable.Repeat((int?)int.MaxValue, 1)).Max(x => x));
     Assert.Null(Enumerable.Repeat(default(int?), 100).Max(x => x));
 }
示例#20
0
 public void MaxNullableDouble()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (double?)i).ToArray();
     var minusTen = new[] { default(double?), -100D, -15, -50, -10 };
     var thousand = new[] { default(double?), -16D, 0, 50, 100, 1000 };
     Assert.Equal(10D, ten.Max());
     Assert.Equal(-10D, minusTen.Max());
     Assert.Equal(1000D, thousand.Max());
     Assert.Equal(double.MaxValue, thousand.Concat(Enumerable.Repeat((double?)double.MaxValue, 1)).Max());
 }
示例#21
0
        public void MaxNullableInt32WithSelectorAccessingField()
        {
            var source = new[]{
                new { name="Tim", num=(int?)10 },
                new { name="John", num=(int?)-105 },
                new { name="Bob", num=(int?)null }
            };

            Assert.Equal(10, source.Max(e => e.num));
        }
示例#22
0
 public void NaNFirstDouble()
 {
     var nanThenOne = Enumerable.Range(1, 10).Select(i => (double)i).Concat(Enumerable.Repeat(double.NaN, 1)).ToArray();
     var nanThenMinusTen = new[] { -1F, -10, double.NaN, 10, 200, 1000 };
     var nanThenMinValue = new[] { double.MinValue, 3000F, 100, 200, double.NaN, 1000 };
     Assert.False(double.IsNaN(nanThenOne.Max()));
     Assert.False(double.IsNaN(nanThenMinusTen.Max()));
     Assert.False(double.IsNaN(nanThenMinValue.Max()));
     var nanWithNull = new[] { default(double?), double.NaN, default(double?) };
     Assert.True(double.IsNaN(nanWithNull.Max().Value));
 }
示例#23
0
 public void MaxNullableInt64WithSelectorAccessingField()
 {
     var source = new[]{
         new {name="Tim", num=default(long?) },
         new {name="John", num=(long?)-105L },
         new {name="Bob", num=(long?)long.MaxValue }
     };
     Assert.Equal(long.MaxValue, source.Max(e => e.num));
 }
示例#24
0
 public void MaxString()
 {
     var nine = Enumerable.Range(1, 10).Select(i => i.ToString()).ToArray();
     var agents = new[] { "Alice", "Bob", "Charlie", "Eve", "Mallory", "Victor", "Trent" };
     var confusedAgents = new[] { null, "Charlie", null, "Victor", "Trent", null, "Eve", "Alice", "Mallory", "Bob" };
     Assert.Equal("9", nine.Max());
     Assert.Equal("Victor", agents.Max());
     Assert.Equal("Victor", confusedAgents.Max());
 }
示例#25
0
 public void MaxNullableSingleWithSelectorAccessingProperty()
 {
     var source = new[]
     {
         new { name="Tim", num=(float?)40.5f },
         new { name="John", num=(float?)null },
         new { name="Bob", num=(float?)100.45f }
     };
     Assert.Equal(100.45f, source.Max(e => e.num));
 }
示例#26
0
 public void MaxInt64WithSelector()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (long)i).ToArray();
     var minusTen = new[] { -100L, -15, -50, -10 };
     var thousand = new[] { -16L, 0, 50, 100, 1000 };
     Assert.Equal(42, Enumerable.Repeat(42L, 1).Max(x => x));
     Assert.Equal(10, ten.Max(x => x));
     Assert.Equal(-10, minusTen.Max(x => x));
     Assert.Equal(1000, thousand.Max(x => x));
     Assert.Equal(long.MaxValue, thousand.Concat(Enumerable.Repeat(long.MaxValue, 1)).Max(x => x));
 }
示例#27
0
 public void MaxNullableDoubleWithSelectorAccessingProperty()
 {
     var source = new []{
         new { name = "Tim", num = (double?)40.5},
         new { name = "John", num = default(double?)},
         new { name = "Bob", num = (double?)100.45}
     };
     Assert.Equal(100.45, source.Max(e => e.num));
 }
示例#28
0
 public void MaxSingleWithSelector()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (float)i).ToArray();
     var minusTen = new[] { -100F, -15, -50, -10 };
     var thousand = new[] { -16F, 0, 50, 100, 1000 };
     Assert.Equal(42F, Enumerable.Repeat(42F, 1).Max(x => x));
     Assert.Equal(10F, ten.Max(x => x));
     Assert.Equal(-10F, minusTen.Max(x => x));
     Assert.Equal(1000F, thousand.Max(x => x));
     Assert.Equal(float.MaxValue, thousand.Concat(Enumerable.Repeat(float.MaxValue, 1)).Max(x => x));
 }
示例#29
0
 public void MaxNullableDecimalWithSelectorAccessingProperty()
 {
     var source = new[] {
         new { name="Tim", num=(decimal?)420.5m },
         new { name="John", num=default(decimal?) },
         new { name="Bob", num=(decimal?)10.45m }
     };
     Assert.Equal(420.5m, source.Max(e => e.num));
 }