diff test/Grids/parameter_space_test.jl @ 1992:ca6d898d3a38 feature/grids/parameter_spaces/in

Implement Base.in(x, ::Simplex)
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 24 Apr 2025 09:23:12 +0200
parents 8cf1764ba124
children e6dbd4bec6cc
line wrap: on
line diff
--- a/test/Grids/parameter_space_test.jl	Thu Apr 24 09:05:30 2025 +0200
+++ b/test/Grids/parameter_space_test.jl	Thu Apr 24 09:23:12 2025 +0200
@@ -92,4 +92,32 @@
     @test verticies(unittetrahedron()) == ([0,0,0], [1,0,0], [0,1,0],[0,0,1])
 
     @test unitsimplex(4) isa Simplex{Float64,4}
+
+    @testset "Base.in" begin
+        @testset "2D" begin
+            T₂ = Simplex([0.0, 0.0], [1.0, 0.0], [0.0, 1.0])
+            @test [0.1, 0.1] ∈ T₂
+            @test [0.3, 0.3] ∈ T₂
+            @test [1.0, 0.0] ∈ T₂
+            @test [0.0, 0.0] ∈ T₂
+            @test [0.0, 1.0] ∈ T₂
+            @test [0.5, 0.5] ∈ T₂
+
+            @test [0.6, 0.6] ∉ T₂
+            @test [-0.1, 0.1] ∉ T₂
+        end
+
+        @testset "3D" begin
+            tetrahedron = Simplex([0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0])
+            @test [0.1, 0.1, 0.1] ∈ tetrahedron
+            @test [0.0, 0.0, 0.0] ∈ tetrahedron
+            @test [1.0, 0.0, 0.0] ∈ tetrahedron
+            @test [0.25, 0.25, 0.25] ∈ tetrahedron
+            @test [0.5, 0.5, 0.0] ∈ tetrahedron
+            @test [0.3, 0.3, 0.3] ∈ tetrahedron
+
+            @test [0.5, 0.5, 1.0] ∉ tetrahedron
+            @test [0.3, 0.3, 0.5] ∉ tetrahedron
+        end
+    end
 end