diff --git a/Example/Tests/QueueManagerTests.swift b/Example/Tests/QueueManagerTests.swift index febbb3c..eab499f 100644 --- a/Example/Tests/QueueManagerTests.swift +++ b/Example/Tests/QueueManagerTests.swift @@ -344,22 +344,20 @@ class QueueManagerTests: QuickSpec { // MARK: - Removal context("then removing a item with index less than currentIndex") { + var removed: Int? + var initialCurrentIndex: Int! beforeEach { - var removed: Int? - var initialCurrentIndex: Int! - beforeEach { - let _ = try? queue.jump(to: 3) - initialCurrentIndex = queue.currentIndex - removed = try? queue.removeItem(at: initialCurrentIndex - 1) - } - - it("should remove an item") { - expect(removed).toNot(beNil()) - } - - it("should decrement the currentIndex") { - expect(queue.currentIndex).to(equal(initialCurrentIndex - 1)) - } + let _ = try? queue.jump(to: 1) + initialCurrentIndex = queue.currentIndex + removed = try? queue.removeItem(at: initialCurrentIndex - 1) + } + + it("should remove an item") { + expect(removed).toNot(beNil()) + } + + it("should decrement the currentIndex") { + expect(queue.currentIndex).to(equal(initialCurrentIndex - 1)) } } diff --git a/SwiftAudioEx/Classes/QueueManager.swift b/SwiftAudioEx/Classes/QueueManager.swift index d6c7c53..4ba9ffe 100755 --- a/SwiftAudioEx/Classes/QueueManager.swift +++ b/SwiftAudioEx/Classes/QueueManager.swift @@ -223,9 +223,11 @@ class QueueManager { try throwIfIndexInvalid(index: index) let result = items.remove(at: index) - mutateCurrentIndex(index: index == currentIndex && items.count > 0 - ? currentIndex % items.count : -1 - ) + if index == currentIndex { + mutateCurrentIndex(index: items.count > 0 ? currentIndex % items.count : -1) + } else if index < currentIndex { + mutateCurrentIndex(index: currentIndex - 1) + } return result; }