<commit_before>package net.detunized.iteratorz

import org.specs2.mutable.Specification

class PoolingIteratorSpec extends Specification {
  "have no next on an empty iterator" in {
    checkEmpty(1)
  }

  "throw on zero pool size" in {
    checkEmpty(0) should throwA[IllegalArgumentException]
  }

  "throw on negative pool size" in {
    checkEmpty(-1) should throwA[IllegalArgumentException]
  }

  "return the same sequence with different pool sizes" in {
    val s = Seq(1, 2, 3)
    check(s, 1)
    check(s, 2)
    check(s, 3)
    check(s, 4)
    check(s, 5)
  }

  def check[A](s: Seq[A], poolSize: Int) = {
    val i = new PoolingIterator(s.iterator, poolSize)(x => x)

    // Should be the same as source sequence
    s foreach { x =>
      i.hasNext should beTrue
      i.next() shouldEqual x
    }

    i.hasNext should beFalse
    i.next() should throwA[NoSuchElementException]
  }

  def checkEmpty(poolSize: Int) = check(Seq[Int](), poolSize)
}<commit_msg>PoolingIterator uses IteratorSpec<commit_after>package net.detunized.iteratorz

class PoolingIteratorSpec extends IteratorSpec[Int] {
  "throw on zero pool size" in {
    mk(0) should throwA[IllegalArgumentException]
  }

  "throw on negative pool size" in {
    mk(-1) should throwA[IllegalArgumentException]
  }

  "return the same sequence with different pool sizes" in {
    val s = Seq(1, 2, 3)
    check(mk(1, s:_*), s:_*)
    check(mk(2, s:_*), s:_*)
    check(mk(3, s:_*), s:_*)
    check(mk(4, s:_*), s:_*)
    check(mk(5, s:_*), s:_*)
  }

  // TODO: Test that poolFilled callback is called.

  protected[this] def mkEmpty = mk(1)
  private[this] def mk(poolSize: Int, s: T*) = new PoolingIterator(s.iterator, poolSize)(x => x)
}
{'fraction_non_alphanumeric': 0.12624196376388078, 'fraction_numerical': 0.013442431326709527, 'mean_word_length': 3.4583333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7236468', 'n_tokens_mistral': 609, 'n_tokens_neox': 589, 'n_words': 173}