<commit_before>
import XCTest

@testable import DataCompression

class CompressionTest: XCTestCase
{
    func testEmptyString()
    {
        XCTAssertEqual("", pray(""))
    }
    
    func testMiscSmall()
    {
        for i in 1...500 {
            let s = String(repeating: "a", count: i)
            XCTAssertEqual(s, pray(s), "Fails with: \(s)")
        }
    }

    func testAsciiNumbers() 
    {
        for i in 1...500 {
            let r = sqrt(Double(i)) / .pi 
            let s = String(repeating: "\(r)", count: i)
            XCTAssertEqual(s, pray(s), "Fails with: \(s)")
        }
    }

    func testRandomDataChunks()
    {
        for i in 1...500 {
            let ints = [UInt32](repeating: 0, count: i).map { _ in arc4random() }
            let data = Data(bytes: ints, count: i)
            XCTAssertEqual(data, comp(data), "Fails with random data :(")
        }
    }

    func testRandomDataBlob()
    {
        let b = 1024 * 1024 * 15 // 15 MB
        let ints = [UInt32](repeating: 0, count: b / 4).map { _ in arc4random() }
        let data = Data(bytes: ints, count: b / 4)
        XCTAssertEqual(data, comp(data), "Fails with random data (\(b) bytes) :(")
    }

    func comp(_ d: Data?) -> Data?
    {
        var tmp: Data? = d

        tmp = tmp?.deflate()
        tmp = tmp?.inflate()

        tmp = tmp?.zip()
        tmp = tmp?.unzip()

        tmp = tmp?.compress(withAlgorithm: .LZFSE)
        tmp = tmp?.decompress(withAlgorithm: .LZFSE)

        tmp = tmp?.compress(withAlgorithm: .LZ4)
        tmp = tmp?.decompress(withAlgorithm: .LZ4)

        tmp = tmp?.compress(withAlgorithm: .LZMA)
        tmp = tmp?.decompress(withAlgorithm: .LZMA)

        tmp = tmp?.compress(withAlgorithm: .ZLIB)
        tmp = tmp?.decompress(withAlgorithm: .ZLIB)

        return tmp
    }

    func pray(_ s: String) -> String?<commit_msg>Faster generation of random numbers for testcases fixed<commit_after>
import XCTest

@testable import DataCompression

class CompressionTest: XCTestCase
{
    func testEmptyString()
    {
        XCTAssertEqual("", pray(""))
    }
    
    func testMiscSmall()
    {
        for i in 1...500 {
            let s = String(repeating: "a", count: i)
            XCTAssertEqual(s, pray(s), "Fails with: \(s)")
        }
    }

    func testAsciiNumbers() 
    {
        for i in 1...500 {
            let r = sqrt(Double(i)) / .pi 
            let s = String(repeating: "\(r)", count: i)
            XCTAssertEqual(s, pray(s), "Fails with: \(s)")
        }
    }

    func testRandomDataChunks()
    {
        for i in 1...500 {
            let ints = [UInt32](repeating: 0, count: 1 + (i / 4)).map { _ in arc4random() }
            let data = Data(bytes: ints, count: i)
            XCTAssertEqual(data, comp(data), "Fails with random data (\(data.count) bytes) :(")
        }
    }

    func testRandomDataBlob()
    {
        let b = 1024 * 1024 * 15 // 15 MB
        let ints = [UInt32](repeating: 0, count: b / 4).map { _ in arc4random() }
        let data = Data(bytes: ints, count: b)
        XCTAssertEqual(data, comp(data), "Fails with random data large blob of 15 MB :(")
    }

    func comp(_ d: Data?) -> Data?
    {
        var tmp: Data? = d

        tmp = tmp?.deflate()
        tmp = tmp?.inflate()

        tmp = tmp?.zip()
        tmp = tmp?.unzip()

        tmp = tmp?.compress(withAlgorithm: .LZFSE)
        tmp = tmp?.decompress(withAlgorithm: .LZFSE)

        tmp = tmp?.compress(withAlgorithm: .LZ4)
        tmp = tmp?.decompress(withAlgorithm: .LZ4)

        tmp = tmp?.compress(withAlgorithm: .LZMA)
        tmp = tmp?.decompress(withAlgorithm: .LZMA)

        tmp = tmp?.compress(withAlgorithm: .ZLIB)
        tmp = tmp?.decompress(withAlgorithm: .ZLIB)

        return tmp
    }

    func pray(_ s: String) -> String?
{'fraction_non_alphanumeric': 0.13981603153745073, 'fraction_numerical': 0.01971090670170828, 'mean_word_length': 1.8964992389649924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6979524', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1253, 'n_words': 328}