Exemplo n.º 1
0
 public void MinInt32()
 {
     var one = Enumerable.Range(1, 10).ToArray();
     var minusTen = new[] { -1, -10, 10, 200, 1000 };
     var hundred = new[] { 3000, 100, 200, 1000 };
     Assert.Equal(1, one.Min());
     Assert.Equal(-10, minusTen.Min());
     Assert.Equal(100, hundred.Min());
     Assert.Equal(int.MinValue, one.Concat(Enumerable.Repeat(int.MinValue, 1)).Min());
 }
Exemplo n.º 2
0
 public void MinInt64()
 {
     var one = Enumerable.Range(1, 10).Select(i => (long)i).ToArray();
     var minusTen = new[] { -1L, -10, 10, 200, 1000 };
     var hundred = new[] { 3000L, 100, 200, 1000 };
     Assert.Equal(42, Enumerable.Repeat(42L, 1).Min());
     Assert.Equal(1, one.Min());
     Assert.Equal(-10, minusTen.Min());
     Assert.Equal(100, hundred.Min());
     Assert.Equal(long.MinValue, one.Concat(Enumerable.Repeat(long.MinValue, 1)).Min());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<long>().Min());
 }
Exemplo n.º 3
0
 public void MinSingle()
 {
     var one = Enumerable.Range(1, 10).Select(i => (float)i).ToArray();
     var minusTen = new[] { -1F, -10, 10, 200, 1000 };
     var hundred = new[] { 3000F, 100, 200, 1000 };
     Assert.Equal(42F, Enumerable.Repeat(42F, 1).Min());
     Assert.Equal(1L, one.Min());
     Assert.Equal(-10L, minusTen.Min());
     Assert.Equal(100L, hundred.Min());
     Assert.Equal(float.MinValue, one.Concat(Enumerable.Repeat(float.MinValue, 1)).Min());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<float>().Min());
 }
Exemplo n.º 4
0
 public void MinInt32()
 {
     var one = Enumerable.Range(1, 10).ToArray();
     var minusTen = new[] { -1, -10, 10, 200, 1000 };
     var hundred = new[] { 3000, 100, 200, 1000 };
     Assert.Equal(42, Enumerable.Repeat(42, 1).Min());
     Assert.Equal(1, one.Min());
     Assert.Equal(-10, minusTen.Min());
     Assert.Equal(100, hundred.Min());
     Assert.Equal(int.MinValue, one.Concat(Enumerable.Repeat(int.MinValue, 1)).Min());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<int>().Min());
 }
Exemplo n.º 5
0
 public void MinString()
 {
     var one = Enumerable.Range(1, 10).Select(i => i.ToString()).ToArray();
     var agents = new[] { "Alice", "Bob", "Charlie", "Eve", "Mallory", "Trent", "Victor"};
     var confusedAgents = new[] { null, "Charlie", null, "Victor", "Trent", null, "Eve", "Alice", "Mallory", "Bob" };
     Assert.Equal("1", one.Min());
     Assert.Equal("Alice", agents.Min());
     Assert.Equal("Alice", confusedAgents.Min());
 }
Exemplo n.º 6
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.True(double.IsNaN(nanThenOne.Min()));
     Assert.True(double.IsNaN(nanThenMinusTen.Min()));
     Assert.True(double.IsNaN(nanThenMinValue.Min()));
     var nanWithNull = new[] { default(double?), double.NaN, default(double?) };
     Assert.True(double.IsNaN(nanWithNull.Min().Value));
 }
Exemplo n.º 7
0
 public void MinDateTime()
 {
     var one = Enumerable.Range(1, 10).Select(i => new DateTime(2000, 1, i)).ToArray();
     var newYears = new[]
     {
         new DateTime(2000, 12, 1),
         new DateTime(2000, 1, 1),
         new DateTime(2000, 1, 12)
     };
     var hundred = new[]
     {
         new DateTime(3000, 1, 1),
         new DateTime(100, 1, 1),
         new DateTime(200, 1, 1),
         new DateTime(1000, 1, 1)
     };
     Assert.Equal(DateTime.MinValue, one.Concat(Enumerable.Repeat(DateTime.MinValue, 1)).Min());
     Assert.Equal(new DateTime(2000, 1, 1), one.Min());
     Assert.Equal(new DateTime(2000, 1, 1), newYears.Min());
     Assert.Equal(new DateTime(100, 1, 1), hundred.Min());
 }
