Skip to content

Commit

Permalink
Adjust type of set difference components
Browse files Browse the repository at this point in the history
  • Loading branch information
laschuet committed Feb 17, 2020
1 parent 514a821 commit a4c3c08
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DifferencesBase"
uuid = "f7c07657-0d0a-4d46-b086-01df223a7b4f"
authors = ["Lars Schütz"]
version = "0.2.0"
version = "0.3.0"

[deps]
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Expand Down
9 changes: 6 additions & 3 deletions src/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
Set difference.
"""
struct SetDifference{T}
comvals::Vector{T}
addvals::Vector{T}
remvals::Vector{T}
comvals::Set{T}
addvals::Set{T}
remvals::Set{T}
end
SetDifference(comvals::AbstractVector{T}, addvals::AbstractVector{T},
remvals::AbstractVector{T}) where {T} =
SetDifference(Set(comvals), Set(addvals), Set(remvals))

# Set difference equality operator
==(a::SetDifference, b::SetDifference) =
Expand Down
14 changes: 9 additions & 5 deletions test/set.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
@testset "set difference" begin
a = SetDifference([1], [2, 3], [4, 5])
a = SetDifference(Set([1]), Set([2, 3]), Set([4, 5]))
b = SetDifference([1], [2, 3], [4, 5])
c = SetDifference([1], [2, 3], [4, 5])

@testset "constructors" begin
@test isa(a, SetDifference)
@test a.comvals == [1] && a.addvals == [2, 3] && a.remvals == [4, 5]
@test (a.comvals == Set([1]) && a.addvals == Set([2, 3])
&& a.remvals == Set([4, 5]))
@test isa(b, SetDifference)
@test (b.comvals == Set([1]) && b.addvals == Set([2, 3])
&& b.remvals == Set([4, 5]))
end

@testset "equality operator" begin
Expand All @@ -20,8 +24,8 @@
end

@testset "accessors" begin
@test common(a) == [1]
@test added(a) == [2, 3]
@test removed(a) == [4, 5]
@test common(a) == Set([1])
@test added(a) == Set([2, 3])
@test removed(a) == Set([4, 5])
end
end

0 comments on commit a4c3c08

Please sign in to comment.