Example #1
0
        public static void JudgeTemp(ComparisonHandler comparisonMethod)
        {
            Console.WriteLine($"设定水温为{StandardTemp}");
            Console.WriteLine($"目前水温为:{NowTemp}");

            Console.WriteLine(comparisonMethod(StandardTemp, NowTemp) ? "高于设定温度" : "低于设定温度");
        }
Example #2
0
        public static void SampleSort(int[] items, ComparisonHandler comparisonHandler)
        {
            int i;
            int j;
            int temp;

            if (comparisonHandler == null)
            {
                throw new ArgumentException("comparsionMethod");
            }

            if (items == null)
            {
                return;
            }

            for (i = 0; i <= items.Length; i++)
            {
                for (j = i + 1; j < items.Length; j++)
                {
                    if (comparisonHandler(items[i], items[j]))
                    {
                        temp     = items[i];
                        items[i] = items[j];
                        items[j] = temp;
                    }
                }
            }
        }
Example #3
0
        public static void BubbleSort(int[] items, ComparisonHandler comparisonMethod)
        {
            if (comparisonMethod == null)
            {
                throw new DelegateNullException();
            }


            if (items == null)
            {
                return;
            }

            for (int i = 0; i < items.Length; i++)
            {
                for (int j = i; j < items.Length; j++)
                {
                    if (comparisonMethod(items[i], items[j]))
                    {
                        int temp = items[j];
                        items[j] = items[i];
                        items[i] = temp;
                    }
                }
            }
        }
Example #4
0
        public static void BubbleSort(
            int[] items, ComparisonHandler comparisonMethod)
        {
            int i;
            int j;
            int temp;

            if (items == null)
            {
                return;
            }
            if (comparisonMethod == null)
            {
                throw new ArgumentNullException("comparisonMethod");
            }

            for (i = items.Length - 1; i >= 0; i--)
            {
                for (j = 1; j <= i; j++)
                {
                    if (comparisonMethod(items[j - 1], items[j]))
                    {
                        temp         = items[j - 1];
                        items[j - 1] = items[j];
                        items[j]     = temp;
                    }
                }
            }
        }
Example #5
0
        static void selectionSort(object[] arr, ComparisonHandler comparison, bool isAscending)
        {
            //pos_min is short for position of min
            int    pos_min;
            object temp;

            for (int i = 0; i < arr.Length - 1; i++)
            {
                pos_min = i;//set pos_min to the current index of array

                for (int j = i + 1; j < arr.Length; j++)
                {
                    if (comparison(arr[j], arr[pos_min], isAscending))
                    {
                        //pos_min will keep track of the index that min is in, this is needed when a swap happens
                        pos_min = j;
                    }
                }

                //if pos_min no longer equals i than a smaller value must have been found, so a swap must occur
                if (pos_min != i)
                {
                    temp         = arr[i];
                    arr[i]       = arr[pos_min];
                    arr[pos_min] = temp;
                }
            }
        }
        public static void BubbleSort(
            int[] items, ComparisonHandler comparisonMethod)
        {
            int i;
            int j;
            int temp;

            if(items == null)
            {
                return;
            }
            if(comparisonMethod == null)
            {
                throw new ArgumentNullException("comparisonMethod");
            }

            for(i = items.Length - 1; i >= 0; i--)
            {
                for(j = 1; j <= i; j++)
                {
                    if(comparisonMethod(items[j - 1], items[j]))
                    {
                        temp = items[j - 1];
                        items[j - 1] = items[j];
                        items[j] = temp;
                    }
                }
            }
        }
        public void ShouldReturnErrorWhenIsInvalid()
        {
            // I'm not informing the consumption for the command, neither the repository for the handler.
            var command = new CreateComparisonCommand();
            var handler = new ComparisonHandler(null);
            var result  = handler.Handle(command);

            Assert.IsTrue(handler.Invalid);
        }
        public void ShouldReturnSuccessWhenIsValid()
        {
            // Valid comparison using the fake repository
            var command = new CreateComparisonCommand();

            command.Consumption = 3500;
            var handler = new ComparisonHandler(new FakeProductRepository());
            var result  = handler.Handle(command);

            Assert.IsTrue(handler.Valid);
        }
        public static void BubbleSort(
            int[] items, ComparisonHandler comparisonMethod)
        {
            int i;
            int j;
            int temp;

            for (i = items.Length - 1; i >= 0; i--)
            {
                for (j = 1; j <= i; j++)
                {
                    if (comparisonMethod(items[j - 1], items[j]))
                    {
                        temp         = items[j - 1];
                        items[j - 1] = items[j];
                        items[j]     = temp;
                    }
                }
            }
        }
        public static void BubbleSort(
            int[] items, ComparisonHandler comparisonMethod)
        {
            int i;
            int j;
            int temp;

            for(i = items.Length - 1; i >= 0; i--)
            {
                for(j = 1; j <= i; j++)
                {
                    if(comparisonMethod(items[j - 1], items[j]))
                    {
                        temp = items[j - 1];
                        items[j - 1] = items[j];
                        items[j] = temp;
                    }
                }
            }
        }
Example #11
0
        public static void BubbleSort(int[] arr, ComparisonHandler ComparisonMethod)
        {
            if (arr == null)
            {
                return;
            }
            int temp = 0;

            for (int i = arr.Length - 1; i >= 0; i--)
            {
                for (int j = 1; j <= i; j++)
                {
                    if (ComparisonMethod(arr[j - 1], arr[j]))
                    {
                        temp       = arr[j - 1];
                        arr[j - 1] = arr[j];
                        arr[j]     = temp;
                    }
                }
            }
        }
 public ComparisonController(ComparisonHandler handler)
 {
     this._handler = handler;
 }