package ie.lyit.adt.assignment.algorithms;

import ie.lyit.adt.assignment.algorithms.implementations.MergeSort;

/**
 * Merge sort test runner
 * 
 * @author markus.korbel@lyit.ie
 * 
 */
public class MergeSortRunner implements SortingAlgorithmTestRunner {
	/**
	 * Sort the specified integer array and time the result
	 * 
	 * @param arrayToSort
	 *            The array to sort
	 * @return The number of milliseconds required for the sort
	 */
	@Override
	public long sortIntegerArrayTimed(int[] arrayToSort) {
		long start = System.currentTimeMillis();
		MergeSort.mergeSortInt(arrayToSort);
		return System.currentTimeMillis() - start;
	}

	/**
	 * Sort the specified integer array and count the number of
	 * comparisons/swaps
	 * 
	 * @param arrayToSort
	 *            The array to sort
	 * @return The counting result
	 */
	@Override
	public CountingResult sortIntegerArrayCounting(int[] arrayToSort) {
		MergeSort.comps = 0;
		MergeSort.swaps = 0;
		MergeSort.mergeSortIntCounting(arrayToSort);
		return new CountingResult(MergeSort.comps, MergeSort.swaps);
	}
}
