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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 7 10:21:10 CET 2026


Author: jedick
Date: 2026-01-07 10:21:10 +0100 (Wed, 07 Jan 2026)
New Revision: 954

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/inst/tinytest/test-EOSregress.R
   pkg/CHNOSZ/inst/tinytest/test-nonideal.R
   pkg/CHNOSZ/inst/tinytest/test-phosphorylate.R
Log:
Add tests for EOSregress.R and nonideal.R


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2026-01-07 08:12:08 UTC (rev 953)
+++ pkg/CHNOSZ/DESCRIPTION	2026-01-07 09:21:10 UTC (rev 954)
@@ -1,6 +1,6 @@
 Date: 2026-01-07
 Package: CHNOSZ
-Version: 2.2.0-20
+Version: 2.2.0-21
 Title: Thermodynamic Calculations and Diagrams for Geochemistry
 Authors at R: c(
     person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),

Modified: pkg/CHNOSZ/inst/tinytest/test-EOSregress.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-EOSregress.R	2026-01-07 08:12:08 UTC (rev 953)
+++ pkg/CHNOSZ/inst/tinytest/test-EOSregress.R	2026-01-07 09:21:10 UTC (rev 954)
@@ -2,12 +2,13 @@
 reset()
 
 info <- "EOSvar stops with unknown variables"
+if(exists("TX")) rm("TX")
 expect_error(EOSvar("TX", T = 25, P = 1), "can't find a variable named TX", info = info)
-# Why can't the test find these?
+# TOOD: Why aren't these variables visible to the test runner?
 #TX <- 2
 #expect_error(EOSvar("TX", T = 25, P = 1), "an object named TX is not a function", info = info)
 #TX <- function(T) 2
-#expect_error(EOSvar("TX", T = 25, P = 1), "the arguments of TX\\(\\) are not T, P", info = info)
+#expect_error(EOSvar("TX", T = 25, P = 1), "the arguments of TX\\(\\) do not contain T and P", info = info)
 
 info <- "Regressions return known HKF parameters (neutral species)"
 # Regress computed values of heat capacity and volume of CH4(aq)
@@ -43,3 +44,41 @@
 expect_equivalent(V.coeff[4], CH4.par$a4, info = info)
 # omega (from V)
 expect_equivalent(V.coeff[5], CH4.par$omega, info = info)
+
+# Tests added on 20260107
+
+info <- "Cp_s_var and V_s_var give expected values"
+# This should work for any omega.PrTr != 0
+expect_equal(Cp_s_var(omega.PrTr = 1), water("XBorn")[[1]] * 298.15, tolerance = 1e-7, scale = 1)
+expect_equal(V_s_var(omega.PrTr = 1), -water("QBorn")[[1]], tolerance = 1e-9, scale = 1)
+
+info <- "EOScalc() and EOScoeffs() run without error"
+
+# Calculate the Cp at some temperature and pressure
+expect_silent(EOScalc(Cp.lm$coefficients, 298.15, 1), info = info)
+# Get the database values of c1, c2 and omega for CH4(aq)
+expect_silent(Cp_coeffs <- EOScoeffs("CH4", "Cp"), info = info)
+# Volume parameters
+expect_silent(V_coeffs <- EOScoeffs("CH4", "V"), info = info)
+
+info <- "EOSplot() runs without error"
+
+## Make plots comparing the regressions
+## with the accepted EOS parameters of CH4
+# Read the data from Hnedkovsky and Wood, 1997
+f <- system.file("extdata/misc/HW97_Cp.csv", package = "CHNOSZ")
+d <- read.csv(f)
+# Use data for CH4
+d <- d[d$species == "CH4", ]
+d <- d[, -1]
+# Convert J to cal and MPa to bar
+d$Cp <- convert(d$Cp, "cal")
+d$P <- convert(d$P, "bar")
+
+# Save plot to a temporary PNG file
+pngfile <- tempfile(fileext = ".png")
+png(pngfile)
+expect_silent(EOSplot(d, T.max = 600), info = info)
+# Close the graphics device and remove the temporary PNG file
+dev.off()
+file.remove(pngfile)

