Skip to content

Commit

Permalink
Fix/testing fail (#76)
Browse files Browse the repository at this point in the history
* Modify for testing fail

Signed-off-by: Andy Liu <andy@madmachine.io>

* modify powf function

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update libmath api

Signed-off-by: Andy Liu <andy@madmachine.io>

---------

Signed-off-by: Andy Liu <andy@madmachine.io>
  • Loading branch information
andy0808 authored Nov 3, 2024
1 parent b6efc63 commit 4054a0d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Sources/BME680/BME680.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion Sources/BMP280/BMP280.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
13 changes: 7 additions & 6 deletions Sources/HTU21D/HTU21D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion Sources/LTR390/LTR390.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Sources/MAG3110/MAG3110.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Sources/SGP30/SGP30.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions Sources/TCS34725/TCS34725.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
48 changes: 24 additions & 24 deletions Tests/ADT7410Tests/ADT7410Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down Expand Up @@ -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()))
}
Expand Down

0 comments on commit 4054a0d

Please sign in to comment.