MaxTest.cs 996 B

123456789101112131415161718192021222324252627282930313233343536
  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.Text;
  7. using System.Linq;
  8. using Xunit;
  9. namespace Tests
  10. {
  11. public class MaxTest : Tests
  12. {
  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 Max()
  21. {
  22. Assert.Equal(5, new[] { 2, 5, 3, 7 }.Max(new Mod7Comparer()));
  23. }
  24. private 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. }
  32. }