Skip to content

Commit 93a6cdb

Browse files
authored
Merge pull request #19 from yashcodes/master
SortedVector.jl is modified
2 parents bfb7478 + 7d2af5f commit 93a6cdb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/SortedVectors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct SortedVector{T, F<:Function}
1515
by::F
1616

1717
function SortedVector(data::Vector{T}, by::F) where {T,F}
18-
new{T,F}(sort(data), by)
18+
new{T,F}(sort(data,by=by), by)
1919
end
2020
end
2121

test/sorted_vector.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,16 @@ const SortedVector = IntervalOptimisation.SortedVector
3535
@test v.data == [(1, "x"), (2, "b"), (3, "z"), (4, "y"), (5, "a"), (6, "z")]
3636

3737
end
38+
@testset "With ordering fucntion which compares values of index other than 1" begin
39+
40+
v = SortedVector([(2,"z"), (1,"a")], x->x[2])
41+
@test v.data ==[(1,"a"), (2,"z")]
42+
43+
push!(v, (3, "x"))
44+
@test v.data == [(1, "a"), (3, "x"), (2, "z")]
45+
46+
push!(v, (4, "c"), (5, "y"))
47+
@test v.data == [(1, "a"), (4, "c"), (3, "x"), (5, "y"), (2, "z")]
48+
end
3849

3950
end

0 commit comments

Comments
 (0)