diff --git a/test/construction.jl b/test/construction.jl index cf7786d..9ee0bd1 100644 --- a/test/construction.jl +++ b/test/construction.jl @@ -79,6 +79,21 @@ end @test CliffordNumbers.Z2CliffordNumber(k2) === EvenCliffordNumber{VGA(3)}(0, 1, 2, 3) end +@testset "Abstract constructors" begin + k = KVector{1,VGA(3)}(4, 2, 0) + # Things that should work + @test AbstractCliffordNumber(k) === k + @test AbstractCliffordNumber{VGA(3)}(k) === k + @test AbstractCliffordNumber{VGA(3),scalar_type(k)}(k) === k + @test AbstractCliffordNumber{VGA(3),Float64}(k) === float(k) + @test AbstractCliffordNumber{VGA(3)}(1) === one(KVector{0,VGA(3),Int}) + @test AbstractCliffordNumber{VGA(3),Float64}(1) === one(KVector{0,VGA(3),Float64}) + # Things that shouldn't work + @test_throws ArgumentError AbstractCliffordNumber(1) + @test_throws ArgumentError AbstractCliffordNumber(MockNumber()) + @test_throws ArgumentError AbstractCliffordNumber{VGA(3)}(MockNumber()) +end + @testset "Similar types" begin import CliffordNumbers.similar_type @test similar_type(EvenCliffordNumber{VGA(3),Int}, Val(STA)) === EvenCliffordNumber{STA,Int,8} diff --git a/test/conversion.jl b/test/conversion.jl index fbc242d..afa1ba6 100644 --- a/test/conversion.jl +++ b/test/conversion.jl @@ -24,6 +24,21 @@ @test scalar_convert(Float32, 2) === Float32(2) end +@testset "Abstract conversion" begin + k = KVector{1,VGA(3)}(4, 2, 0) + # Things that should work + @test convert(AbstractCliffordNumber, k) === k + @test convert(AbstractCliffordNumber{VGA(3)}, k) === k + @test convert(AbstractCliffordNumber{VGA(3),scalar_type(k)}, k) === k + @test convert(AbstractCliffordNumber{VGA(3),Float64}, k) === float(k) + @test convert(AbstractCliffordNumber{VGA(3)}, 1) === one(KVector{0,VGA(3),Int}) + @test convert(AbstractCliffordNumber{VGA(3),Float64}, 1) === one(KVector{0,VGA(3),Float64}) + # Things that shouldn't + @test_throws ArgumentError convert(AbstractCliffordNumber, 1) + @test_throws ArgumentError convert(AbstractCliffordNumber, MockNumber()) + @test_throws ArgumentError convert(AbstractCliffordNumber{VGA(3)}, MockNumber()) +end + @testset "Promotion" begin @test promote_type(Int, CliffordNumber{VGA(3)}) === CliffordNumber{VGA(3)} @test promote_type(Int, CliffordNumber{VGA(3),Float64}) === CliffordNumber{VGA(3),Float64,8} diff --git a/test/runtests.jl b/test/runtests.jl index 1d0b014..1f0f0ca 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,6 +9,10 @@ Aqua.test_all(CliffordNumbers; unbound_args = false) @basis_vars(PGA(3), Int) @basis_vars(STA) +# A subtype of Number that does not subtype Real or Complex +struct MockNumber <: Number +end + @testset "CliffordNumbers.jl" begin include("internals.jl") include("metrics.jl")