-
Notifications
You must be signed in to change notification settings - Fork 86
/
lazy_iterators.jl
57 lines (47 loc) · 1.3 KB
/
lazy_iterators.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
# Copyright (c) 2017: Miles Lubin and contributors
# Copyright (c) 2017: Google Inc.
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
module TestLazyIterators
using Test
import MathOptInterface as MOI
function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$(name)", "test_")
@testset "$(name)" begin
getfield(@__MODULE__, name)()
end
end
end
return
end
function _test_EmptyVector(T)
v = MOI.Utilities.EmptyVector{T}()
@test size(v) == (0,)
@test length(v) == 0
@test isempty(v)
@test eltype(v) == T
@test iterate(v) === nothing
c = collect(v)
@test c isa Vector{T}
@test isempty(c)
return
end
test_EmptyVector_Int() = _test_EmptyVector(Int)
test_EmptyVector_Float64() = _test_EmptyVector(Float64)
function _test_LazyMap(T)
v = MOI.Utilities.LazyMap{T}(x -> x^2, [2, 3])
@test size(v) == (2,)
@test length(v) == 2
@test !isempty(v)
@test eltype(v) == T
c = collect(v)
@test c isa Vector{T}
@test c == [4, 9]
return
end
test_LazyMap_Int() = _test_LazyMap(Int)
test_LazyMap_Float64() = _test_LazyMap(Float64)
end # module
TestLazyIterators.runtests()