From 13d843309b48d99138f0189eb88ca613c8ba9e9d Mon Sep 17 00:00:00 2001 From: Brandon Flores Date: Tue, 27 Feb 2024 21:39:48 -0600 Subject: [PATCH] Added a ton of tests --- test/construction.jl | 29 +++++++++++++++++++++++++++++ test/conversion.jl | 10 ++++++++++ test/internals.jl | 2 ++ test/operations.jl | 11 +++++++++++ test/runtests.jl | 1 + 5 files changed, 53 insertions(+) create mode 100644 test/construction.jl diff --git a/test/construction.jl b/test/construction.jl new file mode 100644 index 0000000..2f61598 --- /dev/null +++ b/test/construction.jl @@ -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 diff --git a/test/conversion.jl b/test/conversion.jl index 3223bb1..44a859f 100644 --- a/test/conversion.jl +++ b/test/conversion.jl @@ -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} diff --git a/test/internals.jl b/test/internals.jl index 50041bc..423fe9f 100644 --- a/test/internals.jl +++ b/test/internals.jl @@ -30,6 +30,8 @@ end @testset "Type relations" begin @test CliffordNumber <: AbstractCliffordNumber + @test EvenCliffordNumber <: AbstractCliffordNumber + @test OddCliffordNumber <: AbstractCliffordNumber @test KVector <: AbstractCliffordNumber end diff --git a/test/operations.jl b/test/operations.jl index e8c4662..d573909 100644 --- a/test/operations.jl +++ b/test/operations.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 0631f16..5877b85 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")