Critical findings: unit tests against authoritative methods

This file is kept locally and has not been pushed.

How the tests are built

Results

# Finding (review ids) Control Finding test Package vs reference
01 NE requirements met with ME, no REM/REG (F02, C-01) PASS: NEm = 0.386·BW^0.75 (Eq. 10.3, Table 10.4) FAIL Energy DMI is 0.55–0.63× IPCC Eq. 10.16 on a controlled diet at 64% DE (cows 0.63, steers 0.57, calves 0.55)
02a N retention units (C-02, H-04, F04, F07) PASS: N intake = Eq. 10.32 FAIL Cow N retention 0.00016 vs 0.058 kg N/day (365× too small)
02b N excretion formula (same ids) (as 02a) FAIL Cow 89.4 vs 68.2 kg N/yr (+31%). Steers 49.7 vs 43.3. Calves 12.8 vs 8.8
03 SOC factors applied every year to the measured stock (F01, S-02) PASS: Eq. 2.25 reference gives 0 when nothing changes FAIL 1 ha of unchanged cropland shows −7.02 t C/yr (Eq. 2.25 gives 0)
04 Burning counts CO2 and uses the N2O GWP for NOx (F03, F06) PASS: EFs = Table 2.5 FAIL 1 t DM burnt: 1,802 vs 75 kg CO2e (24×)
05 Tree SOC never added (F02 code, S-01) PASS: biomass_calculation() returns a data frame with no trees_non_feed_biomass element FAIL +2.5 tree c_increase_soc changes the SOC total by 0
06 Zero yield silently becomes 0 ha (LU-01, F04) PASS: a normal pasture gets area > 0 FAIL 9 season rows, 14,231 kg DM of demand reported as 0 ha, with no warning
07a Leaching not multiplied by area (N-01) PASS: out4 = per-ha rate × area FAIL Pasture on 109 ha: 2.6 vs 278 kg N
07b Leaching coefficient 0.021*(P-3.9) (N-02) none SKIP Primary source not verified (see below)
08 Hidden lookup of inputs in the caller (F03 code) PASS: explicit argument gives the same result FAIL ×2 n_balance() and ghg_emission() silently use another scenario's object from the caller
09 Shipped example does not run (F01, D-01, H-03, M-01) none FAIL ×3 Column `crop_name` doesn't exist; object 'fat_milkcontent' not found; dm_content given as fractions (0.3) where the code expects %, with 0 for the concentrate

Totals on v0.7.0 across 22 tests: 8 control PASS, 13 finding FAIL, 1 SKIP. No test errored for harness reasons. (An earlier version of this file said 9 and 12, which was a miscount.) Two guard tests for the proposed fixes were added later; see 07_fix_log.md.

Source excerpts used (verbatim equations, with printed page)

IPCC 2019 Refinement, Vol. 4, Ch. 10 (PDF)

IPCC 2006, Vol. 4, Ch. 2 (PDF)

Code-contract standards (tests 06 and 08)

These aren't IPCC tests. They check against standard R package practice: signal a condition when a result is impossible (R Packages 2e), and don't make a result depend on objects in the caller's environment (Advanced R 2e §6.4).

Where the tests disagree with the reviews

To reproduce

cd fixes
./run_all.sh

openxlsx must be installed; this run used a scratch library. The tests are written against the correct behaviour. When a finding is fixed, its test turns green and stays in the suite as a regression test.

Comments

Comments are GitHub Discussions on peetmate/cleaned-review; sign in with GitHub to post.