Skip to content

Commit ef3cfdb

Browse files
committed
Further corrections to logic
Also, comment out specs for categorizations that require clarification
1 parent a968c1f commit ef3cfdb

File tree

2 files changed

+47
-20
lines changed

2 files changed

+47
-20
lines changed

publication/src/main/scala/hmda/publication/reports/util/RaceUtil.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object RaceUtil {
4949

5050
case Joint =>
5151
larSource.filter { lar =>
52-
(applicantTwoOrMoreMinorities(lar) || coApplicantTwoOrMoreMinorities(lar)) &&
52+
(applicantOneOrMoreMinorities(lar) || coApplicantOneOrMoreMinorities(lar)) &&
5353
(lar.race1 == 5 || coApplicantWhite(lar))
5454
}
5555

@@ -99,12 +99,19 @@ object RaceUtil {
9999
(lar.race5 != "" && lar.race5 != "5"))
100100
}
101101

102-
private def coApplicantTwoOrMoreMinorities(lar: LoanApplicationRegisterQuery): Boolean = {
103-
lar.coRace1 != 5 &&
104-
((lar.coRace2 != "" && lar.coRace2 != "5") ||
105-
(lar.coRace3 != "" && lar.coRace3 != "5") ||
106-
(lar.coRace4 != "" && lar.coRace4 != "5") ||
107-
(lar.coRace5 != "" && lar.coRace5 != "5"))
102+
private def applicantOneOrMoreMinorities(lar: LoanApplicationRegisterQuery): Boolean = {
103+
(lar.race1 == 1 || lar.race1 == 2 || lar.race1 == 3 || lar.race1 == 4) ||
104+
(lar.race2 != "" && lar.race2 != "5") ||
105+
(lar.race3 != "" && lar.race3 != "5") ||
106+
(lar.race4 != "" && lar.race4 != "5") ||
107+
(lar.race5 != "" && lar.race5 != "5")
108+
}
109+
private def coApplicantOneOrMoreMinorities(lar: LoanApplicationRegisterQuery): Boolean = {
110+
(lar.coRace1 == 1 || lar.coRace1 == 2 || lar.coRace1 == 3 || lar.coRace1 == 4) ||
111+
(lar.coRace2 != "" && lar.coRace2 != "5") ||
112+
(lar.coRace3 != "" && lar.coRace3 != "5") ||
113+
(lar.coRace4 != "" && lar.coRace4 != "5") ||
114+
(lar.coRace5 != "" && lar.coRace5 != "5")
108115
}
109116

110117
def raceBorrowerCharacteristic[as: AS, mat: MAT, ec: EC](larSource: Source[LoanApplicationRegisterQuery, NotUsed], dispositions: List[DispositionType]): Future[RaceBorrowerCharacteristic] = {

publication/src/test/scala/hmda/publication/reports/RaceUtilSpec.scala

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ class RaceUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerators wi
127127

128128
"'White' race filter" must {
129129
"include applications that meet 'White' criteria" in {
130-
def nonWhiteCoApp = Gen.oneOf(5, 6, 7, 8).sample.get
130+
def nonMinorityCoApp = Gen.oneOf(5, 6, 7, 8).sample.get
131131
val lars = larCollectionWithApplicant { app =>
132132
val whiteApp = app.copy(race1 = 5, race2 = "", race3 = "", race4 = "", race5 = "")
133-
whiteApp.copy(coRace1 = nonWhiteCoApp, coRace2 = "", coRace3 = "", coRace4 = "", coRace5 = "")
133+
whiteApp.copy(coRace1 = nonMinorityCoApp, coRace2 = "", coRace3 = "", coRace4 = "", coRace5 = "")
134134
}
135135
val whiteLars = filterRace(source(lars), White)
136136
count(whiteLars).map(_ mustBe 100)
@@ -173,7 +173,7 @@ class RaceUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerators wi
173173
count(multiMinorityLars).map(_ mustBe 100)
174174
}
175175
/*"exclude lars where applicant does not meet criteria" in {
176-
// Ask about this --- can any of the races be 5?
176+
// TODO: Confirm with BAs--can any of the races be 5?
177177
val excludedLars = larCollectionWithApplicant(_.copy(race1 = 2, race2 = "5"))
178178
val otherLars = filterRace(source(excludedLars), TwoOrMoreMinority)
179179
count(otherLars).map(_ mustBe 0)
@@ -187,23 +187,43 @@ class RaceUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerators wi
187187

188188
/*
189189
"'Joint' race filter" must {
190-
"include applications that meet 'Joint' criteria" in {
191-
val lars = larCollection { lar =>
190+
// TODO: Confirm with BAs--how to define "minority" here?
191+
def minority = Gen.oneOf(1, 2, 3, 4).sample.get
192+
193+
"include applications with white applicant and minority coApplicant" in {
194+
val lars = larCollectionWithApplicant { app =>
195+
app.copy(race1 = 5, race2 = "", race3 = "", race4 = "", race5 = "", coRace1 = minority)
196+
}
197+
val jointLars = filterRace(source(lars), Joint)
198+
count(jointLars).map(_ mustBe 100)
199+
}
200+
"include applications with minority applicant and white coApplicant" in {
201+
val lars = larCollectionWithApplicant { app =>
202+
app.copy(race1 = minority, coRace1 = 5, coRace2 = "", coRace3 = "", coRace4 = "", coRace5 = "")
192203
}
193204
val jointLars = filterRace(source(lars), Joint)
194205
count(jointLars).map(_ mustBe 100)
195206
}
196-
"exclude applications that do not meet 'Joint' criteria" in {
197-
val larsExcludedByApplicant = larCollection { lar =>
198-
val applicant = lar.applicant.copy(ethnicity = 2, coEthnicity = 3)
199-
lar.copy(applicant = applicant)
207+
"exclude lars with two white applicants" in {
208+
val excludedLars = larCollectionWithApplicant(_.copy(race1 = 5, coRace1 = 5))
209+
val nonJointLars = filterRace(source(excludedLars), Joint)
210+
count(nonJointLars).map(_ mustBe 0)
211+
}
212+
"exclude lars with two minority applicants" in {
213+
val excludedLars = larCollectionWithApplicant { app =>
214+
app.copy(race1 = minority, coRace1 = minority)
200215
}
201-
val larsExcludedByCoApplicant = larCollection { lar =>
202-
val applicant = lar.applicant.copy(ethnicity = 1, coEthnicity = 2)
203-
lar.copy(applicant = applicant)
216+
val nonJointLars = filterRace(source(excludedLars), Joint)
217+
count(nonJointLars).map(_ mustBe 0)
218+
219+
}
220+
"exclude lars with only one applicant" in {
221+
val excludedLars = larCollectionWithApplicant { app =>
222+
app.copy(race1 = minority, coRace1 = 8)
204223
}
205-
val nonJointLars = filterRace(source(lars), Joint)
224+
val nonJointLars = filterRace(source(excludedLars), Joint)
206225
count(nonJointLars).map(_ mustBe 0)
226+
207227
}
208228
}
209229
*/

0 commit comments

Comments
 (0)