From c4aaa54b19c620eaf39694607bbedfd6ea9ea00d Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Thu, 31 Oct 2024 17:50:43 +0100 Subject: [PATCH] Fix AtomsBaseTesting.test_approx_eq issue (#129) * Updates * up --- lib/AtomsBaseTesting/Project.toml | 2 +- lib/AtomsBaseTesting/src/AtomsBaseTesting.jl | 4 +++- lib/AtomsBaseTesting/test/runtests.jl | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/AtomsBaseTesting/Project.toml b/lib/AtomsBaseTesting/Project.toml index 6a88afb..4689d99 100644 --- a/lib/AtomsBaseTesting/Project.toml +++ b/lib/AtomsBaseTesting/Project.toml @@ -1,7 +1,7 @@ name = "AtomsBaseTesting" uuid = "ed7c10db-df7e-4efa-a7be-4f4190f7f227" authors = ["JuliaMolSim community"] -version = "0.3.0" +version = "0.3.1" [deps] AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a" diff --git a/lib/AtomsBaseTesting/src/AtomsBaseTesting.jl b/lib/AtomsBaseTesting/src/AtomsBaseTesting.jl index ecb8c9d..16f3777 100644 --- a/lib/AtomsBaseTesting/src/AtomsBaseTesting.jl +++ b/lib/AtomsBaseTesting/src/AtomsBaseTesting.jl @@ -72,7 +72,9 @@ function test_approx_eq(s::AbstractSystem, t::AbstractSystem; end # Test some things on cell objects - @test typeof(cell(s)) == typeof(cell(t)) + if cell(s) isa PeriodicCell + @test maximum(map(rnorm, bounding_box(cell(s)), bounding_box(cell(t)))) < rtol + end @test periodicity(cell(s)) == periodicity(cell(t)) @test n_dimensions(cell(s)) == n_dimensions(cell(t)) diff --git a/lib/AtomsBaseTesting/test/runtests.jl b/lib/AtomsBaseTesting/test/runtests.jl index ed9a4f3..bc7369a 100644 --- a/lib/AtomsBaseTesting/test/runtests.jl +++ b/lib/AtomsBaseTesting/test/runtests.jl @@ -109,5 +109,17 @@ include("testmacros.jl") test_approx_eq(hydrogen, hydrogen) end + @testset "Identical systems with just different units" begin + box = 10.26 / 2 * [[0, 0, 1], [1, 0, 1], [1, 1, 0]]u"bohr" + box_A = [[uconvert.(u"Å", i[j]) for j in 1:3] for i in box] + silicon = AtomsBase.periodic_system([:Si => ones(3)/8, + :Si => -ones(3)/8], + box, fractional=true) + silicon_A = AtomsBase.periodic_system([:Si => ones(3)/8, + :Si => -ones(3)/8], + box_A, fractional=true) + @testpass AtomsBaseTesting.test_approx_eq(silicon, silicon_A) + end + # TODO More tests would be useful end