Skip to content

Commit

Permalink
Added extra tests for ShiftVector
Browse files Browse the repository at this point in the history
  • Loading branch information
brainandforce committed Nov 27, 2023
1 parent 0ec0ff7 commit b186257
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions test/kpoints.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
@testset "k-points" begin
@testset "Shift vectors" begin
# Equality and hashing
@test KPoint(0, 0, 0, weight = 1) == KPoint(0, 0, 0, weight = 1)
@test KPoint(0, 0, 0, weight = 1) != KPoint(0, 0, 0, weight = 2)
@test hash(KPoint(0, 0, 0, weight = 1)) == hash(KPoint(0, 0, 0, weight = 1))
@test hash(KPoint(0, 0, 0, weight = 1)) != hash(KPoint(0, 0, 0, weight = 2))
@test ShiftVector{Electrum.ByRealSpace}(0, 0) != ShiftVector{Electrum.ByReciprocalSpace}(0, 0)
# Constructors
@test zero(KPoint{3}) === zero(KPoint{3,Bool})
@test zero(KPoint{3,Int}) === KPoint(0, 0, 0, weight = 1)
@test zero(KPoint{3,Int}) === KPoint(SVector{3}(0, 0, 0), 1)
@test zero(KPoint{3,Float64}) === KPoint{3}(SVector{3}(0, 0, 0), 1.0)
@test zero(KPoint{3,Float32}) === KPoint{3,Float32}(SVector{3}(0, 0, 0), 1.0)
@test zero(KPoint{3,Float64}) === KPoint{3}([0, 0, 0], 1.0)
@test zero(KPoint{3,Float32}) === KPoint{3,Float64}([0, 0, 0], 1.0)
@test_throws Exception KPoint(SMatrix{3,1}([0, 0, 0]))
@test_throws Exception KPoint{3}(SMatrix{3,1}([0, 0, 0]))
@test_throws Exception KPoint{3,Int}(SMatrix{3,1}([0, 0, 0]))
# Traits
@test Electrum.DataSpace(zero(KPoint{3})) === Electrum.ByReciprocalSpace{3}()
@test Electrum.ByCoordinate(zero(KPoint{3})) === Electrum.ByFractionalCoordinate{3}()
# Truncation
# TODO: see note for trunc() in Electrum.jl/src/kpoints.jl
# TODO: see note for trunc() in src/vectors.jl
@test truncate(KPoint(1, 2, 3)) == KPoint(0, 0, 0)
@test truncate(KPoint(0.5, -0.5, 1.5)) == KPoint(0.5, -0.5, -0.5)
@test truncate(KPoint(0.5, -0.5 + eps(Float64), 1.5)) == KPoint(0.5, -0.5 + eps(Float64), -0.5)
@test truncate(KPoint(0.5, -0.5 - eps(Float64), 1.5)) == KPoint(0.5, 0.5 - eps(Float64), -0.5)
# Length measurement
@test length(KPoint(1, 2, 3, 4, 5)) == 5
@test length(KPoint{2}) == 2
@test size(KPoint(1, 2, 3, 4, 5)) == (5,)
@test size(KPoint{2}) == (2,)
@test convert(Vector, KPoint(0.1, 0.2, 0.3)) == [0.1, 0.2, 0.3]
@test convert(Vector, KPoint(0.1, 0.2, 0.3)) isa Vector{<:Real}
@test convert(SVector, KPoint(0.1, 0.2, 0.3)) === SVector{3}(0.1, 0.2, 0.3)
Expand Down

0 comments on commit b186257

Please sign in to comment.