<commit_before>package net.detunized.iteratorz

import org.specs2.mutable.Specification

class RemappingIteratorSpec extends Specification {
  "have no next on an empty iterator" in {
    val i = mkEmpty("?", "?")

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

  "throw on blank from parameter" in {
    mkEmpty("", "?") should throwA[IllegalArgumentException]
  }

  // TODO: Test more failures!

  "return the same sequence with identity mapping" in {
    checkSame(Seq(1, 2, 3), "A", "A")
    checkSame(Seq(1, 2, 3, 4), "AB", "AB")
    checkSame(Seq(1, 2, 3, 4, 5, 6), "ABC", "ABC")
  }

  "swap elements" in {
    check(Seq(1, 2, 3, 4), "AB", "BA", Seq(2, 1, 4, 3))
    check(Seq(1, 2, 3), "ABC", "BCA", Seq(2, 3, 1))
    check(Seq(1, 2, 3, 4), "ABCD", "DCBA", Seq(4, 3, 2, 1))
  }

  "remove elements" in {
    check(Seq(1, 2, 3, 4), "AB", "A", Seq(1, 3))
    check(Seq(1, 2, 3, 4), "AB", "B", Seq(2, 4))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "A", Seq(1, 4))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "B", Seq(2, 5))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "C", Seq(3, 6))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "BC", Seq(2, 3, 5, 6))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "AC", Seq(1, 3, 4, 6))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "BC", Seq(2, 3, 5, 6))
  }

  "duplicate elements" in {
    check(Seq(1, 2, 3), "A", "AA", Seq(1, 1, 2, 2, 3, 3))
    check(Seq(1, 2, 3), "A", "AAA", Seq(1, 1, 1, 2, 2, 2, 3, 3, 3))
    check(Seq(1, 2, 3, 4), "AB", "AABB", Seq(1, 1, 2, 2, 3, 3, 4, 4))
    check(Seq(1, 2, 3, 4), "AB", "AAABBB", Seq(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "AABC", Seq(1, 1, 2, 3, 4, 4, 5, 6))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "ABBC", Seq(1, 2, 2, 3, 4, 5, 5, 6))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "ABCC", Seq(1, 2, 3, 3, 4, 5, 6, 6))
  }

  "swap, remove and duplicate" in {
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "CBB", Seq(3, 2, 2, 6, 5, 5))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "BAA", Seq(2, 1, 1, 5, 4, 4))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "CCA", Seq(3, 3, 1, 6, 6, 4))
    check(Seq(1, 2, 3, 4, 5, 6), "ABC", "CCCA", Seq(3, 3, 3, 1, 6, 6, 6, 4))
  }

  private def mk[A](s: Seq[A], from: String, to: String) = new RemappingIterator(s.iterator, from, to)
  private def mkEmpty[A](from: String, to: String) = mk(Seq[Int](), from, to)

  private def check[A](s: Seq[A], from: String, to: String, expected: Seq[A]) = {
    val i = mk(s, from, to)

    expected foreach { x =>
      i.hasNext should beTrue
      i.next() shouldEqual x
    }

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

  private def checkSame[A](s: Seq[A], from: String, to: String) =
    check(s, from, to, s)
}
<commit_msg>RemappingIteratorSpec uses IteratorSpec<commit_after>package net.detunized.iteratorz

class RemappingIteratorSpec extends IteratorSpec[Int] {
  "throw on blank from parameter" in {
    mk()("", "?") must throwA[IllegalArgumentException]
  }

  // TODO: Test more failures!

  "return the same sequence with identity mapping" in {
    mk(1, 2, 3)("A" -> "A") must expandTo(1, 2, 3)
    mk(1, 2, 3, 4)("AB" -> "AB") must expandTo(1, 2, 3, 4)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "ABC") must expandTo(1, 2, 3, 4, 5, 6)
  }

  "swap elements" in {
    mk(1, 2, 3, 4)("AB" -> "BA") must expandTo(2, 1, 4, 3)
    mk(1, 2, 3)("ABC" -> "BCA") must expandTo(2, 3, 1)
    mk(1, 2, 3, 4)("ABCD" -> "DCBA") must expandTo(4, 3, 2, 1)
  }

  "remove elements" in {
    mk(1, 2, 3, 4)("AB" -> "A") must expandTo(1, 3)
    mk(1, 2, 3, 4)("AB" -> "B") must expandTo(2, 4)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "A") must expandTo(1, 4)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "B") must expandTo(2, 5)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "C") must expandTo(3, 6)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "BC") must expandTo(2, 3, 5, 6)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "AC") must expandTo(1, 3, 4, 6)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "BC") must expandTo(2, 3, 5, 6)
  }

  "duplicate elements" in {
    mk(1, 2, 3)("A" -> "AA") must expandTo(1, 1, 2, 2, 3, 3)
    mk(1, 2, 3)("A" -> "AAA") must expandTo(1, 1, 1, 2, 2, 2, 3, 3, 3)
    mk(1, 2, 3, 4)("AB" -> "AABB") must expandTo(1, 1, 2, 2, 3, 3, 4, 4)
    mk(1, 2, 3, 4)("AB" -> "AAABBB") must expandTo(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "AABC") must expandTo(1, 1, 2, 3, 4, 4, 5, 6)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "ABBC") must expandTo(1, 2, 2, 3, 4, 5, 5, 6)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "ABCC") must expandTo(1, 2, 3, 3, 4, 5, 6, 6)
  }

  "swap, remove and duplicate" in {
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "CBB") must expandTo(3, 2, 2, 6, 5, 5)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "BAA") must expandTo(2, 1, 1, 5, 4, 4)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "CCA") must expandTo(3, 3, 1, 6, 6, 4)
    mk(1, 2, 3, 4, 5, 6)("ABC" -> "CCCA") must expandTo(3, 3, 3, 1, 6, 6, 6, 4)
  }

  protected[this] def mkEmpty = mk()("?", "?")

  private[this] def mk(s: T*)(mapping: (String, String)) =
    new RemappingIterator(s.iterator, mapping._1, mapping._2)
}

{'fraction_non_alphanumeric': 0.24778062734267114, 'fraction_numerical': 0.09863878477017163, 'mean_word_length': 3.049520766773163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '6428164', 'n_tokens_mistral': 2835, 'n_tokens_neox': 2370, 'n_words': 777}