From 4054a0d5b9ef0a28de507b41751f4e5bb54951a6 Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Sun, 3 Nov 2024 16:54:09 +0700 Subject: [PATCH] Fix/testing fail (#76) * Modify for testing fail Signed-off-by: Andy Liu * modify powf function Signed-off-by: Andy Liu * Update libmath api Signed-off-by: Andy Liu --------- Signed-off-by: Andy Liu --- Sources/BME680/BME680.swift | 4 +-- Sources/BMP280/BMP280.swift | 2 +- Sources/HTU21D/HTU21D.swift | 13 ++++---- Sources/LTR390/LTR390.swift | 2 +- Sources/MAG3110/MAG3110.swift | 2 +- Sources/SGP30/SGP30.swift | 8 ++--- Sources/TCS34725/TCS34725.swift | 4 +-- Tests/ADT7410Tests/ADT7410Tests.swift | 48 +++++++++++++-------------- 8 files changed, 42 insertions(+), 41 deletions(-) diff --git a/Sources/BME680/BME680.swift b/Sources/BME680/BME680.swift index 651d6c2..2140ac8 100644 --- a/Sources/BME680/BME680.swift +++ b/Sources/BME680/BME680.swift @@ -636,7 +636,7 @@ private extension Array where Element == UInt8 { @_extern(c, "atan2f") func atan2f(_: Float, _: Float) -> Float -extension Float { +private extension Float { @_transparent static func atan2(y: Float, x: Float) -> Float { atan2f(y, x) @@ -646,7 +646,7 @@ extension Float { @_extern(c, "pow") func pow(_: Double, _ : Double) -> Double -extension Double { +private extension Double { @_transparent static func mathPow(_ x: Double, _ y: Double) -> Double { guard x >= 0 else { return .nan } diff --git a/Sources/BMP280/BMP280.swift b/Sources/BMP280/BMP280.swift index 09ab462..a8b958c 100644 --- a/Sources/BMP280/BMP280.swift +++ b/Sources/BMP280/BMP280.swift @@ -457,7 +457,7 @@ extension BMP280 { @_extern(c, "pow") func pow(_: Double, _ : Double) -> Double -extension Double { +private extension Double { @_transparent static func mathPow(_ x: Double, _ y: Double) -> Double { guard x >= 0 else { return .nan } diff --git a/Sources/HTU21D/HTU21D.swift b/Sources/HTU21D/HTU21D.swift index aae5a5b..fa15c0b 100644 --- a/Sources/HTU21D/HTU21D.swift +++ b/Sources/HTU21D/HTU21D.swift @@ -165,9 +165,10 @@ extension HTU21D { } - -public enum HTU21DError: Error { - case readError - case writeError - case crcError -} +public extension HTU21D { + enum HTU21DError: Error { + case readError + case writeError + case crcError + } +} \ No newline at end of file diff --git a/Sources/LTR390/LTR390.swift b/Sources/LTR390/LTR390.swift index 32f79b7..781a5f9 100644 --- a/Sources/LTR390/LTR390.swift +++ b/Sources/LTR390/LTR390.swift @@ -361,7 +361,7 @@ extension LTR390 { @_extern(c, "exp2f") func exp2f(_: Float) -> Float -extension Float { +private extension Float { @_transparent static func exp2(_ x: Float) -> Float { exp2f(x) diff --git a/Sources/MAG3110/MAG3110.swift b/Sources/MAG3110/MAG3110.swift index fb0789b..9dea2b2 100644 --- a/Sources/MAG3110/MAG3110.swift +++ b/Sources/MAG3110/MAG3110.swift @@ -297,7 +297,7 @@ extension MAG3110 { @_extern(c, "atan2f") func atan2f(_: Float, _: Float) -> Float -extension Float { +private extension Float { @_transparent static func atan2(y: Float, x: Float) -> Float { atan2f(y, x) diff --git a/Sources/SGP30/SGP30.swift b/Sources/SGP30/SGP30.swift index 2e5a2a9..15b8a02 100644 --- a/Sources/SGP30/SGP30.swift +++ b/Sources/SGP30/SGP30.swift @@ -269,12 +269,12 @@ extension SGP30 { } -@_extern(c, "exp2f") -func exp2f(_: Float) -> Float +@_extern(c, "expf") +func expf(_: Float) -> Float -extension Float { +private extension Float { @_transparent static func exp(_ x: Float) -> Float { - exp2f(x) + expf(x) } } \ No newline at end of file diff --git a/Sources/TCS34725/TCS34725.swift b/Sources/TCS34725/TCS34725.swift index b35394b..716c595 100644 --- a/Sources/TCS34725/TCS34725.swift +++ b/Sources/TCS34725/TCS34725.swift @@ -348,10 +348,10 @@ extension TCS34725 { } -@_extern(c, "pow") +@_extern(c, "powf") func powf(_: Float, _ : Float) -> Float -extension Float { +private extension Float { @_transparent static func pow(_ x: Float, _ y: Float) -> Float { guard x >= 0 else { return .nan } diff --git a/Tests/ADT7410Tests/ADT7410Tests.swift b/Tests/ADT7410Tests/ADT7410Tests.swift index a86792a..84e8d67 100644 --- a/Tests/ADT7410Tests/ADT7410Tests.swift +++ b/Tests/ADT7410Tests/ADT7410Tests.swift @@ -6,31 +6,31 @@ import SwiftIO final class ADT7410Tests: XCTestCase { func testToTemp13Bit(){ - let resulution = ADT7410.Resulution.r_13Bit - XCTAssertEqual(-55,ADT7410.toTemp(resulution,[0b1110_0100,0b1000_0000])) - XCTAssertEqual(-50,ADT7410.toTemp(resulution, [0b1110_0111,0b0000_0000])) - XCTAssertEqual(-25,ADT7410.toTemp(resulution, [0b1111_0011,0b1000_0000])) - XCTAssertEqual(-0.0625,ADT7410.toTemp(resulution, [0b1111_1111,0b1111_1000])) - XCTAssertEqual(0,ADT7410.toTemp(resulution, [0b0000_0000,0b0000_0000])) - XCTAssertEqual(0.0625,ADT7410.toTemp(resulution, [0b0000_0000,0b0000_1000])) - XCTAssertEqual(25,ADT7410.toTemp(resulution, [0b0000_1100,0b1000_0000])) - XCTAssertEqual(50,ADT7410.toTemp(resulution, [0b0001_1001,0b0000_0000])) - XCTAssertEqual(125,ADT7410.toTemp(resulution, [0b0011_1110,0b1000_0000])) - XCTAssertEqual(150,ADT7410.toTemp(resulution, [0b0100_1011,0b0000_0000])) + let resolution = ADT7410.Resolution.r_13Bit + XCTAssertEqual(-55,ADT7410.toTemp(resolution,[0b1110_0100,0b1000_0000])) + XCTAssertEqual(-50,ADT7410.toTemp(resolution, [0b1110_0111,0b0000_0000])) + XCTAssertEqual(-25,ADT7410.toTemp(resolution, [0b1111_0011,0b1000_0000])) + XCTAssertEqual(-0.0625,ADT7410.toTemp(resolution, [0b1111_1111,0b1111_1000])) + XCTAssertEqual(0,ADT7410.toTemp(resolution, [0b0000_0000,0b0000_0000])) + XCTAssertEqual(0.0625,ADT7410.toTemp(resolution, [0b0000_0000,0b0000_1000])) + XCTAssertEqual(25,ADT7410.toTemp(resolution, [0b0000_1100,0b1000_0000])) + XCTAssertEqual(50,ADT7410.toTemp(resolution, [0b0001_1001,0b0000_0000])) + XCTAssertEqual(125,ADT7410.toTemp(resolution, [0b0011_1110,0b1000_0000])) + XCTAssertEqual(150,ADT7410.toTemp(resolution, [0b0100_1011,0b0000_0000])) } func testToData13Bit(){ - let resulution = ADT7410.Resulution.r_13Bit - XCTAssertEqual([0b1110_0100,0b1000_0000],ADT7410.toData(resulution,-55)) - XCTAssertEqual([0b1110_0111,0b0000_0000],ADT7410.toData(resulution,-50)) - XCTAssertEqual([0b1111_0011,0b1000_0000],ADT7410.toData(resulution,-25)) - XCTAssertEqual([0b1111_1111,0b1111_1000],ADT7410.toData(resulution,-0.0625)) - XCTAssertEqual([0b0000_0000,0b0000_0000],ADT7410.toData(resulution,0)) - XCTAssertEqual([0b0000_0000,0b0000_1000],ADT7410.toData(resulution,0.0625)) - XCTAssertEqual([0b0000_1100,0b1000_0000],ADT7410.toData(resulution,25)) - XCTAssertEqual([0b0001_1001,0b0000_0000],ADT7410.toData(resulution,50)) - XCTAssertEqual([0b0011_1110,0b1000_0000],ADT7410.toData(resulution,125)) - XCTAssertEqual([0b0100_1011,0b0000_0000],ADT7410.toData(resulution,150)) + let resolution = ADT7410.Resolution.r_13Bit + XCTAssertEqual([0b1110_0100,0b1000_0000],ADT7410.toData(resolution,-55)) + XCTAssertEqual([0b1110_0111,0b0000_0000],ADT7410.toData(resolution,-50)) + XCTAssertEqual([0b1111_0011,0b1000_0000],ADT7410.toData(resolution,-25)) + XCTAssertEqual([0b1111_1111,0b1111_1000],ADT7410.toData(resolution,-0.0625)) + XCTAssertEqual([0b0000_0000,0b0000_0000],ADT7410.toData(resolution,0)) + XCTAssertEqual([0b0000_0000,0b0000_1000],ADT7410.toData(resolution,0.0625)) + XCTAssertEqual([0b0000_1100,0b1000_0000],ADT7410.toData(resolution,25)) + XCTAssertEqual([0b0001_1001,0b0000_0000],ADT7410.toData(resolution,50)) + XCTAssertEqual([0b0011_1110,0b1000_0000],ADT7410.toData(resolution,125)) + XCTAssertEqual([0b0100_1011,0b0000_0000],ADT7410.toData(resolution,150)) } func testDefaultConfiguration(){ @@ -117,11 +117,11 @@ final class ADT7410Tests: XCTestCase { func testConfigurationResolution(){ var config = ADT7410.Configuration() - config.resulution = .r_13Bit + config.resolution = .r_13Bit XCTAssertEqual(0b0, config.getByte()) XCTAssertEqual(config, ADT7410.Configuration(config.getByte())) - config.resulution = .r_16Bit + config.resolution = .r_16Bit XCTAssertEqual(0b1 << 7, config.getByte()) XCTAssertEqual(config, ADT7410.Configuration(config.getByte())) }