Abstract Sort Test Algorithm
The Abstract Sort Test Algorithm (ASTA) is a generalized sorting algorithm that serves as a framework for assessing and comparing the performance of various sorting algorithms. It is designed to provide a common ground for evaluating different sorting techniques by outlining the necessary components to perform sorting while allowing for the implementation of specific sorting strategies. The main goal of the ASTA is to help developers and researchers identify the most efficient sorting algorithm for a particular use case or dataset, taking into account factors such as time complexity, space complexity, and adaptability to different data types.
In order to use the Abstract Sort Test Algorithm, a developer must first implement a specific sorting algorithm that adheres to the framework set by the ASTA. Once the sorting algorithm is implemented, the developer can then run a series of tests on various datasets to measure the performance of the algorithm. These tests usually involve analyzing the time taken by the algorithm to sort the dataset, the memory consumed by the algorithm during the sorting process, and its ability to handle different types of data. By comparing the performance of different sorting algorithms using the ASTA, developers can identify the best sorting technique for their specific application, leading to more efficient and optimized software solutions.
/*
* Copyright (c) 2017 Kotlin Algorithm Club
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.algorithmexamples.sorts
import org.junit.Assert
import org.junit.Test
abstract class AbstractSortTest<out T: AbstractSortStrategy>(val strategy: T) {
@Test
fun emptyTest() {
val arr = arrayOf<Int>()
strategy.perform(arr)
Assert.assertArrayEquals(arrayOf<Int>(), arr)
}
@Test
fun singletonTest() {
val arr = arrayOf(1)
strategy.perform(arr)
Assert.assertArrayEquals(arrayOf(1), arr)
}
@Test
fun twoElementsInOrderTest() {
val arr = arrayOf(42, 43)
strategy.perform(arr)
Assert.assertArrayEquals(arrayOf(42, 43), arr)
}
@Test
fun twoElementsOutOfOrderTest() {
val arr = arrayOf(43, 42)
strategy.perform(arr)
Assert.assertArrayEquals(arrayOf(42, 43), arr)
}
@Test
fun twoElementsEqualTest() {
val arr = arrayOf(42, 42)
strategy.perform(arr)
Assert.assertArrayEquals(arrayOf(42, 42), arr)
}
@Test
fun tenElementsReverseTest() {
val arr = arrayOf(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
strategy.perform(arr)
Assert.assertArrayEquals(arrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), arr)
}
@Test
fun tenElementsTest() {
val arr = arrayOf(3, 2, 7, 6, 1, 8, 10, 9, 4, 5)
strategy.perform(arr)
Assert.assertArrayEquals(arrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), arr)
}
}