Max.cs 1004 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT 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 Max : Tests
  11. {
  12. #if !NET6_0_OR_GREATER
  13. [Fact]
  14. public void Max_Arguments()
  15. {
  16. AssertThrows<ArgumentNullException>(() => EnumerableEx.Max(null, Comparer<int>.Default));
  17. AssertThrows<ArgumentNullException>(() => EnumerableEx.Max(new[] { 1 }, null));
  18. }
  19. [Fact]
  20. public void Max1()
  21. {
  22. Assert.Equal(5, new[] { 2, 5, 3, 7 }.Max(new Mod7Comparer()));
  23. }
  24. private sealed class Mod7Comparer : IComparer<int>
  25. {
  26. public int Compare(int x, int y)
  27. {
  28. return Comparer<int>.Default.Compare(x % 7, y % 7);
  29. }
  30. }
  31. #endif
  32. }
  33. }