[CHNOSZ-commits] r959 - in pkg/CHNOSZ: . inst/tinytest

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jan 9 04:34:46 CET 2026


Author: jedick
Date: 2026-01-09 04:34:44 +0100 (Fri, 09 Jan 2026)
New Revision: 959

Added:
   pkg/CHNOSZ/inst/tinytest/test-util.formula.R
   pkg/CHNOSZ/inst/tinytest/test-util.misc.R
   pkg/CHNOSZ/inst/tinytest/test-util.units.R
Removed:
   pkg/CHNOSZ/inst/tinytest/test-util.R
Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/inst/tinytest/test-util.expression.R
Log:
Add tests for util.expression.R and util.misc.R


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2026-01-08 05:07:55 UTC (rev 958)
+++ pkg/CHNOSZ/DESCRIPTION	2026-01-09 03:34:44 UTC (rev 959)
@@ -1,6 +1,6 @@
-Date: 2026-01-08
+Date: 2026-01-09
 Package: CHNOSZ
-Version: 2.2.0-25
+Version: 2.2.0-26
 Title: Thermodynamic Calculations and Diagrams for Geochemistry
 Authors at R: c(
     person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),

Deleted: pkg/CHNOSZ/inst/tinytest/test-util.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-util.R	2026-01-08 05:07:55 UTC (rev 958)
+++ pkg/CHNOSZ/inst/tinytest/test-util.R	2026-01-09 03:34:44 UTC (rev 959)
@@ -1,52 +0,0 @@
-# Load default settings for CHNOSZ
-reset()
-
-info <- "Unavailable elements cause errors in mass() and entropy()"
-# The suppressWarnings here refer to the warnings generated by makeup() about the missing elements
-expect_error(suppressWarnings(mass("Xxx")), "element\\(s\\) Xxx not available in thermo\\(\\)\\$element", info = info)
-# 20130101: The error below was changed to a warning to restore functionality of check.OBIGT()
-#   (species in the database include those with Am Cm Np Pu, not listed in thermo()$element)
-expect_warning(entropy("Xxx"), "element\\(s\\) Xxx not available in thermo\\(\\)\\$element", info = info)
-
-info <- "GHS() and ZC() give warnings and errors in some situation"
-expect_error(GHS(c("CO2","H2O"), G = 0, H = 0), "formula, G, H and S arguments are not same length", info = info)
-expect_error(ZC("H2O"), "carbon not found in the stoichiometric matrix", info = info)
-iATP <- info("ATP-4")
-expect_warning(ZC(iATP), "element\\(s\\) P .* not included in this calculation", info = info)
-
-info <- "GHS() and OBIGT2eos() produce expected values"
-## A species with missing entropy value
-ic <- info("cystine")
-icdata <- info(ic)
-GHS <- GHS(icdata$formula, G = icdata$G, H = icdata$H, S = icdata$S)
-expect_equal(GHS[[3]], 61.8102928143, info = info)
-# Done through OBIGT2eos
-coe <- CHNOSZ:::OBIGT2eos(thermo()$OBIGT[ic,], "aq", fixGHS = TRUE)
-expect_equal(coe$S, GHS[[3]], info = info)
-## Mass and entropy of elements in chemical formulas
-# The "-1" is a single negative charge, the electron
-formula <- c("CH4", "H2O", "-1")
-calcmass <- mass(formula)
-calcS <- convert(entropy(formula), "cal")
-expect_equal(calcmass, c(16.04276, 18.01528, 0), info = info)
-expect_equal(calcS, c(63.83843212237, 55.74952198853, 15.61663479924), info = info)
-# Another way to calculate the entropy of the elements in H2O
-calcGHS <- GHS("H2O", G = 0, H = 0, E_units = "cal")
-expect_equal(as.numeric(calcGHS[1, 3]), calcS[2], info = info)
-  
-info <- "[P|T|E].units() do not accept invalid units"
-expect_error(P.units("X"), "units of pressure must be either bar or MPa", info = info)
-expect_error(T.units("X"), "units of temperature must be either C or K", info = info)
-expect_error(E.units("X"), "units of energy must be either cal or J", info = info)
-
-info <- "describe.property() does not accept NULL values"
-expect_error(describe.property(), "property or value is NULL", info = info)
-
-# Test added on 20240211
-# Incorrect result was causing quartz tests in test-subcrt.R to fail
-info <- "dPdTtr gives expected result"
-add.OBIGT("SUPCRT92")
-dPdTtr.calc <- round(dPdTtr(info("quartz", "cr"), info("quartz", "cr2")), 5)
-# The reference value was calculated with CHNOSZ_1.4.3
-# (prior to bug in dPdTtr introduced by switch to Joules)
-expect_equal(dPdTtr.calc, 38.45834, info = info)

