Skip to content

Actaully test recursive_unitless_eltype #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions test/utils_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@ A = [[1 2; 3 4],[1 3;4 6],[5 6;7 8]]
4.6666666666 6.0]

A = zeros(5,5)
recursive_unitless_eltype(A) == Float64
@test recursive_unitless_eltype(A) == Float64

using Unitful
A = zeros(5,5)*1u"kg"
recursive_unitless_eltype(A) == Float64
@test recursive_unitless_eltype(A) == Float64
AA = [zeros(5,5) for i in 1:5]
recursive_unitless_eltype(AA) == Array{Float64,2}
@test recursive_unitless_eltype(AA) == Array{Float64,2}
AofA = [copy(A) for i in 1:5]
recursive_unitless_eltype(AofA) == Array{Float64,2}
@test recursive_unitless_eltype(AofA) == Array{Float64,2}
AofSA = [@SVector [2.0,3.0] for i in 1:5]
recursive_unitless_eltype(AofSA) == SVector{2,Float64}
@test recursive_unitless_eltype(AofSA) == SVector{2,Float64}
AofuSA = [@SVector [2.0u"kg",3.0u"kg"] for i in 1:5]
recursive_unitless_eltype(AofuSA) == SVector{2,Float64}

@inferred recursive_unitless_eltype(AofuSA)
@test recursive_unitless_eltype(AofuSA) == SVector{2,Float64}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@test @inferred(recursive_unitless_eltype(AofuSA)) == SVector{2,Float64}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @YingboMa, I appreciate your comment, but could you please elaborate?
If you mean to tell me that I would need to add the @inferred back, please explain to me why.
From my understanding, the @inferred is just another way of testing things. But as I added the @test macros, I think we don't need it anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that. I should have explained. @inferred is a stronger test than @test recursive_unitless_eltype(AofuSA) == SVector{2,Float64}. Consider the following case

julia> using Test

julia> foo() = rand() > 2 ? Int : Float64
foo (generic function with 1 method)

julia> @test foo() == Float64
Test Passed

julia> @inferred foo()
ERROR: return type Type{Float64} does not match inferred return type Union{Type{Float64}, Type{Int64}}
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] top-level scope at none:0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @YingboMa, thank you for the clarification! Always nice to learn :) As I understand it now, @inferred is used to ensure type stability.
Would it make sense to add @inferred to all tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as many as possible, yes it would be good to have on any test that's checking output types.


A = [ArrayPartition(ones(1),ones(1)),]
@test repr("text/plain", A) == "1-element Array{ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}},1}:\n [1.0][1.0]"