Improved treatment of border cases

Added tests for border cases like empty inputs and
zero-sized samples, as well as tests for the
iterator behavior when 'next' should cause an
NoSuchElementException