Skip to content

Commit b9c76ac

Browse files
committed
H2 specific unit testing to be used during the dev process
1 parent a104c22 commit b9c76ac

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/testthat/test-h2.R

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Probably temporary testing or may be moved to other unit tests.
2+
3+
4+
ini <- system.file("input/hector_ssp245.ini", package = "hector")
5+
dates <- 1750:2100
6+
7+
test_that("tau ", {
8+
9+
# Limited testing for now check to see tau oh can be read out...
10+
# in the future might want to test the actual values but for now
11+
# we are happy if the values range from 6.6 to 8
12+
hc <- newcore(ini)
13+
run(hc)
14+
out <- fetchvars(hc, dates = 1750:2100, vars = LIFETIME_OH())
15+
16+
expect_equal(LIFETIME_OH(), "TAU_OH")
17+
expect_lte(mean(out$value), 8)
18+
expect_gte(mean(out$value), 6.6)
19+
20+
})
21+
22+
23+
test_that("H2 emissions ", {
24+
25+
# Check to make sure that can fetch and set the H2 emissions although
26+
# at this point changing the emissions will have no impact on
27+
# [ch4] dynamics but in the future it should...
28+
29+
hc <- newcore(ini)
30+
run(hc)
31+
d <- 1750:2100
32+
out <- fetchvars(hc, dates = d,
33+
vars = c(EMISSIONS_H2(), CONCENTRATIONS_CH4(), LIFETIME_OH()))
34+
35+
new_val <- 10
36+
setvar(core = hc, dates = d, var = c(EMISSIONS_H2()), values = rep(new_val, length(d)),
37+
unit = getunits(EMISSIONS_H2()))
38+
reset(hc)
39+
run(hc)
40+
out2 <- fetchvars(hc, dates = d,
41+
vars = c(EMISSIONS_H2(), CONCENTRATIONS_CH4(), LIFETIME_OH()))
42+
43+
diff <- abs(out$value - out2$value)
44+
45+
# As of now the [CH4] and tau oh should not change
46+
expect_equal(unique(diff[out$variable == CONCENTRATIONS_CH4()]), 0)
47+
expect_equal(unique(diff[out$variable == LIFETIME_OH()]), 0)
48+
49+
# But if we can change the H2 emissions we should see a difference in
50+
# H2 emissions between the two new runs!
51+
expect_equal(unique(diff[out$variable == EMISSIONS_H2()]), new_val)
52+
53+
})
54+
55+

0 commit comments

Comments
 (0)