<commit_before>import akka.actor.ActorSystem
import akka.testkit.{TestActorRef, TestProbe, TestKit}
import models._
import org.scalatest.{BeforeAndAfterAll, Matchers, GivenWhenThen, FeatureSpecLike}

import scala.util.Random

class TransactionHandlerSpec extends TestKit(ActorSystem("TransactionHandlerSpec")) with
  FeatureSpecLike with
  GivenWhenThen with
  Matchers with
  BeforeAndAfterAll {

  /** Shutdown actor system when finished. */
  override def afterAll(): Unit = {
    system.shutdown()
  }

  def generateRandomPrice(maxPrice: Double = 1000.0): Double = {
    Random.nextDouble() * maxPrice
  }

  def generateRandomQuantity(maxQuantity: Int = 10000): Int = {
    Random.nextInt(maxQuantity)
  }

  val testInstrument = "GOOG"


  feature("TransactionHandler should receive Fills.") {

    scenario("TransactionHandler receives a PartialFill.") {

      val transactionHandlerRef = TestActorRef(new TransactionHandler)

      val transactionHandler = transactionHandlerRef.underlyingActor

      Given("An existing PartialFill")

      val askTradingParty = TestProbe()

      val bidTradingParty = TestProbe()

      val fillPrice = generateRandomPrice()

      val fillQuantity = generateRandomQuantity()

      val partialFill = PartialFill(askTradingParty.ref,
                                    bidTradingParty.ref,
                                    testInstrument,
                                    fillPrice,
                                    fillQuantity)

      When("TransactionHandler receives the PartialFill")

      transactionHandlerRef ! partialFill

      Then("TransactionHandler should send requests for payment and securities.")

      val securitiesRequest = RequestSecurities(testInstrument, fillQuantity)
      askTradingParty.expectMsg(securitiesRequest)

      val paymentRequest = RequestPayment(fillPrice * fillQuantity)
      bidTradingParty.expectMsg(paymentRequest)

    }

    scenario("TransactionHandler receives a TotalFill.") {

      val transactionHandlerRef = TestActorRef(new TransactionHandler)

      val transactionHandler = transactionHandlerRef.underlyingActor<commit_msg>Fixed typo.<commit_after>import akka.actor.ActorSystem
import akka.testkit.{TestActorRef, TestProbe, TestKit}
import models._
import org.scalatest.{BeforeAndAfterAll, Matchers, GivenWhenThen, FeatureSpecLike}

import scala.util.Random

class TransactionHandlerSpec extends TestKit(ActorSystem("TransactionHandlerSpec")) with
  FeatureSpecLike with
  GivenWhenThen with
  Matchers with
  BeforeAndAfterAll {

  /** Shutdown actor system when finished. */
  override def afterAll(): Unit = {
    system.shutdown()
  }

  def generateRandomAmount(maxAmount: Double = 1e6): Double = {
    Random.nextDouble() * maxAmount
  }

  def generateRandomPrice(maxPrice: Double = 1000.0): Double = {
    Random.nextDouble() * maxPrice
  }

  def generateRandomQuantity(maxQuantity: Int = 10000): Int = {
    Random.nextInt(maxQuantity)
  }

  val testInstrument = "GOOG"


  feature("TransactionHandler should receive Fills.") {

    scenario("TransactionHandler receives a PartialFill.") {

      val transactionHandlerRef = TestActorRef(new TransactionHandler)

      val transactionHandler = transactionHandlerRef.underlyingActor

      Given("An existing PartialFill")

      val askTradingParty = TestProbe()

      val bidTradingParty = TestProbe()

      val fillPrice = generateRandomPrice()

      val fillQuantity = generateRandomQuantity()

      val partialFill = PartialFill(askTradingParty.ref,
                                    bidTradingParty.ref,
                                    testInstrument,
                                    fillPrice,
                                    fillQuantity)

      When("TransactionHandler receives a PartialFill")

      transactionHandlerRef ! partialFill

      Then("TransactionHandler should send requests for payment and securities.")

      val securitiesRequest = RequestSecurities(testInstrument, fillQuantity)
      askTradingParty.expectMsg(securitiesRequest)

      val paymentRequest = RequestPayment(fillPrice * fillQuantity)
      bidTradingParty.expectMsg(paymentRequest)

    }

    scenario("TransactionHandler receives a TotalFill.") {

      val transactionHandlerRef = TestActorRef(new TransactionHandler)

      val transactionHandler = transactionHandlerRef.underlyingActor
{'fraction_non_alphanumeric': 0.07056405572048413, 'fraction_numerical': 0.005023978077186572, 'mean_word_length': 3.2318840579710146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7371050', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1050, 'n_words': 257}