From 6fbfd767dfadc388dce5346080bfc925e0959d68 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Thu, 16 Jan 2025 12:48:13 -0500 Subject: [PATCH] Fix typo in promote, add tests (#6) --- Project.toml | 2 +- src/unspecifiedzero.jl | 2 +- test/Project.toml | 1 + test/test_basics.jl | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/test_basics.jl diff --git a/Project.toml b/Project.toml index 7c387e6..71d9ac3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "UnspecifiedTypes" uuid = "42b3faec-625b-4613-8ddc-352bf9672b8d" authors = ["ITensor developers and contributors"] -version = "0.1.1" +version = "0.1.2" [compat] julia = "1.10" diff --git a/src/unspecifiedzero.jl b/src/unspecifiedzero.jl index ee9726d..47ede0e 100644 --- a/src/unspecifiedzero.jl +++ b/src/unspecifiedzero.jl @@ -32,6 +32,6 @@ Base.:/(::Number, ::UnspecifiedZero) = throw(DivideError()) Base.:/(::UnspecifiedZero, ::UnspecifiedZero) = throw(DivideError()) Base.:-(::UnspecifiedZero) = UnspecifiedZero() -Base.promote_rule(::Type{<:UnspecifiedZero}, t::Type) = t2 +Base.promote_rule(::Type{<:UnspecifiedZero}, t::Type) = t Base.promote_rule(::Type{<:UnspecifiedZero}, ::Type{<:UnspecifiedZero}) = UnspecifiedZero Base.promote_type(::Type{<:Complex{<:UnspecifiedZero}}, t::Type) = complex(t) diff --git a/test/Project.toml b/test/Project.toml index e9c291e..02432db 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -3,6 +3,7 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +UnspecifiedTypes = "42b3faec-625b-4613-8ddc-352bf9672b8d" [compat] Aqua = "0.8.9" diff --git a/test/test_basics.jl b/test/test_basics.jl new file mode 100644 index 0000000..dbc4214 --- /dev/null +++ b/test/test_basics.jl @@ -0,0 +1,16 @@ +using UnspecifiedTypes: UnspecifiedZero +using Test: @testset, @test + +@testset "UnspecifiedTypes (eltype=$elt)" for elt in ( + Float32, Float64, Complex{Float32}, Complex{Float64} +) + for x in (elt(2) + UnspecifiedZero(), UnspecifiedZero() + elt(2)) + @test x isa elt + @test x === elt(2) + end + + for x in (elt(2) * UnspecifiedZero(), UnspecifiedZero() * elt(2)) + @test x isa UnspecifiedZero + @test x === UnspecifiedZero() + end +end