<commit_before>package hmda.validation.rules.ts.syntactical

import hmda.model.fi.ts.{ Respondent, TransmittalSheet }
import hmda.model.institution.Agency.CFPB
import hmda.model.institution.ExternalIdType.{ FdicCertNo, FederalTaxId, RssdId }
import hmda.model.institution.InstitutionType.Bank
import hmda.model.institution.{ ExternalId, Institution }
import hmda.parser.fi.ts.TsGenerators
import hmda.validation.context.ValidationContext
import hmda.validation.dsl.{ Failure, Success }
import org.scalacheck.Gen
import org.scalatest.{ MustMatchers, PropSpec }
import org.scalatest.prop.PropertyChecks

class S025Spec extends PropSpec with PropertyChecks with MustMatchers with TsGenerators {

  //Generate all Transmittal Sheets with hardcoded Respondent
  override implicit def tsGen: Gen[TransmittalSheet] = {
    for {
      timeStamp <- timeGen
      activityYear <- activityYearGen
      taxId <- taxIdGen
      parent <- parentGen
      contact <- contactGen
    } yield TransmittalSheet(
      1,
      9, //CFPB
      timeStamp,
      activityYear,
      taxId,
      10000,
      Respondent("999999", "Test Bank", "1234 Test St.", "Test City", "CA", "99999"),
      parent,
      contact
    )
  }

  property("Transmittal Sheet's agency code and respondent ID match that of a given institution") {
    val institution = Institution(1, "Test Bank", Set(ExternalId("999999", RssdId), ExternalId("9876543-21", FederalTaxId)), CFPB, Bank)
    val ctx = ValidationContext(Some(institution))

    forAll(tsGen) { ts =>
      S025(ts, ctx) mustBe Success()
    }
  }

  property("Transmittal Sheet's agency code and respondent ID does NOT match that of a given institution") {
    val institution = Institution(1, "Test Bank", Set(ExternalId("111111", RssdId), ExternalId("9876543-21", FederalTaxId)), CFPB, Bank)
    val ctx = ValidationContext(Some(institution))

    forAll(tsGen) { ts =>
      S025(ts, ctx) mustBe Failure()
    }
  }

  property("Institution's respondent ID cannot be derived") {
    val institution = Institution(1, "Test Bank", Set(ExternalId("111111", FdicCertNo), ExternalId("9876543-21", FederalTaxId)), CFPB, Bank)
    val ctx = ValidationContext(Some(institution))

    forAll(tsGen) { ts =>
      whenever(ts.id == 1) {
        S025(ts, ctx) mustBe Failure()
      }
    }
  }

}<commit_msg>Adds LAR-based tests for S025<commit_after>package hmda.validation.rules.ts.syntactical

import hmda.model.fi.lar._
import hmda.model.fi.ts.{ Contact, Parent, Respondent, TransmittalSheet }
import hmda.model.institution.Agency.CFPB
import hmda.model.institution.ExternalIdType.{ FdicCertNo, FederalTaxId, RssdId }
import hmda.model.institution.InstitutionType.Bank
import hmda.model.institution.{ ExternalId, Institution }
import hmda.validation.context.ValidationContext
import hmda.validation.dsl.{ Failure, Success }
import org.scalatest.{ MustMatchers, WordSpec }

class S025Spec extends WordSpec with MustMatchers {

  "Q025 for TS" must {

    val ts = TransmittalSheet(
      1,
      9, //CFPB,
      201602021453L,
      2017,
      "12-3456789",
      10000, Respondent("999999", "Test Bank", "1234 Bank St.", "Test Bank", "CA", "99999"),
      Parent("Test Parent", "1234 Parent St.", "Test City", "CA", "98765"),
      Contact("<NAME>", "123-456-7890", "987-654-3210", "<EMAIL>")
    )

    "succeed when TS's agency code and respondent ID match the Instititution's" in {
      val institution = Institution(1, "Test Bank", Set(ExternalId("999999", RssdId), ExternalId("9876543-21", FederalTaxId)), CFPB, Bank)
      val ctx = ValidationContext(Some(institution))

      S025(ts, ctx) mustBe Success()
    }

    "fail when TS's agency code and respondent ID do NOT match the Instititution's" in {
      val institution = Institution(1, "Test Bank", Set(ExternalId("111111", RssdId), ExternalId("9876543-21", FederalTaxId)), CFPB, Bank)
      val ctx = ValidationContext(Some(institution))

      S025(ts, ctx) mustBe Failure()
    }

    "fail when the Institution's respondent ID cannot be derived" in {
      val institution = Institution(1, "Test Bank", Set(ExternalId("111111", FdicCertNo), ExternalId("9876543-21", FederalTaxId)), CFPB, Bank)
      val ctx = ValidationContext(Some(institution))

      S025(ts, ctx) mustBe Failure()
    }
  }

  "Q025 for LAR" must {

    val lar = LoanApplicationRegister(
      2,
      "999999",
      9,
      Loan("12345678", "20170101", 1, 1, 1, 1, 1000000),
      1,
      1,
      1,
      Geography("", "", "", ""),
      Applicant(1, 1, 1, "", "", "", "", 1, "", "", "", "", 1, 1, ""),
      1,
      Denial("", "", ""),
      "",
      1,
      1
    )

    "succeed when LAR's agency code and respondent ID match the Instititution's" in {
      val institution = Institution(1, "Test Bank", Set(ExternalId("999999", RssdId), ExternalId("9876543-21", FederalTaxId)), CFPB, Bank)
      val ctx = ValidationContext(Some(institution))

      S025(lar, ctx) mustBe Success()
    }

    "fail when LAR's agency code and respondent ID do NOT match the Instititution's" in {
      val institution = Institution(1, "Test Bank", Set(ExternalId("111111", RssdId), ExternalId("9876543-21", FederalTaxId)), CFPB, Bank)
      val ctx = ValidationContext(Some(institution))

      S025(lar, ctx) mustBe Failure()
    }

    "fail when the Institution's respondent ID cannot be derived" in {
      val institution = Institution(1, "Test Bank", Set(ExternalId("111111", FdicCertNo), ExternalId("9876543-21", FederalTaxId)), CFPB, Bank)
      val ctx = ValidationContext(Some(institution))

      S025(lar, ctx) mustBe Failure()
    }
  }

}

{'fraction_non_alphanumeric': 0.12845180830215572, 'fraction_numerical': 0.05914840548726171, 'mean_word_length': 3.632013201320132, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4743306', 'n_tokens_mistral': 2090, 'n_tokens_neox': 1774, 'n_words': 479}