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