From be4cedb916df614aed9526de92b7668c5fe4f3ca Mon Sep 17 00:00:00 2001 From: fcard Date: Sun, 16 Oct 2016 10:02:43 -0300 Subject: [PATCH] Add tests for more permissive any/all with non-boolean collections --- test/reduce.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/reduce.jl b/test/reduce.jl index 24e8a9cfa9e35..40d6ac8a0149f 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -212,6 +212,23 @@ let c = Int[], d = Int[], A = 1:9 @test d == collect(1:5) end +# any/all with non-boolean collections + +let f(x) = x == 1 ? true : x == 2 ? false : 1 + @test any(Any[false,true,false]) + @test any(map(f, [2,1,2])) + @test any([f(x) for x in [2,1,2]]) + + @test all(Any[true,true,true]) + @test all(map(f, [1,1,1])) + @test all([f(x) for x in [1,1,1]]) + + @test_throws TypeError any([1,true]) + @test_throws TypeError all([true,1]) + @test_throws TypeError any(map(f,[3,1])) + @test_throws TypeError all(map(f,[1,3])) +end + # any and all with functors immutable SomeFunctor end