Exemplo n.º 8
0
 public void MinDouble()
 {
     var one = Enumerable.Range(1, 10).Select(i => (double)i).ToArray();
     var minusTen = new[] { -1D, -10, 10, 200, 1000 };
     var hundred = new[] { 3000D, 100, 200, 1000 };
     Assert.Equal(42D, Enumerable.Repeat(42D, 1).Min());
     Assert.Equal(1D, one.Min());
     Assert.Equal(-10D, minusTen.Min());
     Assert.Equal(100D, hundred.Min());
     Assert.Equal(double.MinValue, one.Concat(Enumerable.Repeat(double.MinValue, 1)).Min());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<double>().Min());
 }
Exemplo n.º 9
0
 public void MinNullableDecimal()
 {
     var one = Enumerable.Range(1, 10).Select(i => (decimal?)i).ToArray();
     var minusTen = new[] { default(decimal?), -1M, -10, 10, 200, 1000 };
     var hundred = new[] { default(decimal?), 3000M, 100, 200, 1000 };
     Assert.Equal(1M, one.Min());
     Assert.Equal(-10M, minusTen.Min());
     Assert.Equal(100M, hundred.Min());
     Assert.Equal(decimal.MinValue, one.Concat(Enumerable.Repeat((decimal?)decimal.MinValue, 1)).Min());
 }
Exemplo n.º 10
0
 public void Min_Int_WithSelectorAccessingProperty()
 {
     var source = new[]
     {
         new { name="Tim", num=10 },
         new { name="John", num=-105 },
         new { name="Bob", num=-30 }
     };
     Assert.Equal(-105, source.Min(e => e.num));
 }
Exemplo n.º 11
0
 public void Min_Double_WithSelectorAccessingProperty()
 {
     var source = new[]
     {
         new { name="Tim", num=-45.5 },
         new { name="John", num=-132.5 },
         new { name="Bob", num=20.45 }
     };
     Assert.Equal(-132.5, source.Min(e => e.num));
 }
Exemplo n.º 12
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.True(float.IsNaN(nanThenOne.Min(x => x)));
     Assert.True(float.IsNaN(nanThenMinusTen.Min(x => x)));
     Assert.True(float.IsNaN(nanThenMinValue.Min(x => x)));
     var nanWithNull = new[] { default(float?), float.NaN, default(float?) };
     Assert.True(float.IsNaN(nanWithNull.Min(x => x).Value));
 }
Exemplo n.º 13
0
 public void MinDouble()
 {
     var one = Enumerable.Range(1, 10).Select(i => (double)i).ToArray();
     var minusTen = new[] { -1D, -10, 10, 200, 1000 };
     var hundred = new[] { 3000D, 100, 200, 1000 };
     Assert.Equal(1D, one.Min());
     Assert.Equal(-10D, minusTen.Min());
     Assert.Equal(100D, hundred.Min());
     Assert.Equal(double.MinValue, one.Concat(Enumerable.Repeat(double.MinValue, 1)).Min());
 }
Exemplo n.º 14
0
        public void MinNullableSingleWithSelectorAccessingProperty()
        {
            var source = new[]{
                new {name="Tim", num=(float?)-45.5f},
                new {name="John", num=(float?)-132.5f},
                new {name="Bob", num=default(float?)}
            };

            Assert.Equal(-132.5f, source.Min(e => e.num));
        }
Exemplo n.º 15
0
 public void MinNullableDoubleWithSelector()
 {
     var one = Enumerable.Range(1, 10).Select(i => (double?)i).ToArray();
     var minusTen = new[] { default(double?), -1D, -10, 10, 200, 1000 };
     var hundred = new[] { default(double?), 3000D, 100, 200, 1000 };
     Assert.Equal(42D, Enumerable.Repeat((double?)42, 1).Min(x => x));
     Assert.Equal(1D, one.Min(x => x));
     Assert.Equal(-10D, minusTen.Min(x => x));
     Assert.Equal(100D, hundred.Min(x => x));
     Assert.Equal(double.MinValue, one.Concat(Enumerable.Repeat((double?)double.MinValue, 1)).Min(x => x));
     Assert.Null(Enumerable.Empty<double?>().Min(x => x));
     Assert.Null(Enumerable.Repeat(default(double?), 100).Min(x => x));
 }
