|
| 1 | +package hmda.publication.reports.util |
| 2 | + |
| 3 | +import akka.actor.ActorSystem |
| 4 | +import akka.stream.ActorMaterializer |
| 5 | +import akka.stream.scaladsl.Source |
| 6 | +import hmda.model.fi.lar.LarGenerators |
| 7 | +import hmda.model.publication.reports.MSAReport |
| 8 | +import hmda.publication.reports.util.ReportUtil._ |
| 9 | +import hmda.query.repository.filing.LarConverter._ |
| 10 | +import org.scalatest.{ AsyncWordSpec, MustMatchers } |
| 11 | + |
| 12 | +class ReportUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerators { |
| 13 | + |
| 14 | + implicit val system = ActorSystem() |
| 15 | + implicit val ec = system.dispatcher |
| 16 | + implicit val materializer = ActorMaterializer() |
| 17 | + |
| 18 | + "msaReport" must { |
| 19 | + "get MSA info for given fips code and return MSAReport object" in { |
| 20 | + msaReport("10380") mustBe MSAReport("10380", "Aguadilla-Isabela, PR", "PR", "Puerto Rico") |
| 21 | + msaReport("26980") mustBe MSAReport("26980", "Iowa City, IA", "IA", "Iowa") |
| 22 | + msaReport("41100") mustBe MSAReport("41100", "St. George, UT", "UT", "Utah") |
| 23 | + } |
| 24 | + |
| 25 | + "Return empty MSAReport if fips code is invalid" in { |
| 26 | + msaReport("bogus") mustBe MSAReport("", "", "", "") |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + "calculateMedianIncomeIntervals" must { |
| 31 | + "get median income info for given fips, convert to thousands" in { |
| 32 | + calculateMedianIncomeIntervals(10380)(2) mustBe 18.267 |
| 33 | + calculateMedianIncomeIntervals(26980)(2) mustBe 81.027 |
| 34 | + calculateMedianIncomeIntervals(41100)(2) mustBe 58.145 |
| 35 | + } |
| 36 | + "return array of 50%, 80%, 100%, and 120% levels of median income (in thousands)" in { |
| 37 | + def roundTo3(v: Double) = BigDecimal(v).setScale(3, BigDecimal.RoundingMode.HALF_UP).toDouble |
| 38 | + calculateMedianIncomeIntervals(26980) mustBe Array(40.5135, 64.8216, 81.027, 97.2324) |
| 39 | + calculateMedianIncomeIntervals(41100).map(roundTo3) mustBe Array(29.073, 46.516, 58.145, 69.774) |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + "calculateYear" must { |
| 44 | + "given a larSource, return the Activity Year for the LARs in it" in { |
| 45 | + // Activity Year is the same year as Action Taken Date. This is enforced by edit S270 |
| 46 | + val lars = larListGen.sample.get.map(_.copy(actionTakenDate = 20090822)) |
| 47 | + val src = Source.fromIterator(() => lars.toIterator) |
| 48 | + .map(lar => toLoanApplicationRegisterQuery(lar)) |
| 49 | + |
| 50 | + calculateYear(src).map(_ mustBe 2009) |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments