-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathPersistentSetTest.jl
77 lines (60 loc) · 2.1 KB
/
PersistentSetTest.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using FunctionalCollections
using Test
const PS = PersistentSet
@testset "Persistent Sets" begin
@testset "construction" begin
s = PS([1, 1, 2, 3, 3])
@test length(s) == 3
@test length(PS{String}()) == 0
@test typeof(PS{Int64}([1,2,3])) == PS{Int64}
@test typeof(PS(Int64[1,2,3])) == PS{Int64}
end
@testset "isequal" begin
@test PS([1, 2, 3]) == PS([1, 2, 3])
@test PS([1, 2, 3]) == PS([3, 2, 1])
@test PS{String}() == PS{Int}()
end
@testset "push" begin
@test push(PS([1, 2, 3]), 4) == PS([1, 2, 3, 4])
@test push(PS([1, 2, 3]), 1) == PS([1, 2, 3])
@test push(PS([1, 2, 3]), 4) == PS([4, 3, 2, 1])
end
@testset "disj" begin
@test disj(PS([1, 2, 3]), 3) == PS([1, 2])
@test disj(PS([1, 2]), 3) == PS([1, 2])
@test disj(PS{Int}(), 1234) == PS{Int}()
end
@testset "in" begin
@test "foo" in PS(["foo", "bar"])
@test !("baz" in PS(["foo", "bar"]))
end
@testset "filter" begin
@test filter(iseven, PS([1, 2, 3, 4])) == PS([2, 4])
end
@testset "setdiff, -" begin
@test setdiff(PS([1, 2, 3]), PS([1, 2])) == PS([3])
@test setdiff(PS([1, 2]), PS([1, 2, 3])) == PS{Int}()
@test setdiff(PS([1, 2, 3]), Set([1, 2])) == PS([3])
@test PS([1, 2, 3]) - PS([1, 2]) == PS([3])
end
@testset "isempty" begin
@test isempty(PS{Int}())
@test !isempty(PS([1]))
end
@testset "union" begin
@test union(PS([1, 2, 3]), PS([4, 5])) == PS([1, 2, 3, 4, 5])
@test union(PS([1, 2, 3]), PS([1, 2, 3, 4])) == PS([1, 2, 3, 4])
@test union(PS([1]), PS([2]), PS([3])) == PS([1, 2, 3])
end
@testset "isless, <=" begin
@test PS([1]) <= PS([1, 2])
@test PS([1, 2]) <= PS([1, 2])
@test !(PS([1, 2, 3]) <= PS([1, 2]))
@test PS([1, 2]) <= PS([1, 2, 3])
@test !isless(PS([1, 2]), PS([1, 2]))
@test isless(PS([1, 2]), PS([1, 2, 3]))
end
@testset "iteration" begin
@test length([el for el in PS([1, 2, 3, 4])]) == 4
end
end