Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cossio committed Jun 12, 2020
1 parent ffc3233 commit 78063bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions test/array.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OneHot
using Base: tail, front

X = OneHotArray(rand(1:4, 5), 4)

Expand All @@ -10,5 +11,13 @@ A = randn(3,4)
@test A * X == A[:, X.c]
@inferred A * X

B = randn(3,3)
@test_throws DimensionMismatch B * X

@test X[:,1:3] isa OneHotArray{2}
@inferred X[:,1:3]

for I in eachindex(X)
i = Tuple(I)
@test X[I] == (first(i) == X.c[tail(i)...])
end
6 changes: 6 additions & 0 deletions test/stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ using OneHot, Test, Random
for I in CartesianIndices(cl)
@test maximum(A[:,I]) == A[cl[I],I]
end

X = OneHotArray(rand(1:4,5,5), 4)
cl = OneHot.classify(X)
for I in CartesianIndices(cl)
@test maximum(X[:,I]) == X[cl[I],I]
end
end

@testset "entropy" begin
Expand Down
11 changes: 10 additions & 1 deletion test/util.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OneHot, Test, Random
using OneHot: argmaxdrop, argmaxdropfirst, tuplen
using OneHot: argmaxdrop, argmaxdropfirst, tuplen, columns

@testset "argmaxdrop" begin
@inferred argmaxdrop(randn(3,2,4); dims=2)
Expand All @@ -21,3 +21,12 @@ end
@inferred tuplen(Val(5))
@test tuplen(Val(5)) == (1,2,3,4,5)
end

@testset "columns" begin
A = randn(4,5)
@test columns(A) == collect(eachcol(A))
@inferred columns(A)
A = randn(5,5,3)
@test vec(columns(A)) == collect(eachcol(reshape(A,5,15)))
@inferred columns(A)
end

2 comments on commit 78063bd

@cossio
Copy link
Owner

@cossio cossio commented on 78063bd Jun 12, 2020

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/16276

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 78063bdec5d22166d91d3611e30e03d02e80d029
git push origin v0.2.0

Please sign in to comment.