diff test/Grids/geometry_test.jl @ 1967:669361a8195a feature/grids/geometry_functions

Add tests and better constructors for LineSegment
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 12 Feb 2025 15:40:19 +0100
parents 478b233999c5
children 35cb503985b6
line wrap: on
line diff
--- a/test/Grids/geometry_test.jl	Wed Feb 12 15:33:48 2025 +0100
+++ b/test/Grids/geometry_test.jl	Wed Feb 12 15:40:19 2025 +0100
@@ -1,5 +1,5 @@
 using Diffinitive.Grids
-using Diffinitive.Grids: Line
+using Diffinitive.Grids: Line, LineSegment
 using StaticArrays
 
 @testset "Line" begin
@@ -25,9 +25,23 @@
 
 @testset "LineSegment" begin
     @testset "Constructors" begin
+        @test LineSegment([1,2],[2,3]) isa LineSegment{SVector{2,Int}}
+        @test LineSegment((1,2),(2,3)) isa LineSegment{SVector{2,Int}}
+        @test LineSegment(@SVector[1,2],[2,3]) isa LineSegment{SVector{2,Int}}
+        @test LineSegment(@SVector[1,2],@SVector[2,3]) isa LineSegment{SVector{2,Int}}
+
+        @test LineSegment([1,2],[2.,3]) isa LineSegment{SVector{2,Float64}}
+        @test LineSegment(@SVector[1,2.],@SVector[2,3]) isa LineSegment{SVector{2,Float64}}
+        @test LineSegment((1,2.),(2,3)) isa LineSegment{SVector{2,Float64}}
     end
 
-    @test_broken false
+    @testset "Evaluation" begin
+        l = LineSegment([1,2],[2,3])
+
+        @test l(0) == [1,2]
+        @test l(1) == [2,3]
+        @test l(1/2) == [1,2]/2 + [2,3]/2
+    end
 end
 
 @testset "linesegments" begin