diff test/Grids/grid_test.jl @ 1515:b2eaa1ad19c8 feature/grids/componentview

Move correctness tests of componentview to the tests for ArrayComponentView
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 20 Mar 2024 16:17:53 +0100
parents cfc24f132641
children 8d64f8981bb0
line wrap: on
line diff
--- a/test/Grids/grid_test.jl	Mon Feb 19 15:58:07 2024 +0100
+++ b/test/Grids/grid_test.jl	Wed Mar 20 16:17:53 2024 +0100
@@ -64,27 +64,20 @@
 end
 
 @testset "componentview" begin
-    # REVIEW: I think we can reduce the index ranges.
     v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
 
-    @test componentview(v, 1, 1) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
-    @test componentview(v, 1, 2) == [3 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
-    @test componentview(v, 2, 1) == [2 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
-
-    @test componentview(v, 1, :) == [@SVector[1,3] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
-    @test componentview(v, 2, :) == [@SVector[2,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
-    @test componentview(v, :, 1) == [@SVector[1,2] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
-    @test componentview(v, :, 2) == [@SVector[3,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
-
+    @test componentview(v, 1, 1) isa AbstractArray
+    @test componentview(v, 1, :) isa AbstractArray
 
     A = @SMatrix[
-        1 4 7;
-        2 5 8;
-        3 6 9;
-    ]
+            1 4 7;
+            2 5 8;
+            3 6 9;
+        ]
     v = [A .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
-    @test componentview(v, 1:2, 1:2) == [@SMatrix[1 4;2 5] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
-    @test componentview(v, 2:3, 1:2) == [@SMatrix[2 5;3 6] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+    @test componentview(v, 2:3, 1:2) isa AbstractArray
+
+    # Correctness of the result is tested in ArrayComponentView
 end
 
 @testset "ArrayComponentView" begin
@@ -96,6 +89,31 @@
         @test ArrayComponentView(v, (1,1)) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
         @test [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] == ArrayComponentView(v, (1,1))
     end
+
+    @testset "components" begin
+        # REVIEW: I think we can reduce the index ranges.
+        v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+
+        # switch to indexing in test?
+        @test ArrayComponentView(v, (1, 1))  == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+        @test ArrayComponentView(v, (1, 2))  == [3 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+        @test ArrayComponentView(v, (2, 1))  == [2 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+
+        @test ArrayComponentView(v, (1, :))  == [@SVector[1,3] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+        @test ArrayComponentView(v, (2, :))  == [@SVector[2,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+        @test ArrayComponentView(v, (:, 1))  == [@SVector[1,2] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+        @test ArrayComponentView(v, (:, 2))  == [@SVector[3,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+
+
+        A = @SMatrix[
+            1 4 7;
+            2 5 8;
+            3 6 9;
+        ]
+        v = [A .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+        @test ArrayComponentView(v, (1:2, 1:2)) == [@SMatrix[1 4;2 5] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+        @test ArrayComponentView(v, (2:3, 1:2)) == [@SMatrix[2 5;3 6] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
+    end
 end
 
 @testset "_ncomponents" begin