<commit_before>package ohnosequences.stuff.test.tuples

import ohnosequences.stuff._, Function._, products._
import scala.{ Int, Boolean }
import scala.Predef.String
import org.scalatest.FunSuite

class TuplesSyntax extends FunSuite {

  val l           = Function { x: String => x.length }
  val toStr       = Function { x: Int => x.toString }
  val isZero      = Function { x: Int => x == 0 }
  val isPositive  = Function { x: Int => x > -1 }
  val plusOne     = Function { x: Int => x + 1 }
  val isEmpty     = Function { x: String => x.isEmpty }

  test("build tuple values") {

    val buh: (String × Int) -> (Int × String) =
      l × toStr

    val boh: (String -> Int) × (Int -> String) × (String -> Boolean) =
      l & toStr & isEmpty

    assert {
      πL(l & toStr & isEmpty)    === (l & toStr)  &&
      left(l & toStr & isEmpty)  === (l & toStr)  &&
      πR(l & toStr & isEmpty)    === isEmpty      &&
      right(l & toStr & isEmpty) === isEmpty
    }
  }

  test("product universal") {

    val x =
      both(toStr & isZero)

    val y =
      both(both(toStr & isZero) & isZero)

    val yAgain =
      all3(toStr & isZero & isZero)

    assert {
      all3(toStr & isZero & isZero)(1) === ("1" & false & false)    &&
      // all3(isPositive & isZero & plusOne)(1) === (true & false & 2) && // awful; & is a method on Boolean
      y(12) === yAgain(12)
    }
  }
}<commit_msg>add a couple of fn eval tests<commit_after>package ohnosequences.stuff.test.tuples

import ohnosequences.stuff._, Function._, products._
import scala.{ Int, Boolean }
import scala.Predef.String
import org.scalatest.FunSuite

class TuplesSyntax extends FunSuite {

  val l           = Function { x: String => x.length }
  val toStr       = Function { x: Int => x.toString }
  val isZero      = Function { x: Int => x == 0 }
  val isPositive  = Function { x: Int => x > -1 }
  val plusOne     = Function { x: Int => x + 1 }
  val isEmpty     = Function { x: String => x.isEmpty }

  test("build tuple values") {

    val buh: (String × Int) -> (Int × String) =
      l × toStr

    val boh: (String -> Int) × (Int -> String) × (String -> Boolean) =
      l & toStr & isEmpty

    assert {
      πL(l & toStr & isEmpty)    === (l & toStr)  &&
      left(l & toStr & isEmpty)  === (l & toStr)  &&
      πR(l & toStr & isEmpty)    === isEmpty      &&
      right(l & toStr & isEmpty) === isEmpty
    }
  }

  test("product universal") {

    val x =
      both(toStr & isZero)

    val y =
      both(both(toStr & isZero) & isZero)

    val yAgain =
      all3(toStr & isZero & isZero)

    assert {
      all3(toStr & isZero & isZero)(1) === ("1" & false & false)    &&
      // all3(isPositive & isZero & plusOne)(1) === (true & false & 2) && // awful; & is a method on Boolean
      y(12) === yAgain(12)
    }
  }

  val iterations =
    10000000

  test("std evaluation") {

    import scala.Predef._

    val f = { x: Int => x.toString }
    val g = { x: Int => (x == 0) }
    val h = { x: Int => (x == 0) }

    for(i <- 1 to iterations) {
      val zzz = (f(i), g(i), h(i))
    }
  }

  test("std inline evaluation") {

    import scala.Predef._

    for(i <- 1 to iterations) {
      val zzz = (({ x: Int => x.toString })(i), ({ x: Int => (x == 0) })(i), ({ x: Int => (x == 0) })(i))
    }
  }

  test("allX evaluation") {

    val f = all3(toStr & isZero & isZero)

    import scala.Predef._

    for(i <- 1 to iterations) {
      val zzz = f(i)
    }
  }
}
{'fraction_non_alphanumeric': 0.16020821283979178, 'fraction_numerical': 0.012724117987275883, 'mean_word_length': 2.116216216216216, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '6521075', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1221, 'n_words': 360}