<commit_before>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package swave.core.impl.stages

import org.scalacheck.Gen
import org.scalatest.Inspectors
import swave.core.internal.testkit.{TestError, TestFixture}
import swave.core.{Buffer, StreamEnv, StreamLimitExceeded}

final class SimpleOpSpec extends SyncPipeSpec with Inspectors {

  implicit val env    = StreamEnv()
  implicit val config = PropertyCheckConfiguration(minSuccessful = 1000)

  implicit val integerInput = Gen.chooseNum(0, 999)
  implicit val stringInput  = Gen.listOfN(3, Gen.alphaNumChar).map(_.mkString)

  "Buffer" in check {
    testSetup
      .input[Int]
      .output[Int]
      .param(Gen.chooseNum(0, 16))
      .prop
      .from { (in, out, param) ⇒
        in.spout
          .buffer(param)
          .drainTo(out.drain) shouldTerminate asScripted(in)

        out.received shouldEqual in.produced.take(out.size)
      }
  }

  "BufferDropping" in check {
    import Buffer.OverflowStrategy._
    testSetup
      .input[Int]
      .output[Int]
      .param(Gen.oneOf(DropHead, DropTail, DropBuffer, DropNew))
      .prop
      .from { (in, out, param) ⇒
        in.spout
          .bufferDropping(4, param)
          .drainTo(out.drain) shouldTerminate asScripted(in)
      }
  }

  "Collect" in check {
    testSetup
      .withRandomSeed("<KEY>
      .withTracing()
      .input[Int]
      .output[Int]
      .prop
      .from { (in, out) ⇒
        in.spout
          .collect { case x if x < 100 ⇒ x * 2 }
          .drainTo(out.drain) shouldTerminate asScripted(in)

        out.received shouldEqual in.produced.collect({ case x if x < 100 ⇒ x * 2 }).take(out.scriptedSize)
      }<commit_msg>=cor fully reenable restricted test<commit_after>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package swave.core.impl.stages

import org.scalacheck.Gen
import org.scalatest.Inspectors
import swave.core.internal.testkit.{TestError, TestFixture}
import swave.core.{Buffer, StreamEnv, StreamLimitExceeded}

final class SimpleOpSpec extends SyncPipeSpec with Inspectors {

  implicit val env    = StreamEnv()
  implicit val config = PropertyCheckConfiguration(minSuccessful = 1000)

  implicit val integerInput = Gen.chooseNum(0, 999)
  implicit val stringInput  = Gen.listOfN(3, Gen.alphaNumChar).map(_.mkString)

  "Buffer" in check {
    testSetup
      .input[Int]
      .output[Int]
      .param(Gen.chooseNum(0, 16))
      .prop
      .from { (in, out, param) ⇒
        in.spout
          .buffer(param)
          .drainTo(out.drain) shouldTerminate asScripted(in)

        out.received shouldEqual in.produced.take(out.size)
      }
  }

  "BufferDropping" in check {
    import Buffer.OverflowStrategy._
    testSetup
      .input[Int]
      .output[Int]
      .param(Gen.oneOf(DropHead, DropTail, DropBuffer, DropNew))
      .prop
      .from { (in, out, param) ⇒
        in.spout
          .bufferDropping(4, param)
          .drainTo(out.drain) shouldTerminate asScripted(in)
      }
  }

  "Collect" in check {
    testSetup
      .input[Int]
      .output[Int]
      .prop
      .from { (in, out) ⇒
        in.spout
          .collect { case x if x < 100 ⇒ x * 2 }
          .drainTo(out.drain) shouldTerminate asScripted(in)

        out.received shouldEqual in.produced.collect({ case x if x < 100 ⇒ x * 2 }).take(out.scriptedSize)
      }
{'fraction_non_alphanumeric': 0.108529250956807, 'fraction_numerical': 0.01366867140513942, 'mean_word_length': 2.542110358180058, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, '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': '5712153', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1215, 'n_words': 318}