Exemplo n.º 16
0
 public void MinNullableInt32WithSelector()
 {
     var one = Enumerable.Range(1, 10).Select(i => (int?)i).ToArray();
     var minusTen = new[] { default(int?), -1, -10, 10, 200, 1000 };
     var hundred = new[] { default(int?), 3000, 100, 200, 1000 };
     Assert.Equal(42, Enumerable.Repeat((int?)42, 1).Min(x => x));
     Assert.Equal(1, one.Min(x => x));
     Assert.Equal(-10, minusTen.Min(x => x));
     Assert.Equal(100, hundred.Min(x => x));
     Assert.Null(Enumerable.Empty<int?>().Min(x => x));
     Assert.Equal(int.MinValue, one.Concat(Enumerable.Repeat((int?)int.MinValue, 1)).Min(x => x));
     Assert.Null(Enumerable.Repeat(default(int?), 100).Min(x => x));
 }
Exemplo n.º 17
0
 public void MinDecimalWithSelector()
 {
     var one = Enumerable.Range(1, 10).Select(i => (decimal)i).ToArray();
     var minusTen = new[] { -1M, -10, 10, 200, 1000 };
     var hundred = new[] { 3000M, 100, 200, 1000 };
     Assert.Equal(42M, Enumerable.Repeat(42M, 1).Min(x => x));
     Assert.Equal(1M, one.Min(x => x));
     Assert.Equal(-10M, minusTen.Min(x => x));
     Assert.Equal(100M, hundred.Min(x => x));
     Assert.Equal(decimal.MinValue, one.Concat(Enumerable.Repeat(decimal.MinValue, 1)).Min(x => x));
 }
Exemplo n.º 18
0
        public void should_get_minimum_element_using_min()
        {
            var sequence = new[] { 1, 2, 3, 4, 5 };

            int minNumber = sequence.Min();

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

            Assert.Equal(expectedMinNumber, minNumber);
        }
Exemplo n.º 19
0
 public void MinInt64WithSelector()
 {
     var one = Enumerable.Range(1, 10).Select(i => (long)i).ToArray();
     var minusTen = new[] { -1L, -10, 10, 200, 1000 };
     var hundred = new[] { 3000L, 100, 200, 1000 };
     Assert.Equal(42, Enumerable.Repeat(42L, 1).Min(x => x));
     Assert.Equal(1, one.Min(x => x));
     Assert.Equal(-10, minusTen.Min(x => x));
     Assert.Equal(100, hundred.Min(x => x));
     Assert.Equal(long.MinValue, one.Concat(Enumerable.Repeat(long.MinValue, 1)).Min(x => x));
 }
Exemplo n.º 20
0
 public void Min_NullableLong_WithSelectorAccessingProperty()
 {
     var source = new[]
     {
         new { name="Tim", num=default(long?) },
         new { name="John", num=(long?)long.MinValue },
         new { name="Bob", num=(long?)-10L }
     };
     Assert.Equal(long.MinValue, source.Min(e => e.num));
 }
Exemplo n.º 21
0
 public void MinSingleWithSelector()
 {
     var one = Enumerable.Range(1, 10).Select(i => (float)i).ToArray();
     var minusTen = new[] { -1F, -10, 10, 200, 1000 };
     var hundred = new[] { 3000F, 100, 200, 1000 };
     Assert.Equal(42F, Enumerable.Repeat(42F, 1).Min(x => x));
     Assert.Equal(1L, one.Min(x => x));
     Assert.Equal(-10L, minusTen.Min(x => x));
     Assert.Equal(100L, hundred.Min(x => x));
     Assert.Equal(float.MinValue, one.Concat(Enumerable.Repeat(float.MinValue, 1)).Min(x => x));
 }
Exemplo n.º 22
0
 public void Min_NullableDecimal_WithSelectorAccessingProperty()
 {
     var source = new[]
     {
         new { name="Tim", num=(decimal?)100.45m },
         new { name="John", num=(decimal?)10.5m },
         new { name="Bob", num=default(decimal?) }
     };
     Assert.Equal(10.5m, source.Min(e => e.num));
 }
