1
+ using Test
2
+ using GeometryOps
3
+ using GeometryOpsCore
4
+
5
+ using GeometryOps: Planar, Spherical, AutoManifold, rebuild, manifold, best_manifold, enforce, get
6
+ using GeometryOps: CLibraryPlanarAlgorithm, GEOS, TG, PROJ
7
+
8
+ @testset " CLibraryPlanarAlgorithm" begin
9
+ # Test that it's a subtype of SingleManifoldAlgorithm{Planar}
10
+ @test CLibraryPlanarAlgorithm <: GeometryOpsCore.SingleManifoldAlgorithm{Planar}
11
+
12
+ # Test that it requires params::NamedTuple
13
+ struct TestAlg <: CLibraryPlanarAlgorithm
14
+ params:: NamedTuple
15
+ end
16
+
17
+ # Test constructor with keyword arguments
18
+ alg = TestAlg (; a= 1 , b= 2 )
19
+ @test alg. params == (; a= 1 , b= 2 )
20
+
21
+ # Test constructor with NamedTuple
22
+ alg = TestAlg ((; a= 1 , b= 2 ))
23
+ @test alg. params == (; a= 1 , b= 2 )
24
+
25
+ # Test null constructor
26
+ alg = TestAlg (())
27
+ @test alg. params == NamedTuple ()
28
+
29
+ # Test manifold methods
30
+ @test manifold (alg) == Planar ()
31
+ @test best_manifold (alg, nothing ) == Planar ()
32
+
33
+ # Test rebuild methods
34
+ @test rebuild (alg, Planar ()) == TestAlg (alg. params)
35
+ @test rebuild (alg, AutoManifold ()) == TestAlg (alg. params)
36
+ @test_throws GeometryOpsCore. WrongManifoldException rebuild (alg, Spherical ())
37
+ @test rebuild (alg, (; c= 3 , d= 4 )) == TestAlg ((; c= 3 , d= 4 ))
38
+ @test rebuild (alg; c= 3 , d= 4 ) == TestAlg ((; c= 3 , d= 4 ))
39
+
40
+ # Test get methods
41
+ @test Base. get (alg, :a , 0 ) == 0
42
+ @test Base. get (alg, :c , 0 ) == 0
43
+
44
+ # Test enforce method
45
+ @test_throws ErrorException enforce (alg, :a , " test" )
46
+ @test_throws ErrorException enforce (alg, :c , " test" )
47
+ end
48
+
49
+ @testset " GEOS" begin
50
+ # Test that it's a subtype of CLibraryPlanarAlgorithm
51
+ @test GEOS () isa CLibraryPlanarAlgorithm
52
+
53
+ # Test null constructor
54
+ alg = GEOS ()
55
+ @test alg. params == NamedTuple ()
56
+ @test manifold (alg) == Planar ()
57
+
58
+ # Test constructor
59
+ alg = GEOS (; a= 1 , b= 2 )
60
+ @test alg. params == (; a= 1 , b= 2 )
61
+
62
+ # Test manifold methods
63
+ @test manifold (alg) == Planar ()
64
+ @test best_manifold (alg, nothing ) == Planar ()
65
+
66
+ # Test rebuild methods
67
+ @test rebuild (alg, Planar ()) == GEOS (alg. params)
68
+ @test rebuild (alg, AutoManifold ()) == GEOS (alg. params)
69
+ @test_throws GeometryOpsCore. WrongManifoldException rebuild (alg, Spherical ())
70
+ @test rebuild (alg, (; c= 3 , d= 4 )) == GEOS ((; c= 3 , d= 4 ))
71
+ @test rebuild (alg; c= 3 , d= 4 ) == GEOS ((; c= 3 , d= 4 ))
72
+
73
+ # Test get methods
74
+ @test Base. get (alg, :a , 0 ) == 1
75
+ @test Base. get (alg, :c , 0 ) == 0
76
+
77
+ # Test enforce method
78
+ @test enforce (alg, :a , " test" ) == 1
79
+ @test_throws ErrorException enforce (alg, :c , " test" )
80
+ end
81
+
82
+ @testset " TG" begin
83
+ # Test that it's a subtype of CLibraryPlanarAlgorithm
84
+ @test TG <: CLibraryPlanarAlgorithm
85
+
86
+ # Test null constructor
87
+ alg = TG ()
88
+ @test alg. params == NamedTuple ()
89
+ @test manifold (alg) == Planar ()
90
+
91
+ # Test constructor
92
+ alg = TG (; a= 1 , b= 2 )
93
+ @test alg. params == (; a= 1 , b= 2 )
94
+
95
+ # Test manifold methods
96
+ @test manifold (alg) == Planar ()
97
+ @test best_manifold (alg, nothing ) == Planar ()
98
+
99
+ # Test rebuild methods
100
+ @test rebuild (alg, Planar ()) == TG (alg. params)
101
+ @test rebuild (alg, AutoManifold ()) == TG (alg. params)
102
+ @test_throws GeometryOpsCore. WrongManifoldException rebuild (alg, Spherical ())
103
+ @test rebuild (alg, (; c= 3 , d= 4 )) == TG ((; c= 3 , d= 4 ))
104
+ @test rebuild (alg; c= 3 , d= 4 ) == TG ((; c= 3 , d= 4 ))
105
+
106
+ # Test get methods
107
+ @test Base. get (alg, :a , 0 ) == 1
108
+ @test Base. get (alg, :c , 0 ) == 0
109
+
110
+ # Test enforce method
111
+ @test enforce (alg, :a , " test" ) == 1
112
+ @test_throws ErrorException enforce (alg, :c , " test" )
113
+ end
114
+
115
+ @testset " PROJ" begin
116
+ # Test that it's a subtype of Algorithm
117
+ @test PROJ <: GeometryOpsCore.Algorithm
118
+
119
+ # Test null constructor
120
+ alg = PROJ ()
121
+ @test alg. manifold == Planar ()
122
+ @test alg. params == NamedTuple ()
123
+
124
+ # Test constructors
125
+ alg1 = PROJ (; a= 1 , b= 2 )
126
+ @test alg1. manifold == Planar ()
127
+ @test alg1. params == (; a= 1 , b= 2 )
128
+
129
+ alg2 = PROJ (Spherical ())
130
+ @test alg2. manifold == Spherical ()
131
+ @test alg2. params == NamedTuple ()
132
+
133
+ # Test manifold method
134
+ @test manifold (alg1) == Planar ()
135
+ @test manifold (alg2) == Spherical ()
136
+
137
+ # Test rebuild methods
138
+ @test rebuild (alg1, Spherical ()) == PROJ (Spherical (), alg1. params)
139
+ @test rebuild (alg1, (; c= 3 , d= 4 )) == PROJ (Planar (), (; c= 3 , d= 4 ))
140
+
141
+ # Test get methods
142
+ @test Base. get (alg1, :a , 0 ) == 1
143
+ @test Base. get (alg1, :c , 0 ) == 0
144
+
145
+ # Test enforce method
146
+ @test enforce (alg1, :a , " test" ) == 1
147
+ @test_throws ErrorException enforce (alg1, :c , " test" )
148
+ end
0 commit comments