Skip to content

Commit 1d1ae6a

Browse files
committed
Add test/similar.jl
1 parent 32dcc91 commit 1d1ae6a

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

test/invariants.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using LinearAlgebra: I, diagm, norm, tr
2-
using Unitful: @u_str
32

43
# Example from https://www.continuummechanics.org/hydrodeviatoricstrain.html
54
@testset "Test `hydrostatic` and `deviatoric`" begin

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using LinearElasticityBase
22
using Test
33

44
@testset "LinearElasticityBase.jl" begin
5+
include("similar.jl")
56
include("operations.jl")
67
include("invariants.jl")
78
include("axial.jl")

test/similar.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Unitful: @u_str
2+
3+
@testset "Test broadcasting" begin
4+
σ = TensorStress([
5+
300 100 0
6+
100 100 0
7+
0 0 0
8+
])
9+
@test σ * 5.0 == 5.0 * σ == TensorStress([
10+
300 100 0
11+
100 100 0
12+
0 0 0
13+
] * 5)
14+
@test σ * u"MPa" == u"MPa" * σ == TensorStress([
15+
300 100 0
16+
100 100 0
17+
0 0 0
18+
] * u"MPa")
19+
@test σ + σ == 2 * σ == σ * 2
20+
@test σ - σ == 0 * σ == σ * 0
21+
@test σ .+ 100 == TensorStress([
22+
400 200 100
23+
200 200 100
24+
100 100 100
25+
])
26+
end
27+
28+
@testset "Test `similar`" begin
29+
σ = TensorStress([
30+
300 100 0
31+
100 100 0
32+
0 0 0
33+
]) * u"MPa"
34+
@test typeof(similar(σ)) == TensorStress{typeof(1u"MPa")}
35+
@test size(similar(σ)) == (3, 3)
36+
@test typeof(similar(σ, axes(σ))) == TensorStress{typeof(1u"MPa")}
37+
@test size(similar(σ, axes(σ))) == (3, 3)
38+
@test_throws DimensionMismatch similar(σ, 4, 4)
39+
@test typeof(similar(typeof(σ), 3, 3)) == TensorStress{typeof(1u"MPa")}
40+
@test size(similar(typeof(σ), 3, 3)) == (3, 3)
41+
@test_throws DimensionMismatch similar(typeof(σ))
42+
@test_throws DimensionMismatch similar(typeof(σ), 4, 4)
43+
end

0 commit comments

Comments
 (0)