From 5c0b3d55d04fcd8dbc3fdb1fd3de963d7ba41e35 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 11 Feb 2021 21:47:15 +0300 Subject: [PATCH] Add more test cases --- .../Devirtualization/Comparer_get_Default.cs | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/tests/JIT/opt/Devirtualization/Comparer_get_Default.cs b/src/tests/JIT/opt/Devirtualization/Comparer_get_Default.cs index 76f5466412a3a..36dfb4418faf7 100644 --- a/src/tests/JIT/opt/Devirtualization/Comparer_get_Default.cs +++ b/src/tests/JIT/opt/Devirtualization/Comparer_get_Default.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; @@ -61,15 +62,21 @@ private static void Compare_nint(nint a, nint b) => private static void Compare_nuint(nuint a, nuint b) => AssertEquals(a.CompareTo(b), Comparer.Default.Compare(a, b)); - private static void Compare_Enum(MethodImplOptions a, MethodImplOptions b) => + private static void Compare_Enum_Int32(MethodImplOptions a, MethodImplOptions b) => AssertEquals(a.CompareTo(b), Comparer.Default.Compare(a, b)); + private static void Compare_Enum_Byte(Enum_byte a, Enum_byte b) => + AssertEquals(a.CompareTo(b), Comparer.Default.Compare(a, b)); + private static void Compare_String(String a, String b) => AssertEquals(a.CompareTo(b), Comparer.Default.Compare(a, b)); private static void Compare_DateTime(DateTime a, DateTime b) => AssertEquals(a.CompareTo(b), Comparer.Default.Compare(a, b)); + private static void Compare_Struct1(Struct1 a, Struct1 b) => + AssertEquals(a.CompareTo(b), Comparer.Default.Compare(a, b)); + private static void Compare_Int32_Nullable(long? a, long? b) { int actual = Comparer.Default.Compare(a, b); @@ -83,10 +90,9 @@ private static void Compare_Int32_Nullable(long? a, long? b) public static int Main(string[] args) { - ; long[] values = Enumerable.Range(1000, 2000) .Select(i => (long)i) - .Concat(new [] + .Concat(new[] { short.MinValue, short.MinValue + 1, short.MaxValue - 1, short.MaxValue, short.MaxValue + 1, int.MinValue, int.MinValue + 1, int.MaxValue, int.MaxValue - 1, @@ -157,9 +163,17 @@ public static int Main(string[] args) var nuintB = Unsafe.As(ref b); Compare_nuint(nuintA, nuintB); - var enumA = Unsafe.As(ref a); - var enumB = Unsafe.As(ref b); - Compare_Enum(enumA, enumB); + var enumIntA = Unsafe.As(ref a); + var enumIntB = Unsafe.As(ref b); + Compare_Enum_Int32(enumIntA, enumIntB); + + var enumByteA = Unsafe.As(ref a); + var enumByteB = Unsafe.As(ref b); + Compare_Enum_Byte(enumByteA, enumByteB); + + var structA = new Struct1 {a = a, b = b}; + var structB = new Struct1 {a = b, b = a}; + Compare_Struct1(structA, structB); Compare_DateTime( new DateTime(Math.Clamp(a, DateTime.MinValue.Ticks, DateTime.MaxValue.Ticks)), @@ -214,10 +228,17 @@ private static int GetHashCodeTests() } } -public struct Struct1 +public enum Enum_byte : byte +{ + A,B,C,D,E +} + +public struct Struct1 : IComparable { public long a; public long b; - public long c; - public long d; + public int CompareTo(object? obj) + { + return b.CompareTo(((Struct1) obj).b); + } }