<commit_before>package ml.wolfe.macros

import ml.wolfe.{Wolfe, WolfeSpec}
import scala.collection.mutable

/**
 * @author <NAME>
 */
class MetaStructureSpecs extends WolfeSpec {

  implicit class StructureTest[T](structure:Structure[T]) {
    def mustBeIsomorphicTo(expected:Iterable[T]) {
      val actual = new mutable.ArrayBuffer[T]()
      structure.resetSetting()
      while (structure.hasNextSetting) {
        structure.nextSetting()
        val value = structure.value()
        actual += value
      }
      actual.size should be (expected.size)
      actual.toSet should be (expected.toSet)

      for (t <- expected) {
        structure.observe(t)
        structure.resetSetting()
        structure.nextSetting()
        structure.value() should be (t)
      }

    }
  }
  implicit class StructureProjectionTest[T1,T2](pair:(Structure[T1],Structure[T1] => T2)) {
    def mustBeIsomorphicTo(that:(Iterable[T1],T1=>T2)) = {
      val expected = that._1
      val structure = pair._1
      val actual = new mutable.ArrayBuffer[T1]()
      structure.resetSetting()
      while (structure.hasNextSetting) {
        structure.nextSetting()
        val value = structure.value()
        val expectedProjection = that._2(value)
        val actualProjection = pair._2(structure)
        actualProjection should be (expectedProjection)
        actual += value
      }
      actual.size should be (expected.size)
      actual.toSet should be (expected.toSet)

      for (t <- expected) {
        structure.observe(t)
        structure.resetSetting()
        structure.nextSetting()
        structure.value() should be (t)
      }

    }
  }


  "A meta structure" should {
    "generate a structure for an atomic sequence of values" in {
      val space = Seq(false,true)
      val structure = MetaStructure.createStructure(space)
      structure mustBeIsomorphicTo space
      structure.nodes().size should be (1)
    }
    "generate a matching projection for an atomic sequence" in {
      val space = Seq(false,true)
      val (structure,projection) = MetaStructure.createStructureAndProjection[Boolean,Boolean](space, x => x)
      (structure,projection) mustBeIsomorphicTo (space,x => x)
    }
    "generate a structure for all case class objects within a cartesian product of arguments" in {
      import Wolfe._
      case class Data(x:Boolean,y:Boolean)
      val space = Wolfe.all(Data)
      val structure = MetaStructure.createStructure(space)
      structure mustBeIsomorphicTo space
      structure.nodes().size should be (2)
    }

    "generate a structure for all case class objects within a cartesian product of arguments blah " in {
      import Wolfe._
      case class Data(a1:Boolean,a2:Boolean)
      val space = Wolfe.all(Data)
      val (structure,projection) = MetaStructure.createStructureAndProjection[Data,Boolean](space, d => d.a1)
      (structure,projection) mustBeIsomorphicTo (space,_.a1)
    }

  }

}<commit_msg>better name for spec<commit_after>package ml.wolfe.macros

import ml.wolfe.{Wolfe, WolfeSpec}
import scala.collection.mutable

/**
 * @author <NAME>
 */
class MetaStructureSpecs extends WolfeSpec {

  implicit class StructureTest[T](structure:Structure[T]) {
    def mustBeIsomorphicTo(expected:Iterable[T]) {
      val actual = new mutable.ArrayBuffer[T]()
      structure.resetSetting()
      while (structure.hasNextSetting) {
        structure.nextSetting()
        val value = structure.value()
        actual += value
      }
      actual.size should be (expected.size)
      actual.toSet should be (expected.toSet)

      for (t <- expected) {
        structure.observe(t)
        structure.resetSetting()
        structure.nextSetting()
        structure.value() should be (t)
      }

    }
  }
  implicit class StructureProjectionTest[T1,T2](pair:(Structure[T1],Structure[T1] => T2)) {
    def mustBeIsomorphicTo(that:(Iterable[T1],T1=>T2)) = {
      val expected = that._1
      val structure = pair._1
      val actual = new mutable.ArrayBuffer[T1]()
      structure.resetSetting()
      while (structure.hasNextSetting) {
        structure.nextSetting()
        val value = structure.value()
        val expectedProjection = that._2(value)
        val actualProjection = pair._2(structure)
        actualProjection should be (expectedProjection)
        actual += value
      }
      actual.size should be (expected.size)
      actual.toSet should be (expected.toSet)

      for (t <- expected) {
        structure.observe(t)
        structure.resetSetting()
        structure.nextSetting()
        structure.value() should be (t)
      }

    }
  }


  "A meta structure" should {
    "generate a structure for an atomic sequence of values" in {
      val space = Seq(false,true)
      val structure = MetaStructure.createStructure(space)
      structure mustBeIsomorphicTo space
      structure.nodes().size should be (1)
    }
    "generate a matching projection for an atomic sequence" in {
      val space = Seq(false,true)
      val (structure,projection) = MetaStructure.createStructureAndProjection[Boolean,Boolean](space, x => x)
      (structure,projection) mustBeIsomorphicTo (space,x => x)
    }
    "generate a structure for all case class objects within a cartesian product of arguments" in {
      import Wolfe._
      case class Data(x:Boolean,y:Boolean)
      val space = Wolfe.all(Data)
      val structure = MetaStructure.createStructure(space)
      structure mustBeIsomorphicTo space
      structure.nodes().size should be (2)
    }

    "generate a structure and projection for case class spaces" in {
      import Wolfe._
      case class Data(a1:Boolean,a2:Boolean)
      val space = Wolfe.all(Data)
      val (structure,projection) = MetaStructure.createStructureAndProjection[Data,Boolean](space, d => d.a1)
      (structure,projection) mustBeIsomorphicTo (space,_.a1)
    }

  }

}
{'fraction_non_alphanumeric': 0.10049395332992676, 'fraction_numerical': 0.006472491909385114, 'mean_word_length': 2.917278185456971, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '932919', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1677, 'n_words': 427}