<commit_before>package collection

import org.scalatest.FunSuite

import scala.collection.mutable.ArrayBuffer
import scala.language.postfixOps

class FunctionalTest extends FunSuite {
  test("list *") {
    val list = List(1, 2, 3)
    assert(list.head == 1)
    assert(list.tail == List(2, 3))
    assert(list.last == 3)
    assert(list.sum == 6)
    assert(list.filter(_ > 1) == List(2, 3))
    assert(list.map(_ * 2) == List(2, 4, 6))
    assert((list drop 1) == List(2, 3))
    assert(list.dropWhile(_ < 2) == List(2, 3))
    assert(list.dropRight(1) == List(1, 2))
    assert((list take 2) == List(1, 2))
    assert(list.takeWhile(_ < 3) == List(1, 2))
    assert(list.takeRight(1) == List(3))
    assert(list.slice(0, 2) == List(1, 2))
    assert(list.mkString(", ") == "1, 2, 3")
  }
  
  test("diff") {
    val xs = List(1, 2)
    val ys = List(2, 3)
    assert((xs diff ys) == List(1))
    assert((ys diff xs) == List(3))
  }

  test("filter") {
    val list = List(1, 2, 3)
    assert(list.filter(_ > 1) == List(2, 3))
    assert(list.filter(_ > 1).map(_ * 2) == List(4, 6))
  }

  test("flatten") {
    val xs = List(List(1, 2), List(3, 4))
    assert(xs.flatten == List(1, 2, 3, 4))

    val ys = List(Some(1), None, Some(3), None)
    assert(ys.flatten == List(1, 3))
  }

  test("map") {
    val list = List(1, 2)
    val result = list map (_ * 2)
    assert(result == List(2, 4))
  }

  test("flatmap") {
    val xs = List("abc")
    assert(xs.flatMap(_.toUpperCase) == List('A', 'B', 'C'))

    val map = Map(1 -> "one", 2 -> "two", 3 -> "three")
    assert((1 to map.size flatMap map.get) == List("one", "two", "three"))

    def g(v: Int) = List(v - 1, v, v + 1)
    val ys = List(1, 2, 3)
    assert(ys.map(i => g(i)) == List(List(0, 1, 2), List(1, 2, 3), List(2, 3, 4)))
    assert(ys.flatMap(i => g(i)) == List(0, 1, 2, 1, 2, 3, 2, 3, 4))

    val listOfList: List[List[String]] = List(List("a", "b", "c"))
    val flatMappedListOfList = listOfList flatMap (as => as.map(a => a.toUpperCase))
    assert(listOfList.length == 1)
    assert(flatMappedListOfList.length == 3)
  }

  test("fold") {
    val list = List(1, 2, 3)
    assert(list.foldLeft(3)(_ + _) == 9)
    assert(list.foldRight(3)(_ + _) == 9)
  }

  test("groupBy") {
    val list = List(1, 2, 3, 4)
    assert(list.groupBy(_ % 2 == 0) == Map(false -> List(1, 3), true -> List(2, 4)))
  }

  test("merge") {
    assert(List(1, 2, 3) ++ List(4, 5, 6) == List(1, 2, 3, 4, 5, 6))
    assert((ArrayBuffer(1, 2, 3) ++= List(4, 5, 6)) == ArrayBuffer(1, 2, 3, 4, 5, 6))<commit_msg>renamed function<commit_after>package collection

import org.scalatest.FunSuite

import scala.collection.mutable.ArrayBuffer
import scala.language.postfixOps

class FunctionalTest extends FunSuite {
  test("list *") {
    val list = List(1, 2, 3)
    assert(list.head == 1)
    assert(list.tail == List(2, 3))
    assert(list.last == 3)
    assert(list.sum == 6)
    assert(list.filter(_ > 1) == List(2, 3))
    assert(list.map(_ * 2) == List(2, 4, 6))
    assert((list drop 1) == List(2, 3))
    assert(list.dropWhile(_ < 2) == List(2, 3))
    assert(list.dropRight(1) == List(1, 2))
    assert((list take 2) == List(1, 2))
    assert(list.takeWhile(_ < 3) == List(1, 2))
    assert(list.takeRight(1) == List(3))
    assert(list.slice(0, 2) == List(1, 2))
    assert(list.mkString(", ") == "1, 2, 3")
  }
  
  test("diff") {
    val xs = List(1, 2)
    val ys = List(2, 3)
    assert((xs diff ys) == List(1))
    assert((ys diff xs) == List(3))
  }

  test("filter") {
    val list = List(1, 2, 3)
    assert(list.filter(_ > 1) == List(2, 3))
    assert(list.filter(_ > 1).map(_ * 2) == List(4, 6))
  }

  test("flatten") {
    val xs = List(List(1, 2), List(3, 4))
    assert(xs.flatten == List(1, 2, 3, 4))

    val ys = List(Some(1), None, Some(3), None)
    assert(ys.flatten == List(1, 3))
  }

  test("map") {
    val list = List(1, 2)
    val result = list map (_ * 2)
    assert(result == List(2, 4))
  }

  test("flatmap") {
    val xs = List("abc")
    assert(xs.flatMap(_.toUpperCase) == List('A', 'B', 'C'))

    val map = Map(1 -> "one", 2 -> "two", 3 -> "three")
    assert((1 to map.size flatMap map.get) == List("one", "two", "three"))

    def toList(v: Int) = List(v - 1, v, v + 1)
    val ys = List(1, 2, 3)
    assert(ys.map(i => toList(i)) == List(List(0, 1, 2), List(1, 2, 3), List(2, 3, 4)))
    assert(ys.flatMap(i => toList(i)) == List(0, 1, 2, 1, 2, 3, 2, 3, 4))

    val listOfList: List[List[String]] = List(List("a", "b", "c"))
    val flatMappedListOfList = listOfList flatMap (as => as.map(a => a.toUpperCase))
    assert(listOfList.length == 1)
    assert(flatMappedListOfList.length == 3)
  }

  test("fold") {
    val list = List(1, 2, 3)
    assert(list.foldLeft(3)(_ + _) == 9)
    assert(list.foldRight(3)(_ + _) == 9)
  }

  test("groupBy") {
    val list = List(1, 2, 3, 4)
    assert(list.groupBy(_ % 2 == 0) == Map(false -> List(1, 3), true -> List(2, 4)))
  }

  test("merge") {
    assert(List(1, 2, 3) ++ List(4, 5, 6) == List(1, 2, 3, 4, 5, 6))
    assert((ArrayBuffer(1, 2, 3) ++= List(4, 5, 6)) == ArrayBuffer(1, 2, 3, 4, 5, 6))
{'fraction_non_alphanumeric': 0.22088040514218932, 'fraction_numerical': 0.05531749123490456, 'mean_word_length': 2.999221183800623, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '4221441', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2089, 'n_words': 520}