Skip to content

Commit

Permalink
Modify for testing fail
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Liu <andy@madmachine.io>
  • Loading branch information
andy0808 committed Nov 3, 2024
1 parent b6efc63 commit 74e6da0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
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
}
}
6 changes: 3 additions & 3 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 {
@_transparent
static func exp(_ x: Float) -> Float {
exp2f(x)
expf(x)
}
}
4 changes: 3 additions & 1 deletion Sources/TCS34725/TCS34725.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,13 @@ extension TCS34725 {
@_extern(c, "pow")
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 }
if x == 0 && y == 0 { return .nan }
let result = powf(x, y)
print("powf(\(x), \(y)) result = \(result)")
return powf(x, y)
}
}
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 74e6da0

Please sign in to comment.