Skip to content

Commit

Permalink
Unit test for building a layer from a bank
Browse files Browse the repository at this point in the history
  • Loading branch information
smithkm committed Oct 28, 2024
1 parent 4ae7c0e commit 96eeb56
Showing 1 changed file with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,22 @@ void before() throws IOException, ResourceParseException {
lb.addSpecies(sb -> {
sb.genus("B", controlMap);
sb.baseArea(0.4f);
sb.percentGenus(10);
});
lb.addSpecies(sb -> {
sb.genus("C", controlMap);
sb.baseArea(0.6f);
sb.percentGenus(10);
});
lb.addSpecies(sb -> {
sb.genus("D", controlMap);
sb.baseArea(10f);
sb.percentGenus(10);
});
lb.addSpecies(sb -> {
sb.genus("H", controlMap);
sb.baseArea(50f);
sb.percentGenus(60);
sb.addSite(ib -> {
ib.ageTotal(100);
ib.yearsToBreastHeight(5);
Expand All @@ -77,6 +81,7 @@ void before() throws IOException, ResourceParseException {
lb.addSpecies(sb -> {
sb.genus("S", controlMap);
sb.baseArea(99.9f);
sb.percentGenus(10);
sb.addSite(ib -> {
ib.ageTotal(100);
ib.yearsToBreastHeight(5);
Expand Down Expand Up @@ -242,6 +247,46 @@ void testLayerUpdate() throws IOException, ResourceParseException, ProcessingExc
verifyBankMatchesLayer(bank, pLayer);
}

@Test
void testBuildLayerFromBank() throws IOException, ResourceParseException, ProcessingException {

VdypLayer pLayer = polygon.getLayers().get(LayerType.PRIMARY);
assertThat(pLayer, notNullValue());

Bank bank = new Bank(pLayer, polygon.getBiogeoclimaticZone(), s -> true);

pLayer = ProcessingTestUtils.normalizeLayer(pLayer);

verifyBankMatchesLayer(bank, pLayer);

var bankPart2 = new float[][][] { bank.loreyHeights, bank.basalAreas, bank.quadMeanDiameters,
bank.treesPerHectare, bank.wholeStemVolumes, bank.closeUtilizationVolumes, bank.cuVolumesMinusDecay,
bank.cuVolumesMinusDecayAndWastage };

var bankPart1 = new float[][] { bank.ageTotals, bank.dominantHeights,
// bank.percentagesOfForestedLand,
bank.siteIndices, bank.yearsAtBreastHeight
// bank.yearsToBreastHeight //
};

for (int i = 0; i < bankPart1.length; i++) {
for (int j = 0; j < bankPart1[i].length; j++) {
bankPart1[i][j] += 1;
}
}
for (int i = 0; i < bankPart2.length; i++) {
for (int j = 0; j < bankPart2[i].length; j++) {
for (int k = 0; k < bankPart2[i][j].length; k++) {
bankPart2[i][j][k] += 1;
}
}
}

var result = bank.buildLayerFromBank();

verifyBankMatchesLayer(bank, result);
}

private void verifyBankMatchesLayer(Bank lps, VdypLayer layer) {

List<Integer> sortedSpIndices = layer.getSpecies().values().stream().map(s -> s.getGenusIndex()).sorted()
Expand Down Expand Up @@ -293,11 +338,17 @@ private void verifyBankSpeciesMatchesSpecies(Bank bank, int index, VdypSpecies s
assertThat(bank.speciesNames[index], is(species.getGenus()));

species.getSite().ifPresentOrElse(site -> {
assertThat(bank.yearsAtBreastHeight[index], is(site.getYearsAtBreastHeight().get()));
assertThat(bank.ageTotals[index], is(site.getAgeTotal().get()));
assertThat(bank.dominantHeights[index], is(site.getHeight().get()));
assertThat(bank.siteIndices[index], is(site.getSiteIndex().get()));
assertThat(bank.yearsToBreastHeight[index], is(site.getYearsToBreastHeight().get()));
assertThat(
bank.yearsAtBreastHeight[index],
is(site.getYearsAtBreastHeight().orElse(VdypEntity.MISSING_FLOAT_VALUE))
);
assertThat(bank.ageTotals[index], is(site.getAgeTotal().orElse(VdypEntity.MISSING_FLOAT_VALUE)));
assertThat(bank.dominantHeights[index], is(site.getHeight().orElse(VdypEntity.MISSING_FLOAT_VALUE)));
assertThat(bank.siteIndices[index], is(site.getSiteIndex().orElse(VdypEntity.MISSING_FLOAT_VALUE)));
assertThat(
bank.yearsToBreastHeight[index],
is(site.getYearsToBreastHeight().orElse(VdypEntity.MISSING_FLOAT_VALUE))
);
site.getSiteCurveNumber().ifPresentOrElse(scn -> {
assertThat(bank.siteCurveNumbers[index], is(scn));
}, () -> {
Expand Down

0 comments on commit 96eeb56

Please sign in to comment.