Skip to content

Commit

Permalink
Added a ton of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brainandforce committed Feb 28, 2024
1 parent 5d0bcac commit 13d8433
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/construction.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@testset "Zero elements" begin
@test zero(KVector{0,APS}) == KVector{0,APS,Bool}(0)
@test zero(KVector{1,APS}) == KVector{1,APS,Bool}(0, 0, 0)
@test zero(KVector{2,APS}) == KVector{2,APS,Bool}(0, 0, 0)
@test zero(KVector{3,APS}) == KVector{3,APS,Bool}(0)
@test zero(EvenCliffordNumber{APS}) == EvenCliffordNumber{APS,Bool}(0, 0, 0, 0)
@test zero(OddCliffordNumber{APS}) == OddCliffordNumber{APS,Bool}(0, 0, 0, 0)
@test zero(CliffordNumber{APS}) == CliffordNumber{APS,Bool}(0, 0, 0, 0, 0, 0, 0, 0)
end

@testset "Units" begin
# one
@test one(KVector{0,APS}) == KVector{0,APS,Bool}(1)
@test one(KVector{1,APS}) == KVector{0,APS,Bool}(1)
@test one(KVector{2,APS}) == KVector{0,APS,Bool}(1)
@test one(KVector{3,APS}) == KVector{0,APS,Bool}(1)
@test one(EvenCliffordNumber{APS}) == EvenCliffordNumber{APS,Bool}(1, 0, 0, 0)
@test one(OddCliffordNumber{APS}) == KVector{0,APS,Bool}(1)
@test one(CliffordNumber{APS}) == CliffordNumber{APS,Bool}(1, 0, 0, 0, 0, 0, 0, 0)
# oneunit
@test oneunit(KVector{0,APS}) == KVector{0,APS,Bool}(1)
@test oneunit(EvenCliffordNumber{APS}) == EvenCliffordNumber{APS,Bool}(1, 0, 0, 0)
@test oneunit(CliffordNumber{APS}) == CliffordNumber{APS,Bool}(1, 0, 0, 0, 0, 0, 0, 0)
# these should throw since they can't represent 1
@test_throws InexactError oneunit(KVector{1,APS})
@test_throws InexactError oneunit(KVector{2,APS})
@test_throws InexactError oneunit(KVector{3,APS})
@test_throws InexactError oneunit(OddCliffordNumber{APS})
end
10 changes: 10 additions & 0 deletions test/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ end
@test promote_type(CliffordNumber{APS,Int}, CliffordNumber{APS,Float64}) ===
CliffordNumber{APS,Float64,8}
@test promote_type(KVector{1,APS,Int}, KVector{1,APS,Float64}) === KVector{1,APS,Float64,3}
@test promote_type(KVector{0,APS,Int}, KVector{2,APS,Int}) === EvenCliffordNumber{APS,Int,4}
@test promote_type(KVector{1,APS,Int}, KVector{3,APS,Int}) === OddCliffordNumber{APS,Int,4}
@test promote_type(KVector{1,APS,Int}, KVector{2,APS,Int}) === CliffordNumber{APS,Int,8}
@test promote_type(KVector{1,APS,Int}, EvenCliffordNumber{APS,Int}) ===
CliffordNumber{APS,Int,8}
@test promote_type(KVector{2,APS,Int}, EvenCliffordNumber{APS,Int}) ===
EvenCliffordNumber{APS,Int,4}
@test promote_type(KVector{2,APS,Int}, OddCliffordNumber{APS,Int}) ===
CliffordNumber{APS,Int,8}
@test promote_type(KVector{1,APS,Int}, OddCliffordNumber{APS,Int}) ===
OddCliffordNumber{APS,Int,4}
@test promote_type(KVector{0,APS,Int}, Int) === KVector{0,APS,Int,1}
@test promote_type(KVector{0,APS,Int}, Float64) === KVector{0,APS,Float64,1}
@test promote_type(KVector{1,APS,Int}, Int) === CliffordNumber{APS,Int,8}
Expand Down
2 changes: 2 additions & 0 deletions test/internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ end

@testset "Type relations" begin
@test CliffordNumber <: AbstractCliffordNumber
@test EvenCliffordNumber <: AbstractCliffordNumber
@test OddCliffordNumber <: AbstractCliffordNumber
@test KVector <: AbstractCliffordNumber
end

Expand Down
11 changes: 11 additions & 0 deletions test/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@ end
@test CliffordNumbers.exp_taylor(pi/2 * k) exp(pi/2 * k)
@test CliffordNumbers.exp_taylor(pi/2 * k) exppi(1//2 * k)
@test CliffordNumbers.exp_taylor(pi/2 * k) exptau(1//4 * k)
# Integer exponentiation of a multivector
k1 = KVector{1,APS}(4, 2, 0)
k2 = KVector{2,APS}(0, 6, 9)
@test k1^2 isa CliffordNumber
@test k2^2 isa EvenCliffordNumber
@test k1^0 == one(k1)
@test k1^1 == k1
@test k1^2 == k1 * k1
@test k2^0 == one(k2)
@test k2^1 == k2
@test k2^2 == k2 * k2
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using Test

@testset "CliffordNumbers.jl" begin
include("internals.jl")
include("construction.jl")
include("indexing.jl")
include("conversion.jl")
include("operations.jl")
Expand Down

0 comments on commit 13d8433

Please sign in to comment.