Modified: pkg/CHNOSZ/inst/tinytest/test-util.expression.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-util.expression.R	2026-01-08 05:07:55 UTC (rev 958)
+++ pkg/CHNOSZ/inst/tinytest/test-util.expression.R	2026-01-09 03:34:44 UTC (rev 959)
@@ -12,3 +12,33 @@
 info <- "expr.species() handles non-integer charge"
 es <- expr.species("FeS+1.33")
 expect_equal(es[[length(es)]], "+1.33", info = info)
+
+info <- "describe.property() does not accept NULL values"
+expect_error(describe.property(), "property or value is NULL", info = info)
+
+# Tests added on 20260109
+
+info <- "describe.basis() runs without error"
+basis("CHNOS+")
+basis("FeCHNOS+")
+basis("O2", "HM")
+expect_silent(describe.basis(), info = info)
+expect_silent(describe.basis(oneline = TRUE), info = info)
+
+info <- "describe.property() runs without error"
+property <- c("P", "T", "Eh", "pH", "IS")
+value <- c(1, 42.42, -1, 7, 0.1)
+expect_silent(describe.property(property, value), info = info)
+expect_silent(describe.property(property, value, oneline = TRUE), info = info)
+
+info <- "ratlab() and syslab() run without error"
+expect_silent(ratlab(), info = info)
+expect_silent(syslab(), info = info)
+
+info <- "split.formula() works with H-citrate-2"
+expect_silent(result <- CHNOSZ:::split.formula("H-citrate-2"), info = info)
+expect_equivalent(result["H-citrate"], 1, info = info)
+expect_equivalent(result["Z"], -2, info = info)
+
+info <- "split.formula() works with 2-octanone"
+expect_equal(CHNOSZ:::split.formula("2-octanone"), "2-octanone")