Modified: pkg/CHNOSZ/inst/tinytest/test-nonideal.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-nonideal.R	2026-01-07 08:12:08 UTC (rev 953)
+++ pkg/CHNOSZ/inst/tinytest/test-nonideal.R	2026-01-07 09:21:10 UTC (rev 954)
@@ -169,3 +169,14 @@
 # IS-T grid
 a_IS.T <- affinity(T = c(190, 310, 5), IS = c(0, 1, 6))
 expect_equivalent(a_IS.T$values[[2]][3, ], as.numeric(a250$values[[2]]), info = info)
+
+# Tests added on 20260107
+info <- "bgamma() runs without error"
+# Save plot to a temporary PNG file
+pngfile <- tempfile(fileext = ".png")
+png(pngfile)
+expect_silent(bgamma(showsplines = "T"), info = info)
+expect_silent(bgamma(showsplines = "P"), info = info)
+# Close the graphics device and remove the temporary PNG file
+dev.off()
+file.remove(pngfile)

Modified: pkg/CHNOSZ/inst/tinytest/test-phosphorylate.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-phosphorylate.R	2026-01-07 08:12:08 UTC (rev 953)
+++ pkg/CHNOSZ/inst/tinytest/test-phosphorylate.R	2026-01-07 09:21:10 UTC (rev 954)
@@ -46,9 +46,9 @@
 dev.off()
 file.remove(pngfile)
 
-info <- "Tests for more species"
+## Tests for more species
 
-# Acetate phosphorylation: circular reference
+info <- "Acetate phosphorylation"
 # Delta G0 from Table 3.2 of Alberty (2003)
 mod.OBIGT("acetylphosphate0", formula = "C2H5O5P", G = -1298260)
 mod.OBIGT("acetylphosphate-1", formula = "C2H4O5P-", G = -1268080)
@@ -57,62 +57,72 @@
 mod.OBIGT("acetylphosphate-3", formula = "C2H2O5P-3", G = 0)
 # This is the dimensionless affinity (A/2.303RT) of the reaction
 affinity_nodim <- as.numeric(phosphorylate("acetic acid", "P")$a12)
-expect_equal(affinity_nodim, -6.20, tolerance = 0.01, scale = 1)
+# This is a circular reference value (calculated with CHNOSZ, not from an outside source)
+expect_equal(affinity_nodim, -6.20, tolerance = 0.01, scale = 1, info = info)
 
-# Glycerol phosphorylation: reference value from p. 295 of Alberty (2003)
+info <- "Glycerol phosphorylation"
 mod.OBIGT("3-phosphoglycerol", formula = "C3H9O6P", G = 0)
 mod.OBIGT("3-phosphoglycerol-1", formula = "C3H8O6P-", G = -1397040)
 mod.OBIGT("3-phosphoglycerol-2", formula = "C3H7O6P-2", G = -1358960)
 affinity_nodim <- as.numeric(phosphorylate("glycerol", "P")$a12)
-expect_equal(convert(affinity_nodim, "G"), -1780.75, tolerance = 1200, scale = 1)
+# Reference value from p. 295 of Alberty (2003)
+expect_equal(convert(affinity_nodim, "G"), -1780.75, tolerance = 1200, scale = 1, info = info)
 
-# Adenosine phosphorylation (to AMP): reference value from p. 295 of Alberty (2003)
+info <- "Adenosine phosphorylation (to AMP)"
 affinity_nodim <- as.numeric(phosphorylate("adenosine_to_AMP", "P")$a12)
-expect_equal(convert(affinity_nodim, "G"), 12969.6, tolerance = 500, scale = 1)
+# Reference value from p. 295 of Alberty (2003)
+expect_equal(convert(affinity_nodim, "G"), 12969.6, tolerance = 500, scale = 1, info = info)
 
-# Adenosine phosphorylation (model 2)
+info <- "Adenosine phosphorylation (model 2)"
 # adenosine_for_RNA excludes PO4-3 and AMP-2 (polymerization model from LaRowe and Dick, 2025)
 affinity_nodim <- as.numeric(phosphorylate("adenosine_for_RNA", "P")$a12)
 # For this let's use the same reference value as above, but with a greater expected difference
-expect_equal(convert(affinity_nodim, "G"), 12969.6, tolerance = 7000, scale = 1)
+expect_equal(convert(affinity_nodim, "G"), 12969.6, tolerance = 7000, scale = 1, info = info)
 
