Skip to content

Commit

Permalink
Update to linspace changes in #18777
Browse files Browse the repository at this point in the history
Make trunc, round, floor, ceil testing more precise
  • Loading branch information
andreasnoack committed Feb 2, 2017
1 parent d66eef2 commit 4e8b7b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Compat.isapprox` with `nans` keyword argument [#20022](https://github.com/JuliaLang/julia/pull/20022)

* `take!` method for `Task`s since some functions now return `Channel`s instead of `Task`s [#19841](https://github.com/JuliaLang/julia/pull/19841).

## Renamed functions

* `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively
Expand Down
34 changes: 15 additions & 19 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,32 @@ if VERSION < v"0.4.0-dev+1387"
@test isdefined(Main, :AbstractString)
end

if VERSION < v"0.6.0-"
@test round(Int, 3//4) == 1
@test round(Int, 1) == 1
@test round(Int, 1.1) == 1
@test round(Int, 3//4) == 1
@test round(Int, 1) == 1
@test round(Int, 1.1) == 1
@test ceil(Int, 1) == 1
@test ceil(Int, 1.1) == 2
@test floor(Int, 1) == 1
@test floor(Int, 1.1) == 1
@test trunc(Int, 1) == 1
@test trunc(Int, 1.1) == 1

if VERSION < v"0.6.0-dev.1825"
@test round(Int, [1, 1]) == [1, 1]
@test round(Int, [1.1, 1.1]) == [1, 1]
@test round(Int, [1 1]) == [1 1]
@test round(Int, [1.1 1.1]) == [1 1]
@test round(Int, fill(1.1, 2, 3, 4)) == fill(1, 2, 3, 4)
@test ceil(Int, 1) == 1
@test ceil(Int, 1.1) == 2
@test ceil(Int, [1, 1]) == [1, 1]
@test ceil(Int, [1.1, 1.1]) == [2, 2]
@test ceil(Int, [1 1]) == [1 1]
@test ceil(Int, [1.1 1.1]) == [2 2]
@test ceil(Int, fill(1.1, 2, 3, 4)) == fill(2, 2, 3, 4)
@test floor(Int, 1) == 1
@test floor(Int, 1.1) == 1
@test floor(Int, [1, 1]) == [1, 1]
@test floor(Int, [1.1, 1.1]) == [1, 1]
@test floor(Int, [1 1]) == [1 1]
@test floor(Int, [1.1 1.1]) == [1 1]
@test floor(Int, fill(1.1, 2, 3, 4)) == fill(1, 2, 3, 4)
@test trunc(Int, 1) == 1
@test trunc(Int, 1.1) == 1
@test trunc(Int, [1, 1]) == [1, 1]
@test trunc(Int, [1.1, 1.1]) == [1, 1]
@test trunc(Int, [1 1]) == [1 1]
Expand Down Expand Up @@ -577,9 +578,6 @@ for T = (Float32, Float64)
@test [Compat.linspace(-u,-u,1);] == [-u]
@test [Compat.linspace(-u,u,2);] == [-u,u]
@test [Compat.linspace(-u,u,3);] == [-u,0,u]
@test [Compat.linspace(-u,u,4);] == [-u,0,0,u]
@test [Compat.linspace(-u,u,4);][2] === -z
@test [Compat.linspace(-u,u,4);][3] === z
@test first(Compat.linspace(-u,-u,0)) == -u
@test last(Compat.linspace(-u,-u,0)) == -u
@test first(Compat.linspace(u,-u,0)) == u
Expand All @@ -588,12 +586,8 @@ for T = (Float32, Float64)
@test [Compat.linspace(u,u,1);] == [u]
@test [Compat.linspace(u,-u,2);] == [u,-u]
@test [Compat.linspace(u,-u,3);] == [u,0,-u]
@test [Compat.linspace(u,-u,4);] == [u,0,0,-u]
@test [Compat.linspace(u,-u,4);][2] === z
@test [Compat.linspace(u,-u,4);][3] === -z
v = [Compat.linspace(-u,u,12);]
@test length(v) == 12
@test issorted(v) && unique(v) == [-u,0,0,u]
@test [-3u:u:3u;] == [Compat.linspace(-3u,3u,7);] == [-3:3;].*u
@test [3u:-u:-3u;] == [Compat.linspace(3u,-3u,7);] == [3:-1:-3;].*u
end
Expand Down Expand Up @@ -1336,8 +1330,10 @@ end
@test allunique([1, 2, 3])
@test !allunique([1, 2, 1])
@test allunique(1:3)
@test allunique(FloatRange(0.0, 0.0, 0.0, 1.0))
@test !allunique(FloatRange(0.0, 0.0, 2.0, 1.0))
if VERSION < v"0.6.0-dev.2390"
@test allunique(FloatRange(0.0, 0.0, 0.0, 1.0))
@test !allunique(FloatRange(0.0, 0.0, 2.0, 1.0))
end

# Add test for Base.view
let a = rand(10,10)
Expand Down

0 comments on commit 4e8b7b3

Please sign in to comment.