-
Notifications
You must be signed in to change notification settings - Fork 24
/
test_inference.jl
63 lines (54 loc) · 1.81 KB
/
test_inference.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module TestInference
include("preamble.jl")
using Transducers: _nonidtype, DefaultId, OptId
collections = [
1:1,
1:0,
Base.Generator(identity, 1:1),
Base.Generator(identity, 1:0),
]
constant(x) = (_...) -> x
@testset "_nonidtype" begin
# This is required for "foldl without init" tests below work:
@test _nonidtype(Float64) === Float64
@test _nonidtype(Union{DefaultId{typeof(+)}, Float64}) === Float64
end
@testset "foldl" begin
@testset for xs in collections
@test_inferred foldl(+, Map(exp), xs; init=0.0)
@test_inferred foldl(+, Map(exp), xs; init=OptId)
@test_inferred foldl(+, Map(exp) |> Filter(x -> x > 0), xs; init=0.0)
@test_inferred foldl(+, Map(exp) |> Filter(x -> x > 0), xs; init=OptId)
end
@testset for xs in [
1:1,
Base.Generator(identity, 1:1),
]
@test_inferred foldl(+, Map(exp), xs)
@test_inferred foldl(+, Map(exp) |> Filter(x -> x > 0), xs)
@test_inferred foldl(+, Map(exp) |> Scan(+), xs)
@test_inferred foldl(+, TakeLast(1), xs)
@test_inferred foldl(+, PartitionBy(identity) |> Map(first), xs)
@test_inferred foldl(+, Unique(), xs)
end
end
@testset "collect" begin
@testset for xs in collections
@test_inferred collect(Map(exp), xs)
@test_inferred collect(Map(exp) |> Filter(x -> x > 0), xs)
end
end
@testset "foreach" begin
@testset for xs in collections
@test_inferred foreach(constant(nothing), Map(exp), xs)
@test_inferred foreach(constant(nothing), Map(exp) |> Filter(x -> x > 0),
xs)
end
end
@testset "eduction" begin
@testset for xs in collections
@test_inferred eduction(Map(exp), xs)
@test_inferred eduction(Map(exp) |> Filter(x -> x > 0), xs)
end
end
end # module