From 972a6d3e4d3b684fbadeb5cd046a8634ec24eb8c Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Mon, 3 Feb 2025 22:31:45 +0000 Subject: iqconvert: converts from u8 to f32 without issues --- PrySDR_Tests/PrySDR_Tests.swift | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 PrySDR_Tests/PrySDR_Tests.swift (limited to 'PrySDR_Tests/PrySDR_Tests.swift') diff --git a/PrySDR_Tests/PrySDR_Tests.swift b/PrySDR_Tests/PrySDR_Tests.swift new file mode 100644 index 0000000..70b9828 --- /dev/null +++ b/PrySDR_Tests/PrySDR_Tests.swift @@ -0,0 +1,79 @@ +// +// PrySDR_Tests.swift +// PrySDR_Tests +// +// Created by Jacky Jack on 21/01/2025. +// + +import Testing +import Numerics + +struct IQConverter_Tests { + + @Test func convertU8arrayToFloat32_accel_size1() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. + let arr1:[UInt8] = [0] + let res1 = cnvU8toFloat32_accel(arr1) + #expect(res1[0].truncate(places: 3) == -0.997) + //#expect(res1[0].isApproximatelyEqual(to: -0.997, absoluteTolerance: 0.001)) + + + let arr2:[UInt8] = [255] + let res2 = cnvU8toFloat32_accel(arr2) + #expect(res2[0].truncate(places: 3) == 0.996) + + let arr3:[UInt8] = [127] + let res3 = cnvU8toFloat32_accel(arr3) + #expect(res3[0].truncate(places: 3) == -0.004) + + let arr4:[UInt8] = [128] + let res4 = cnvU8toFloat32_accel(arr4) + #expect(res4[0].truncate(places: 3) == 0.003) + } + /* + @Test func cnvU8arrayToFloat32_size16() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. + #expect(false) + } + */ + /* + @Test func cnvU8arrayToFloat32_size1024() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. + #expect(false) + } + */ + + @Test func cnvU8arrayToFloat32_naive_size1() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. + let arr1:[UInt8] = [0] + let res1 = cnvU8toFloat32(arr1) + //minus truncates to "up" + #expect(res1[0].truncate(places: 3) == -0.997) + + let arr2:[UInt8] = [255] + let res2 = cnvU8toFloat32(arr2) + #expect(res2[0].truncate(places: 3) == 0.996) + + let arr3:[UInt8] = [127] + let res3 = cnvU8toFloat32(arr3) + //minus truncates to "up" + #expect(res3[0].truncate(places: 3) == -0.004) + + let arr4:[UInt8] = [128] + let res4 = cnvU8toFloat32(arr4) + #expect(res4[0].truncate(places: 3) == 0.003) + } + /* + @Test func cnvU8arrayToFloat32_naive_size16() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. + #expect(false) + } + */ + + /* + @Test func cnvU8arrayToFloat32_naive_size1024() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. + #expect(false) + } + */ +} -- cgit v1.2.3