-# Adenosine phosphorylation (to cAMP): circular reference
+info <- "Adenosine phosphorylation (to cAMP)"
 # Delta G0 are placeholder values
 mod.OBIGT("cyclic-HAMP", formula = "C10H12N5O6P", G = 0)
 mod.OBIGT("cyclic-AMP-1", formula = "C10H11N5O6P-", G = 0)
 affinity_nodim <- as.numeric(phosphorylate("adenosine_to_cAMP", "P")$a12)
-expect_equal(affinity_nodim, -149.20, tolerance = 0.01, scale = 1)
+# Circular reference
+expect_equal(affinity_nodim, -149.20, tolerance = 0.01, scale = 1, info = info)
 
-# Ribose phosphorylation: circular reference
+info <- "Ribose phosphorylation"
 affinity_nodim <- as.numeric(phosphorylate("ribose", "P")$a12)
-expect_equal(affinity_nodim, -3.75, tolerance = 0.01, scale = 1)
+# Circular reference
+expect_equal(affinity_nodim, -3.75, tolerance = 0.01, scale = 1, info = info)
 
-# Uridine phosphorylation: circular reference
+info <- "Uridine phosphorylation"
 affinity_nodim <- as.numeric(phosphorylate("uridine", "P")$a12)
-expect_equal(affinity_nodim, -2.24, tolerance = 0.01, scale = 1)
+# Circular reference
+expect_equal(affinity_nodim, -2.24, tolerance = 0.01, scale = 1, info = info)
 
-# AMP phosphorylation: circular reference
+info <- "AMP phosphorylation"
 affinity_nodim <- as.numeric(phosphorylate("AMP", "P")$a12)
-expect_equal(affinity_nodim, -5.83, tolerance = 0.01, scale = 1)
+# Circular reference
+expect_equal(affinity_nodim, -5.83, tolerance = 0.01, scale = 1, info = info)
 
-# ADP phosphorylation: circular reference
+info <- "ADP phosphorylation"
 affinity_nodim <- as.numeric(phosphorylate("ADP", "P")$a12)
-expect_equal(affinity_nodim, -6.52, tolerance = 0.01, scale = 1)
+# Circular reference
+expect_equal(affinity_nodim, -6.52, tolerance = 0.01, scale = 1, info = info)
 
-# Pyruvate phosphorylation with ATP: reference value from p. 224 of Alberty (2003)
+info <- "Pyruvate phosphorylation with ATP"
 mod.OBIGT("phosphoenolpyruvate", formula = "C3H5O6P", G = 0)
 mod.OBIGT("phosphoenolpyruvate-1", formula = "C3H4O6P-", G = 0)
 mod.OBIGT("phosphoenolpyruvate-2", formula = "C3H3O6P-2", G = -1303610)
 mod.OBIGT("phosphoenolpyruvate-3", formula = "C3H2O6P-3", G = -1263650)
 affinity_nodim <- as.numeric(phosphorylate("pyruvic acid", "ATP")$a12)
-expect_equal(convert(affinity_nodim, "G"), 30622.4, tolerance = 4000, scale = 1)
+# Reference value from p. 224 of Alberty (2003)
+expect_equal(convert(affinity_nodim, "G"), 30622.4, tolerance = 4000, scale = 1, info = info)
 
-# Pyruvate phosphorylation with acetylphosphate: circular reference
+info <- "Pyruvate phosphorylation with acetylphosphate"
 affinity_nodim <- as.numeric(phosphorylate("pyruvic acid", "acetylphosphate")$a12)
-expect_equal(affinity_nodim, -5.06, tolerance = 0.01, scale = 1)
+# Circular reference
+expect_equal(affinity_nodim, -5.06, tolerance = 0.01, scale = 1, info = info)
 
 info <- "Error produced with unknown reactant or P_source"
 # reactant should be pyruvic acid, not pyruvate
-expect_error(phosphorylate("pyruvate", "acetylphosphate"), "unrecognized reactant")
+expect_error(phosphorylate("pyruvate", "acetylphosphate"), "unrecognized reactant", info = info)
 # acetyphosphate is missing an "l"
-expect_error(phosphorylate("pyruvic acid", "acetyphosphate"), "unrecognized P_source")
+expect_error(phosphorylate("pyruvic acid", "acetyphosphate"), "unrecognized P_source", info = info)



More information about the CHNOSZ-commits mailing list