Copied: pkg/CHNOSZ/inst/tinytest/test-util.formula.R (from rev 958, pkg/CHNOSZ/inst/tinytest/test-util.R)
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-util.formula.R	                        (rev 0)
+++ pkg/CHNOSZ/inst/tinytest/test-util.formula.R	2026-01-09 03:34:44 UTC (rev 959)
@@ -0,0 +1,36 @@
+# Load default settings for CHNOSZ
+reset()
+
+info <- "Unavailable elements cause errors in mass() and entropy()"
+# The suppressWarnings here refer to the warnings generated by makeup() about the missing elements
+expect_error(suppressWarnings(mass("Xxx")), "element\\(s\\) Xxx not available in thermo\\(\\)\\$element", info = info)
+# 20130101: The error below was changed to a warning to restore functionality of check.OBIGT()
+#   (species in the database include those with Am Cm Np Pu, not listed in thermo()$element)
+expect_warning(entropy("Xxx"), "element\\(s\\) Xxx not available in thermo\\(\\)\\$element", info = info)
+
+info <- "GHS() and ZC() give warnings and errors in some situation"
+expect_error(GHS(c("CO2","H2O"), G = 0, H = 0), "formula, G, H and S arguments are not same length", info = info)
+expect_error(ZC("H2O"), "carbon not found in the stoichiometric matrix", info = info)
+iATP <- info("ATP-4")
+expect_warning(ZC(iATP), "element\\(s\\) P .* not included in this calculation", info = info)
+
+info <- "GHS() and OBIGT2eos() produce expected values"
+## A species with missing entropy value
+ic <- info("cystine")
+icdata <- info(ic)
+GHS <- GHS(icdata$formula, G = icdata$G, H = icdata$H, S = icdata$S)
+expect_equal(GHS[[3]], 61.8102928143, info = info)
+# Done through OBIGT2eos
+coe <- CHNOSZ:::OBIGT2eos(thermo()$OBIGT[ic,], "aq", fixGHS = TRUE)
+expect_equal(coe$S, GHS[[3]], info = info)
+## Mass and entropy of elements in chemical formulas
+# The "-1" is a single negative charge, the electron
+formula <- c("CH4", "H2O", "-1")
+calcmass <- mass(formula)
+calcS <- convert(entropy(formula), "cal")
+expect_equal(calcmass, c(16.04276, 18.01528, 0), info = info)
+expect_equal(calcS, c(63.83843212237, 55.74952198853, 15.61663479924), info = info)
+# Another way to calculate the entropy of the elements in H2O
+calcGHS <- GHS("H2O", G = 0, H = 0, E_units = "cal")
+expect_equal(as.numeric(calcGHS[1, 3]), calcS[2], info = info)
+  

Added: pkg/CHNOSZ/inst/tinytest/test-util.misc.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-util.misc.R	                        (rev 0)
+++ pkg/CHNOSZ/inst/tinytest/test-util.misc.R	2026-01-09 03:34:44 UTC (rev 959)
@@ -0,0 +1,31 @@
+# Load default settings for CHNOSZ
+reset()
+
+# Test added on 20240211
+# Incorrect result was causing quartz tests in test-subcrt.R to fail
+info <- "dPdTtr gives expected result"
+add.OBIGT("SUPCRT92")
+dPdTtr.calc <- round(dPdTtr(info("quartz", "cr"), info("quartz", "cr2")), 5)
+# The reference value was calculated with CHNOSZ_1.4.3
+# (prior to bug in dPdTtr introduced by switch to Joules)
+expect_equal(dPdTtr.calc, 38.45834, info = info)
+
+# Tests added on 20260109
+
+info <- "GHS_Tr() runs without error"
+Htr <- c(326.0, 215.0, 165.0)
+iiron <- info("iron")
+expect_silent(result <- GHS_Tr(iiron, Htr), info = info)
+info <- "GHS_Tr() gives expected output"
+expect_equal(round(result$Gf_Tr, 2), c(-618.24, 1293.53, 979.29), info = info)
+expect_equal(round(result$Hf_Tr, 2), c(-1768.42, 1865.34, 1252.89), info = info)
+expect_equal(round(result$S_Tr, 2), c(2.66, 8.44, 7.44), info = info)
+
+info <- "unitize() gives expected output"
+# The proteins have unequal activity, but the activities of residues still add up to one
+logact.tot <- 0
+logact <- c(-3, -2)
+length <- c(100, 200)
+loga <- unitize(logact, length, logact.tot)
+expect_equal(loga[2] - loga[1], 1)
+expect_equal(sum(10^loga * length), 1)

Added: pkg/CHNOSZ/inst/tinytest/test-util.units.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-util.units.R	                        (rev 0)
+++ pkg/CHNOSZ/inst/tinytest/test-util.units.R	2026-01-09 03:34:44 UTC (rev 959)
@@ -0,0 +1,7 @@
+# Load default settings for CHNOSZ
+reset()
+
+info <- "[P|T|E].units() do not accept invalid units"
+expect_error(P.units("X"), "units of pressure must be either bar or MPa", info = info)
+expect_error(T.units("X"), "units of temperature must be either C or K", info = info)
+expect_error(E.units("X"), "units of energy must be either cal or J", info = info)



More information about the CHNOSZ-commits mailing list