comparison test/Grids/parameter_space_test.jl @ 2057:8a2a0d678d6f feature/lazy_tensors/pretty_printing

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 10 Feb 2026 22:41:19 +0100
parents e6dbd4bec6cc
children
comparison
equal deleted inserted replaced
1110:c0bff9f6e0fb 2057:8a2a0d678d6f
1 using Test
2
3 using Diffinitive.Grids
4 using StaticArrays
5
6 @testset "ParameterSpace" begin
7 @test ndims(HyperBox([1,1], [2,2])) == 2
8 @test ndims(unittetrahedron()) == 3
9 end
10
11 @testset "Interval" begin
12 @test Interval <: ParameterSpace{1}
13
14 @test Interval(0,1) isa Interval{Int}
15 @test Interval(0,1.) isa Interval{Float64}
16
17 @test unitinterval() isa Interval{Float64}
18 @test unitinterval() == Interval(0.,1.)
19 @test limits(unitinterval()) == (0.,1.)
20
21 @test unitinterval(Int) isa Interval{Int}
22 @test unitinterval(Int) == Interval(0,1)
23 @test limits(unitinterval(Int)) == (0,1)
24
25 @test boundary_identifiers(unitinterval()) == (LowerBoundary(), UpperBoundary())
26
27 @test 0 ∈ Interval(0,1)
28 @test 0. ∈ Interval(0,1)
29 @test 1. ∈ Interval(0,1)
30 @test 2 ∉ Interval(0,1)
31 @test -1 ∉ Interval(0,1)
32 @test -1. ∉ Interval(0,1)
33 end
34
35 @testset "HyperBox" begin
36 @test HyperBox{<:Any, 2} <: ParameterSpace{2}
37 @test HyperBox([1,1], [2,2]) isa HyperBox{Int, 2}
38
39 @test HyperBox([1,2], [1.,2.]) isa HyperBox{Float64,2}
40
41 @test limits(HyperBox([1,2], [3,4])) == ([1,2], [3,4])
42 @test limits(HyperBox([1,2], [3,4]), 1) == (1,3)
43 @test limits(HyperBox([1,2], [3,4]), 2) == (2,4)
44
45 @test unitsquare() isa HyperBox{Float64,2}
46 @test limits(unitsquare()) == ([0,0],[1,1])
47
48 @test unitcube() isa HyperBox{Float64,3}
49 @test limits(unitcube()) == ([0,0,0],[1,1,1])
50
51 @test unithyperbox(4) isa HyperBox{Float64,4}
52 @test limits(unithyperbox(4)) == ([0,0,0,0],[1,1,1,1])
53
54
55 @test boundary_identifiers(unitsquare()) == [
56 CartesianBoundary{1,LowerBoundary}(),
57 CartesianBoundary{1,UpperBoundary}(),
58 CartesianBoundary{2,LowerBoundary}(),
59 CartesianBoundary{2,UpperBoundary}(),
60 ]
61
62 @test boundary_identifiers(unitcube()) == [
63 CartesianBoundary{1,LowerBoundary}(),
64 CartesianBoundary{1,UpperBoundary}(),
65 CartesianBoundary{2,LowerBoundary}(),
66 CartesianBoundary{2,UpperBoundary}(),
67 CartesianBoundary{3,LowerBoundary}(),
68 CartesianBoundary{3,UpperBoundary}(),
69 ]
70
71 @test @SVector[1.5, 3.5] ∈ HyperBox([1,2], [3,4])
72 @test @SVector[1, 2] ∈ HyperBox([1,2], [3,4])
73 @test @SVector[3, 4] ∈ HyperBox([1,2], [3,4])
74
75 @test @SVector[0.5, 3.5] ∉ HyperBox([1,2], [3,4])
76 @test @SVector[1.5, 4.5] ∉ HyperBox([1,2], [3,4])
77 end
78
79 @testset "Simplex" begin
80 @test Simplex{<:Any, 3} <: ParameterSpace{3}
81 @test Simplex([1,2], [3,4]) isa Simplex{Int, 2}
82 @test Simplex([1,2,3], [4,5,6],[1,1,1]) isa Simplex{Int, 3}
83
84 @test Simplex([1,2], [3.,4.]) isa Simplex{Float64, 2}
85
86 @test verticies(Simplex([1,2], [3,4])) == ([1,2], [3,4])
87
88 @test unittriangle() isa Simplex{Float64,2}
89 @test verticies(unittriangle()) == ([0,0], [1,0], [0,1])
90
91 @test unittetrahedron() isa Simplex{Float64,3}
92 @test verticies(unittetrahedron()) == ([0,0,0], [1,0,0], [0,1,0],[0,0,1])
93
94 @test unitsimplex(4) isa Simplex{Float64,4}
95
96 @testset "Base.in" begin
97 @testset "2D" begin
98 T₂ = Simplex([0.0, 0.0], [1.0, 0.0], [0.0, 1.0])
99 @test [0.1, 0.1] ∈ T₂
100 @test [0.3, 0.3] ∈ T₂
101 @test [1.0, 0.0] ∈ T₂
102 @test [0.0, 0.0] ∈ T₂
103 @test [0.0, 1.0] ∈ T₂
104 @test [0.5, 0.5] ∈ T₂
105
106 @test [0.6, 0.6] ∉ T₂
107 @test [-0.1, 0.1] ∉ T₂
108 end
109
110 @testset "3D" begin
111 T₃ = 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])
112 @test [0.1, 0.1, 0.1] ∈ T₃
113 @test [0.0, 0.0, 0.0] ∈ T₃
114 @test [1.0, 0.0, 0.0] ∈ T₃
115 @test [0.25, 0.25, 0.25] ∈ T₃
116 @test [0.5, 0.5, 0.0] ∈ T₃
117 @test [0.3, 0.3, 0.3] ∈ T₃
118
119 @test [0.5, 0.5, 1.0] ∉ T₃
120 @test [0.3, 0.3, 0.5] ∉ T₃
121 end
122 end
123 end