Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
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();
        }
Beispiel #3
0
 public static bool operator !=(Card card1, ICard card2) => !CardUtilities.IsEqual(card1, card2);
Beispiel #4
0
 public static bool operator <=(Card card1, ICard card2) => !CardUtilities.IsGreater(card1, card2);
Beispiel #5
0
 public static bool operator >=(Card card1, ICard card2) => !CardUtilities.IsLesser(card1, card2);
Beispiel #6
0
 public static bool operator ==(OptimizedCard card1, ICard card2) => CardUtilities.IsEqual(card1, card2);
Beispiel #7
0
 public static bool operator <(OptimizedCard card1, ICard card2) => CardUtilities.IsLesser(card1, card2);
Beispiel #8
0
 public static bool operator >(OptimizedCard card1, ICard card2) => CardUtilities.IsGreater(card1, card2);
Beispiel #9
0
 public int CompareTo([AllowNull] ICard other)
 {
     CardUtilities.CountComparison();
     return(_value.CompareTo(GetUnderlyingValue(other) ?? 0));
 }