Skip to content

Commit

Permalink
Added tests for abstract construction and conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
brainandforce committed Nov 11, 2024
1 parent 6047b4a commit 084ff99
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
15 changes: 15 additions & 0 deletions test/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 084ff99

Please sign in to comment.