@@ -6,6 +6,7 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
66 # - UUID encoding (binary → string if needed)
77 # - :null atom encoding (:null → nil)
88
9+ import Ecto.Query
910 alias Ecto.Adapters.SQL
1011
1112 defmodule TestRepo do
@@ -138,8 +139,6 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
138139 TestRepo . insert! ( % User { name: "Eve" , email: "[email protected] " , active: false } ) 139140
140141 # Query with boolean parameter
141- import Ecto.Query
142-
143142 active_users = TestRepo . all ( from ( u in User , where: u . active == ^ true ) )
144143
145144 assert length ( active_users ) == 1
@@ -206,8 +205,6 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
206205 TestRepo . insert! ( % User { name: "Dave" , email: "[email protected] " , uuid: uuid } ) 207206
208207 # Query with UUID parameter
209- import Ecto.Query
210-
211208 users = TestRepo . all ( from ( u in User , where: u . uuid == ^ uuid ) )
212209
213210 assert length ( users ) == 1
@@ -327,8 +324,6 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
327324 TestRepo . insert! ( % User { name: "Eve" , email: "[email protected] " , active: false , uuid: nil } ) 328325
329326 # Query with multiple encoded types
330- import Ecto.Query
331-
332327 users = TestRepo . all ( from ( u in User , where: u . active == ^ true and u . uuid == ^ uuid ) )
333328
334329 assert length ( users ) == 1
@@ -404,8 +399,10 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
404399
405400 describe "string encoding edge cases" do
406401 setup do
402+ SQL . query! ( TestRepo , "DROP TABLE IF EXISTS test_types" )
403+
407404 SQL . query! ( TestRepo , """
408- CREATE TABLE IF NOT EXISTS test_types (
405+ CREATE TABLE test_types (
409406 id INTEGER PRIMARY KEY AUTOINCREMENT,
410407 text_col TEXT,
411408 blob_col BLOB,
@@ -465,8 +462,10 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
465462
466463 describe "binary encoding edge cases" do
467464 setup do
465+ SQL . query! ( TestRepo , "DROP TABLE IF EXISTS test_types" )
466+
468467 SQL . query! ( TestRepo , """
469- CREATE TABLE IF NOT EXISTS test_types (
468+ CREATE TABLE test_types (
470469 id INTEGER PRIMARY KEY AUTOINCREMENT,
471470 blob_col BLOB
472471 )
@@ -514,8 +513,10 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
514513
515514 describe "numeric encoding edge cases" do
516515 setup do
516+ SQL . query! ( TestRepo , "DROP TABLE IF EXISTS test_types" )
517+
517518 SQL . query! ( TestRepo , """
518- CREATE TABLE IF NOT EXISTS test_types (
519+ CREATE TABLE test_types (
519520 id INTEGER PRIMARY KEY AUTOINCREMENT,
520521 int_col INTEGER,
521522 real_col REAL,
@@ -565,8 +566,8 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
565566 SQL . query! ( TestRepo , "SELECT real_col FROM test_types WHERE real_col = ?" , [ 0.0 ] )
566567
567568 [ [ stored_real ] ] = result . rows
568- # Float comparison: allow for +0.0 vs -0.0 representation
569- assert stored_real == + 0.0 or stored_real == - 0.0
569+ # Float comparison: +0.0 == -0.0 in Elixir
570+ assert stored_real == 0.0
570571 end
571572
572573 test "Decimal parameter encoding" do
@@ -604,8 +605,10 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
604605
605606 describe "temporal type encoding" do
606607 setup do
608+ SQL . query! ( TestRepo , "DROP TABLE IF EXISTS test_types" )
609+
607610 SQL . query! ( TestRepo , """
608- CREATE TABLE IF NOT EXISTS test_types (
611+ CREATE TABLE test_types (
609612 id INTEGER PRIMARY KEY AUTOINCREMENT,
610613 text_col TEXT
611614 )
@@ -673,8 +676,10 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
673676
674677 describe "float/real field encoding" do
675678 setup do
679+ SQL . query! ( TestRepo , "DROP TABLE IF EXISTS test_types" )
680+
676681 SQL . query! ( TestRepo , """
677- CREATE TABLE IF NOT EXISTS test_types (
682+ CREATE TABLE test_types (
678683 id INTEGER PRIMARY KEY AUTOINCREMENT,
679684 real_col REAL
680685 )
@@ -777,8 +782,10 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
777782
778783 describe "NULL/nil edge cases" do
779784 setup do
785+ SQL . query! ( TestRepo , "DROP TABLE IF EXISTS test_types" )
786+
780787 SQL . query! ( TestRepo , """
781- CREATE TABLE IF NOT EXISTS test_types (
788+ CREATE TABLE test_types (
782789 id INTEGER PRIMARY KEY AUTOINCREMENT,
783790 int_col INTEGER,
784791 real_col REAL,
@@ -903,8 +910,10 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
903910
904911 describe "type coercion edge cases" do
905912 setup do
913+ SQL . query! ( TestRepo , "DROP TABLE IF EXISTS test_types" )
914+
906915 SQL . query! ( TestRepo , """
907- CREATE TABLE IF NOT EXISTS test_types (
916+ CREATE TABLE test_types (
908917 id INTEGER PRIMARY KEY AUTOINCREMENT,
909918 int_col INTEGER,
910919 text_col TEXT,
@@ -965,20 +974,21 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
965974 end
966975
967976 test "float precision in arithmetic" do
968- SQL . query! ( TestRepo , "INSERT INTO test_types (real_col) VALUES (?)" , [ 0.1 ] )
969- SQL . query! ( TestRepo , "INSERT INTO test_types (real_col) VALUES (?)" , [ 0.2 ] )
977+ SQL . query! ( TestRepo , "INSERT INTO test_types (real_col) VALUES (?)" , [ 0.5 ] )
978+ SQL . query! ( TestRepo , "INSERT INTO test_types (real_col) VALUES (?)" , [ 1.5 ] )
970979
971- # Floating point arithmetic can have precision issues
980+ # Use integer-representable values to ensure deterministic results
981+ # 0.5 + 0.5 = 1.0, which equals 1.0 (match)
982+ # 1.5 + 0.5 = 2.0, which is > 1.0 (match)
972983 result =
973984 SQL . query! (
974985 TestRepo ,
975- "SELECT real_col FROM test_types WHERE real_col + ? > ?" ,
976- [ 0.1 , 0.35 ]
986+ "SELECT real_col FROM test_types WHERE real_col + ? >= ?" ,
987+ [ 0.5 , 1.0 ]
977988 )
978989
979- # Due to floating point precision, this might return 0 or 1 rows
980- # depending on exact arithmetic
981- assert length ( result . rows ) in [ 0 , 1 ]
990+ # Exactly 2 rows match: 0.5 + 0.5 >= 1.0 and 1.5 + 0.5 >= 1.0
991+ assert length ( result . rows ) == 2
982992 end
983993
984994 test "division by zero handling" do
0 commit comments