diff --git a/Tests/OmFileFormatTests/OmFileFormatTests.swift b/Tests/OmFileFormatTests/OmFileFormatTests.swift index 8772119..ee6b061 100644 --- a/Tests/OmFileFormatTests/OmFileFormatTests.swift +++ b/Tests/OmFileFormatTests/OmFileFormatTests.swift @@ -290,7 +290,7 @@ import Foundation try r.withUnsafeMutableBufferPointer({ try read.read(into: $0.baseAddress!, range: [x.. { + let dimensions: [UInt64] = [5, 5] + let chunkDimensions: [UInt64] = [2, 2] + let generateValue: () -> T + + func test() throws { + let file = "test_file_\(T.self).om" + try FileManager.default.removeItemIfExists(at: file) + + do { + defer { try? FileManager.default.removeItemIfExists(at: file) } + + // Write file + let fn = try FileHandle.createNewFile(file: file) + let fileWriter = OmFileWriter2(fn: fn, initialCapacity: 8) + + let count = Int(dimensions.reduce(1, *)) + let values = (0...init() { Float.random(in: 0..<1) * 10000 }.test() + try TestCase.init() { Double.random(in: 0..<1) * 10000 }.test() + try TestCase.init() { Int8.random(in: Int8.min...init() { Int16.random(in: Int16.min...init() { Int32.random(in: Int32.min...init() { Int.random(in: Int.min...init() { UInt8.random(in: 0...init() { UInt16.random(in: 0...init() { UInt32.random(in: 0...init() { UInt.random(in: 0.. Bool { + func testSimilar(_ b: [Element], accuracy: Element = 0.001) -> Bool { + return testSimilarFloating(b, accuracy: accuracy) + } +} + +extension Array where Element == Double { + func testSimilar(_ b: [Element], accuracy: Element = 0.001) -> Bool { + return testSimilarFloating(b, accuracy: accuracy) + } +} + +extension Array where Element: FloatingPoint { + func testSimilarFloating(_ b: [Element], accuracy: Element) -> Bool { let a = self guard a.count == b.count else { Issue.record("Array length different")