Add unit tests

This commit is contained in:
2025-10-25 18:56:55 +03:00
parent ddc47abdde
commit bbb7f14650
38 changed files with 1051 additions and 526 deletions

View File

@@ -1,50 +1,26 @@
import Foundation
import Testing
import DataLiteCore
struct BinaryFloatingPointTests {
@Test func testFloatToSQLiteRawValue() {
let floatValue: Float = 3.14
let rawValue = floatValue.sqliteValue
#expect(rawValue == .real(Double(floatValue)))
@Test func floatingPointToSQLiteValue() {
#expect(Float(3.14).sqliteValue == .real(Double(Float(3.14))))
#expect(Double(3.14).sqliteValue == .real(3.14))
}
@Test func testDoubleToSQLiteRawValue() {
let doubleValue: Double = 3.14
let rawValue = doubleValue.sqliteValue
#expect(rawValue == .real(doubleValue))
}
@Test func testFloatInitializationFromSQLiteRawValue() {
let realValue: SQLiteValue = .real(3.14)
let floatValue = Float(realValue)
#expect(floatValue != nil)
#expect(floatValue == 3.14)
@Test func floatingPointFromSQLiteValue() {
#expect(Float(SQLiteValue.real(3.14)) == 3.14)
#expect(Float(SQLiteValue.int(42)) == 42)
let intValue: SQLiteValue = .int(42)
let floatFromInt = Float(intValue)
#expect(floatFromInt != nil)
#expect(floatFromInt == 42.0)
}
@Test func testDoubleInitializationFromSQLiteRawValue() {
let realValue: SQLiteValue = .real(3.14)
let doubleValue = Double(realValue)
#expect(doubleValue != nil)
#expect(doubleValue == 3.14)
#expect(Double(SQLiteValue.real(3.14)) == 3.14)
#expect(Double(SQLiteValue.int(42)) == 42)
let intValue: SQLiteValue = .int(42)
let doubleFromInt = Double(intValue)
#expect(doubleFromInt != nil)
#expect(doubleFromInt == 42.0)
}
@Test func testInitializationFailureFromInvalidSQLiteRawValue() {
let nullValue: SQLiteValue = .null
#expect(Float(nullValue) == nil)
#expect(Double(nullValue) == nil)
#expect(Float(SQLiteValue.text("42")) == nil)
#expect(Float(SQLiteValue.blob(Data([0x42]))) == nil)
#expect(Float(SQLiteValue.null) == nil)
let textValue: SQLiteValue = .text("Invalid")
#expect(Float(textValue) == nil)
#expect(Double(textValue) == nil)
#expect(Double(SQLiteValue.text("42")) == nil)
#expect(Double(SQLiteValue.blob(Data([0x42]))) == nil)
#expect(Double(SQLiteValue.null) == nil)
}
}