comparison test/Grids/grid_test.jl @ 1524:b2b9693aa63b

Merge feature/grids/componentview
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 22 Mar 2024 08:59:36 +0100
parents 0cd6cf62af93
children 43aaf710463e
comparison
equal deleted inserted replaced
1520:97af5489dcf0 1524:b2b9693aa63b
63 # Multi-argument functions 63 # Multi-argument functions
64 f(x,y) = sin(x)*cos(y) 64 f(x,y) = sin(x)*cos(y)
65 @test eval_on(g, f) == map(x̄->f(x̄...), g) 65 @test eval_on(g, f) == map(x̄->f(x̄...), g)
66 end 66 end
67 67
68 @testset "componentview" begin
69 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
70
71 @test componentview(v, 1, 1) isa AbstractArray
72 @test componentview(v, 1, :) isa AbstractArray
73
74 A = @SMatrix[
75 1 4 7;
76 2 5 8;
77 3 6 9;
78 ]
79 v = [A .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
80 @test componentview(v, 2:3, 1:2) isa AbstractArray
81
82 # Correctness of the result is tested in ArrayComponentView
83 end
84
85 @testset "ArrayComponentView" begin
86 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
87
88 @testset "==" begin
89 @test ArrayComponentView(v, (1,1)) == ArrayComponentView(v, (1,1))
90 @test ArrayComponentView(v, (1,1)) == ArrayComponentView(copy(v), (1,1))
91 @test ArrayComponentView(v, (1,1)) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
92 @test [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] == ArrayComponentView(v, (1,1))
93 end
94
95 @testset "components" begin
96 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
97
98 @test ArrayComponentView(v, (1, 1)) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
99 @test ArrayComponentView(v, (1, 2)) == [3 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
100 @test ArrayComponentView(v, (2, 1)) == [2 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
101
102 @test ArrayComponentView(v, (1, :)) == [@SVector[1,3] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
103 @test ArrayComponentView(v, (2, :)) == [@SVector[2,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
104 @test ArrayComponentView(v, (:, 1)) == [@SVector[1,2] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
105 @test ArrayComponentView(v, (:, 2)) == [@SVector[3,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
106
107
108 A = @SMatrix[
109 1 4 7;
110 2 5 8;
111 3 6 9;
112 ]
113 v = [A .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
114 @test ArrayComponentView(v, (1:2, 1:2)) == [@SMatrix[1 4;2 5] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
115 @test ArrayComponentView(v, (2:3, 1:2)) == [@SMatrix[2 5;3 6] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4]
116 end
117 end
118
68 @testset "_ncomponents" begin 119 @testset "_ncomponents" begin
69 @test Grids._ncomponents(Int) == 1 120 @test Grids._ncomponents(Int) == 1
70 @test Grids._ncomponents(Float64) == 1 121 @test Grids._ncomponents(Float64) == 1
71 @test Grids._ncomponents(Rational) == 1 122 @test Grids._ncomponents(Rational) == 1
72 123