public int CompareTo([AllowNull] ICard other) { CardUtilities.CountComparison(); if (other == null) { return(1); } if (Value > other.Value) { return(1); } else if (Value < other.Value) { return(-1); } else { if (Suit > other.Suit) { return(1); } else if (Suit < other.Suit) { return(-1); } else { return(0); } } }
private static void TestSorter(ICard[] randomSet, ISorter sorter) { _stopwatch.Restart(); var sorted = sorter.Sort(randomSet).ToArray(); Console.WriteLine($"With {sorter} I took {CardUtilities.ComparisonCount:N0} comparison to sort the set. It took {_stopwatch.ElapsedMilliseconds} ms"); ICard previous = null; foreach (var current in sorted) { if (current.CompareTo(previous) < 0) { throw new InvalidOperationException("Something went wrong in the sorting!"); } previous = current; } Console.WriteLine(); CardUtilities.ResetComparisionCount(); }
public static bool operator !=(Card card1, ICard card2) => !CardUtilities.IsEqual(card1, card2);
public static bool operator <=(Card card1, ICard card2) => !CardUtilities.IsGreater(card1, card2);
public static bool operator >=(Card card1, ICard card2) => !CardUtilities.IsLesser(card1, card2);
public static bool operator ==(OptimizedCard card1, ICard card2) => CardUtilities.IsEqual(card1, card2);
public static bool operator <(OptimizedCard card1, ICard card2) => CardUtilities.IsLesser(card1, card2);
public static bool operator >(OptimizedCard card1, ICard card2) => CardUtilities.IsGreater(card1, card2);
public int CompareTo([AllowNull] ICard other) { CardUtilities.CountComparison(); return(_value.CompareTo(GetUnderlyingValue(other) ?? 0)); }