Min.cs 978 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using Xunit;
  8. namespace Tests
  9. {
  10. public class Min : Tests
  11. {
  12. [Fact]
  13. public void Min_Arguments()
  14. {
  15. AssertThrows<ArgumentNullException>(() => EnumerableEx.Min(null, Comparer<int>.Default));
  16. AssertThrows<ArgumentNullException>(() => EnumerableEx.Min(new[] { 1 }, null));
  17. }
  18. [Fact]
  19. public void Min1()
  20. {
  21. Assert.Equal(3, new[] { 5, 3, 7 }.Min(new Mod3Comparer()));
  22. }
  23. private sealed class Mod3Comparer : IComparer<int>
  24. {
  25. public int Compare(int x, int y)
  26. {
  27. return Comparer<int>.Default.Compare(x % 3, y % 3);
  28. }
  29. }
  30. }
  31. }