Skip to content

Commit 3228e27

Browse files
committed
great bug fixes and test additions by @Roger-luo
1 parent ebd92dd commit 3228e27

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/TupleTools.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ end
216216
Returns the value and index of the maximum element in a tuple. If there are multiple
217217
maximal elements, then the first one will be returned.
218218
"""
219-
findmax(::Tuple{Any}) = (t[1], 1)
219+
findmax(t::Tuple{Any}) = (t[1], 1)
220220
findmax(t::Tuple) = _findmax(tail(t),2,t[1],1)
221221
_findmax(t::Tuple{}, s, v, i) = (v, i)
222222
@inline function _findmax(t::Tuple, s, v, i)

test/runtests.jl

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ ip = invperm(p)
1010

1111
t = (p...,)
1212

13+
@test @inferred(TupleTools.argtail2(1, 2, 3, 4)) == (3, 4)
1314
@test @inferred(TupleTools.tail2(t)) == t[3:n]
1415
@test @inferred(TupleTools.unsafe_tail(t)) == t[2:n]
1516
@test @inferred(TupleTools.unsafe_front(t)) == t[1:n-1]
1617
@test @inferred(TupleTools.unsafe_tail(())) == ()
1718
@test @inferred(TupleTools.unsafe_front(())) == ()
18-
19+
@test @inferred(TupleTools.vcat()) == ()
20+
@test @inferred(TupleTools.vcat((1, 2))) == (1, 2)
21+
@test @inferred(TupleTools.getindices(t, ())) == ()
1922
@test @inferred(TupleTools.getindices(t, (1,2,3))) == t[1:3]
2023

24+
@test @inferred(TupleTools.deleteat((1, 2), (1, ))) == (2, )
2125
for i = 1:n
2226
@test @inferred(TupleTools.deleteat(t, i)) == (deleteat!(copy(p), i)...,)
2327
@test @inferred(TupleTools.insertat(t, i, (1,2,3))) == (vcat(p[1:i-1], [1,2,3], p[i+1:n])...,)
@@ -28,23 +32,40 @@ for i = 0:n
2832
end
2933
@test @inferred(TupleTools.vcat((1,2,3),4,(5,),(),(6,7,8))) == (1,2,3,4,5,6,7,8)
3034

35+
@test @inferred(TupleTools.sum(())) == 0
36+
@test @inferred(TupleTools.sum((1, ))) == 1
3137
@test @inferred(TupleTools.sum(t)) == sum(t)
38+
@test @inferred(TupleTools.cumsum(())) == ()
39+
@test @inferred(TupleTools.cumsum((1, ))) == (1, )
3240
@test @inferred(TupleTools.cumsum(t)) == (cumsum(p)...,)
41+
@test @inferred(TupleTools.prod(())) == 1
42+
@test @inferred(TupleTools.prod((2, ))) == 2
3343
@test @inferred(TupleTools.prod(t)) == prod(t)
44+
@test @inferred(TupleTools.cumprod(())) == ()
45+
@test @inferred(TupleTools.cumprod((1, ))) == (1, )
3446
@test @inferred(TupleTools.cumprod(t)) == (cumprod(p)...,)
3547

36-
@test @inferred(TupleTools.findmin(t)) == findmin(t)
37-
@test @inferred(TupleTools.findmax(t)) == findmax(t)
38-
@test @inferred(TupleTools.minimum(t)) == minimum(t)
39-
@test @inferred(TupleTools.maximum(t)) == maximum(t)
40-
@test @inferred(TupleTools.argmin(t)) == argmin(t)
41-
@test @inferred(TupleTools.argmax(t)) == argmax(t)
48+
for a in (t, (1, ))
49+
@test @inferred(TupleTools.findmin(a)) == findmin(a)
50+
@test @inferred(TupleTools.findmax(a)) == findmax(a)
51+
@test @inferred(TupleTools.minimum(a)) == minimum(a)
52+
@test @inferred(TupleTools.maximum(a)) == maximum(a)
53+
@test @inferred(TupleTools.argmin(a)) == argmin(a)
54+
@test @inferred(TupleTools.argmax(a)) == argmax(a)
55+
end
4256

57+
@test @inferred(TupleTools.sort((1, ))) == (1, )
58+
@test @inferred(TupleTools.sort(())) == ()
4359
@test @inferred(TupleTools.sort(t; rev = true)) == (sort(p; rev = true)...,)
60+
@test @inferred(TupleTools.sort(t; rev = false)) == (sort(p; rev = false)..., )
4461
@test @inferred(TupleTools.sortperm(t)) == (sortperm(p)...,)
62+
@test @inferred(TupleTools.sortperm(t; rev=true)) == (sortperm(p; rev=true)..., )
4563
@test @inferred(TupleTools.invperm(t)) == (ip...,)
4664
@test @inferred(TupleTools.isperm(t)) == true
4765
@test @inferred(TupleTools.isperm((1,2,1))) == false
4866
@test @inferred(TupleTools.permute(t, t)) == (p[p]...,)
4967

68+
@test @inferred(TupleTools.vcat()) == ()
69+
@test @inferred(TupleTools.diff(())) == ()
70+
@test @inferred(TupleTools.diff((1, ))) == ()
5071
@test @inferred(TupleTools.diff((1, 2, 3))) == (1, 1)

0 commit comments

Comments
 (0)