Skip to content

Commit bd9f5df

Browse files
authored
Merge pull request cfpb#1098 from nickgrippin/q016-fix
Q016 - field reference fix
2 parents 567079d + 50660ea commit bd9f5df

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

persistence/src/test/scala/hmda/persistence/processing/HmdaFileValidatorSpec.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ class HmdaFileValidatorSpec extends ActorSpec with BeforeAndAfterEach with HmdaF
129129
List(
130130
MacroValidationError("Q008"),
131131
MacroValidationError("Q010"),
132-
MacroValidationError("Q016"),
133132
MacroValidationError("Q023")
134133
),
135134
macroVerified = false

validation/src/main/scala/hmda/validation/rules/lar/macro/Q016.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import hmda.validation.rules.AggregateEditCheck
1010
import hmda.validation.rules.lar.`macro`.MacroEditTypes._
1111

1212
import scala.concurrent.Future
13+
import scala.util.Try
1314

1415
object Q016 extends AggregateEditCheck[LoanApplicationRegisterSource, LoanApplicationRegister] {
1516

@@ -21,7 +22,9 @@ object Q016 extends AggregateEditCheck[LoanApplicationRegisterSource, LoanApplic
2122

2223
override def apply[as: AS, mat: MAT, ec: EC](lars: LoanApplicationRegisterSource): Future[Result] = {
2324

24-
val belowIncomeThreshold = count(lars.filter(lar => lar.loan.amount < incomeCap))
25+
val belowIncomeThreshold = count(lars
26+
.filter(lar => Try(lar.applicant.income.toDouble).isSuccess)
27+
.filter(lar => lar.applicant.income.toInt < incomeCap))
2528

2629
val total = count(lars)
2730

validation/src/test/scala/hmda/validation/rules/lar/macro/Q016Spec.scala

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,42 @@ class Q016Spec extends MacroSpec {
1313
val sampleSize = testLars.size
1414
val sampleSizeTarget = (testLars.size * multiplier).toInt
1515
def underCap(lar: LoanApplicationRegister) = {
16-
val underCapLoan = lar.loan.copy(amount = incomeCap - 1)
17-
lar.copy(loan = underCapLoan)
16+
val underCapApplicant = lar.applicant.copy(income = (incomeCap - 1).toString)
17+
lar.copy(applicant = underCapApplicant)
1818
}
1919
def overCap(lar: LoanApplicationRegister) = {
20-
val overCapLoan = lar.loan.copy(amount = incomeCap + 1)
21-
lar.copy(loan = overCapLoan)
20+
val overCapApplicant = lar.applicant.copy(income = incomeCap.toString)
21+
lar.copy(applicant = overCapApplicant)
2222
}
2323

24-
property(s"be valid if under cap loans < $multiplier * over cap loans") {
24+
def naIncome(lar: LoanApplicationRegister) = {
25+
val naApplicant = lar.applicant.copy(income = "NA")
26+
lar.copy(applicant = naApplicant)
27+
}
28+
29+
property(s"be valid if under cap loans < $multiplier * total loans") {
2530
val numOfRelevantLars = sampleSizeTarget - 1
2631
val validLarSource = newLarSource(testLars, numOfRelevantLars, underCap, overCap)
2732
validLarSource.mustPass
2833
}
2934

30-
property(s"be invalid if under cap loans = $multiplier * over cap loans") {
35+
property(s"be invalid if under cap loans = $multiplier * total loans") {
3136
val numOfRelevantLars = sampleSizeTarget
3237
val validLarSource = newLarSource(testLars, numOfRelevantLars, underCap, overCap)
3338
validLarSource.mustPass
3439
}
3540

36-
property(s"be invalid if under cap loans > $multiplier * over cap loans") {
41+
property(s"be invalid if under cap loans > $multiplier * total loans") {
3742
val numOfRelevantLars = sampleSizeTarget + 1
3843
val invalidLarSource = newLarSource(testLars, numOfRelevantLars, underCap, overCap)
3944
invalidLarSource.mustFail
4045
}
4146

47+
property(s"be valid if NA loans > $multiplier * total loans") {
48+
val numOfRelevantLars = sampleSizeTarget + 1
49+
val validLarSource = newLarSource(testLars, numOfRelevantLars, naIncome, overCap)
50+
validLarSource.mustPass
51+
}
52+
4253
override def check: AggregateEditCheck[LoanApplicationRegisterSource, LoanApplicationRegister] = Q016
4354
}

0 commit comments

Comments
 (0)