Exemplo n.º 23
0
        public void Min_Long_WithSelectorAccessingProperty()
        {
            var source = new[]
            {
                new { name="Tim", num=10L },
                new { name="John", num=long.MinValue },
                new { name="Bob", num=-10L }
            };

            Assert.Equal(long.MinValue, source.Min(e => e.num));
        }
Exemplo n.º 24
0
 public void MinDecimal()
 {
     var one = Enumerable.Range(1, 10).Select(i => (decimal)i).ToArray();
     var minusTen = new[] { -1M, -10, 10, 200, 1000 };
     var hundred = new[] { 3000M, 100, 200, 1000 };
     Assert.Equal(42M, Enumerable.Repeat(42M, 1).Max());
     Assert.Equal(1M, one.Min());
     Assert.Equal(-10M, minusTen.Min());
     Assert.Equal(100M, hundred.Min());
     Assert.Equal(decimal.MinValue, one.Concat(Enumerable.Repeat(decimal.MinValue, 1)).Min());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<decimal>().Min());
 }
Exemplo n.º 25
0
 public void Min_NullableInt_WithSelectorAccessingProperty()
 {
     var source = new[]
     {
         new { name="Tim", num=(int?)10 },
         new { name="John", num=default(int?) },
         new { name="Bob", num=(int?)-30 }
     };
     Assert.Equal(-30, source.Min(e => e.num));
 }
Exemplo n.º 26
0
 public void MinDateTimeWithSelector()
 {
     var one = Enumerable.Range(1, 10).Select(i => new DateTime(2000, 1, i)).ToArray();
     var newYears = new[]
     {
         new DateTime(2000, 12, 1),
         new DateTime(2000, 1, 1),
         new DateTime(2000, 1, 12)
     };
     var hundred = new[]
     {
         new DateTime(3000, 1, 1),
         new DateTime(100, 1, 1),
         new DateTime(200, 1, 1),
         new DateTime(1000, 1, 1)
     };
     Assert.Equal(DateTime.MinValue, one.Concat(Enumerable.Repeat(DateTime.MinValue, 1)).Min(x => x));
     Assert.Equal(new DateTime(2000, 1, 1), one.Min(x => x));
     Assert.Equal(new DateTime(2000, 1, 1), newYears.Min(x => x));
     Assert.Equal(new DateTime(100, 1, 1), hundred.Min(x => x));
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<DateTime>().Min(x => x));
 }
Exemplo n.º 27
0
 public void Min_NullableDouble_WithSelectorAccessingProperty()
 {
     var source = new[]
     {
         new { name="Tim", num=(double?)-45.5 },
         new { name="John", num=(double?)-132.5 },
         new { name="Bob", num=default(double?) }
     };
     Assert.Equal(-132.5, source.Min(e => e.num));
 }
Exemplo n.º 28
0
 public void MinNullableInt64()
 {
     var one = Enumerable.Range(1, 10).Select(i => (long?)i).ToArray();
     var minusTen = new[] { default(long?), -1L, -10, 10, 200, 1000 };
     var hundred = new[] { default(long?), 3000L, 100, 200, 1000 };
     Assert.Equal(1, one.Min());
     Assert.Equal(-10, minusTen.Min());
     Assert.Equal(100, hundred.Min());
     Assert.Equal(long.MinValue, one.Concat(Enumerable.Repeat((long?)long.MinValue, 1)).Min());
 }
Exemplo n.º 29
0
 public void Min_String_WithSelectorAccessingProperty()
 {
     var source = new[]
     {
         new { name="Tim", num=100.45m },
         new { name="John", num=10.5m },
         new { name="Bob", num=0.05m }
     };
     Assert.Equal("Bob", source.Min(e => e.name));
 }
Exemplo n.º 30
0
 public void MinNullableSingle()
 {
     var one = Enumerable.Range(1, 10).Select(i => (float?)i).ToArray();
     var minusTen = new[] { default(float?), -1F, -10, 10, 200, 1000 };
     var hundred = new[] { default(float?), 3000F, 100, 200, 1000 };
     Assert.Equal(1F, one.Min());
     Assert.Equal(-10F, minusTen.Min());
     Assert.Equal(100F, hundred.Min());
     Assert.Equal(float.MinValue, one.Concat(Enumerable.Repeat((float?)float.MinValue, 1)).Min());
 }