Skip to content

Commit

Permalink
Fix some improperly handled edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Kornblith committed Feb 16, 2020
1 parent 3a42269 commit 6529794
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/NaturalSort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function natural(x::AbstractString, y::AbstractString)
while cy == '0' && (itery = iterate(y, statey)) !== nothing
cy, statey = itery
end
if iterx === nothing || itery === nothing
break
end

# Begin comparing numbers
diff = false
Expand Down Expand Up @@ -67,6 +70,6 @@ function natural(x::AbstractString, y::AbstractString)
itery = iterate(y, statey)
end

return itery == nothing && iterx != nothing
return iterx == nothing && itery != nothing
end
end # module
7 changes: 5 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ using Test

# write your own tests here
STRS = [
"",
"a#",
"a0",
"a00",
"a0a",
"a1",
"a1b1",
"a1b2",
Expand Down Expand Up @@ -33,7 +35,8 @@ end

EQ_STRS = [
("a01", "a1"),
("a01b2", "a1b2")
("a01b2", "a1b2"),
("a0", "a00")
]
for (str, eqto) in EQ_STRS
for i = 1:findfirst(x->x == eqto, STRS)-1
Expand Down

0 comments on commit 6529794

Please sign in to comment.