Skip to content

Commit b4d6dff

Browse files
committed
Fix test precision issues in type_encoding_implementation_test
- Tighten assertion on active_users query to verify exact count and user identity - Rename misleading test name to clarify it tests nil insertion, not :null encoding - Change loose >= assertions to exact == assertions after DELETE operations - Improve zero value test to verify actual stored values via WHERE clause - Replace generic is_list assertion with specific length check for float precision test - Document and verify expected behavior for string comparison lexicographic order - Fix float zero pattern matching warning by checking +0.0 vs -0.0 representation All tests pass with no warnings.
1 parent 2c99e60 commit b4d6dff

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

test/type_encoding_implementation_test.exs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
144144
from(u in User, where: u.active == ^true)
145145
|> TestRepo.all()
146146

147-
assert length(active_users) >= 1
148-
assert Enum.all?(active_users, & &1.active)
147+
assert length(active_users) == 1
148+
assert hd(active_users).name == "Dave"
149149
end
150150
end
151151

@@ -234,13 +234,13 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
234234
assert [[nil]] = result.rows
235235
end
236236

237-
test "querying with :null atom for IS NULL" do
237+
test "nil inserted value can be queried with IS NULL" do
238238
SQL.query!(TestRepo, "DELETE FROM users")
239239

240240
# Insert NULL value
241241
SQL.query!(TestRepo, "INSERT INTO users (name, uuid) VALUES (?, ?)", ["Alice", nil])
242242

243-
# Query with :null should find it
243+
# Query with IS NULL should find it
244244
result =
245245
SQL.query!(TestRepo, "SELECT COUNT(*) FROM users WHERE uuid IS NULL AND name = ?", [
246246
"Alice"
@@ -317,7 +317,7 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
317317
# Verify all were inserted
318318
result = SQL.query!(TestRepo, "SELECT COUNT(*) FROM users")
319319
assert [[count]] = result.rows
320-
assert count >= 3
320+
assert count == 3
321321
end
322322

323323
test "Ecto query with multiple encoded types" do
@@ -562,10 +562,15 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
562562
SQL.query!(TestRepo, "INSERT INTO test_types (real_col) VALUES (?)", [0.0])
563563

564564
result =
565-
SQL.query!(TestRepo, "SELECT int_col, real_col FROM test_types ORDER BY id DESC LIMIT 2")
565+
SQL.query!(TestRepo, "SELECT int_col FROM test_types WHERE int_col = ?", [0])
566+
assert [[0]] = result.rows
566567

567-
rows = result.rows
568-
assert length(rows) == 2
568+
result =
569+
SQL.query!(TestRepo, "SELECT real_col FROM test_types WHERE real_col = ?", [0.0])
570+
571+
[[stored_real]] = result.rows
572+
# Float comparison: allow for +0.0 vs -0.0 representation
573+
assert stored_real == +0.0 or stored_real == -0.0
569574
end
570575

571576
test "Decimal parameter encoding" do
@@ -977,7 +982,7 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
977982

978983
# Due to floating point precision, this might return 0 or 1 rows
979984
# depending on exact arithmetic
980-
assert is_list(result.rows)
985+
assert length(result.rows) in [0, 1]
981986
end
982987

983988
test "division by zero handling" do
@@ -992,13 +997,13 @@ defmodule EctoLibSql.TypeEncodingImplementationTest do
992997
SQL.query!(TestRepo, "INSERT INTO test_types (text_col) VALUES (?)", ["100"])
993998
SQL.query!(TestRepo, "INSERT INTO test_types (text_col) VALUES (?)", ["20"])
994999

995-
# String comparison: "100" < "20" (lexicographic)
1000+
# String comparison: "100" < "50" (true), "20" < "50" (true) → 2 matches
9961001
result =
9971002
SQL.query!(TestRepo, "SELECT COUNT(*) FROM test_types WHERE text_col < ?", ["50"])
9981003

9991004
assert [[count]] = result.rows
1000-
# Result depends on string vs numeric comparison
1001-
assert is_integer(count)
1005+
# Lexicographic: "100" < "50" (true), "20" < "50" (true) → 2 matches
1006+
assert count == 2
10021007
end
10031008
end
10041009
end

0 commit comments

Comments
 (0)