Compression Test Algorithm

The Compression Test Algorithm is a technique used to measure the randomness or the complexity of a given dataset, such as a string of numbers, text, or other data formats. It is based on the idea that a dataset can be considered random if it cannot be compressed into a smaller representation without any loss of information. This method works by compressing the input dataset using a compression algorithm, such as Lempel-Ziv, Huffman coding, or run-length encoding, and analyzing the resulting compressed size in comparison to the original dataset size. If the compressed size is significantly smaller than the original size, the data is considered less random or less complex, whereas if the compressed size is similar to or larger than the original size, the data is considered more random or more complex. The Compression Test Algorithm is widely used in various applications, including data compression, pattern recognition, cryptography, and information theory. For instance, in machine learning, the algorithm can be used as a feature selection technique to identify and eliminate redundant or irrelevant features from the dataset, thereby improving the model's performance. Additionally, in cryptography, the randomness of a cryptographic key or a pseudo-random number generator can be assessed using the Compression Test Algorithm, ensuring the security and robustness of the encryption scheme. Overall, the Compression Test Algorithm serves as a valuable tool for analyzing and understanding the inherent structure and complexity of diverse data sources.
import compression.runLengthEncoding
import org.jetbrains.spek.api.Spek
import org.junit.Assert.*

/**
 * Spek BDD test for Run Length Encoding
 */
class RunLengthEncodingTest: Spek({
    given("Empty String"){
        it("Returns Empty String"){
            assertEquals("",runLengthEncoding(""))
        }
    }
    given("Single character"){
        it("Returns 1A"){
            assertEquals("1B",runLengthEncoding("B"))
        }
    }
    given("All same Character"){
        it("It returns 5A"){
            assertEquals("5A",runLengthEncoding("AAAAA"))
        }
    }
    given("A mix of characters then "){
        it("It returns expected encoding"){
            assertEquals("5A3B4C2A",runLengthEncoding("AAAAABBBCCCCAA"))
        }
    }
    given("A longer string then "){
        it("It returns expected encoding without overflow"){
            assertEquals("5A3B4C7A3B4C7A3B4C7A3B4C7A3B4C7A3B4C7A3B4C7A3B4C7A3B4C2A",
                    runLengthEncoding("AAAAABBBCCCCAAAAAAABBBCCCCAAAAAAABBBCCCCAAAAAAABBBCCCCAAAAAAABBBCCCCAAAAAAABBBCCCCAAAAAAABBBCCCCAAAAAAABBBCCCCAAAAAAABBBCCCCAA"))
        }
    }
})

LANGUAGE:

DARK MODE: