[CHNOSZ-commits] r92 - in pkg/CHNOSZ: . inst inst/tests tests tests/testthat

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Oct 8 14:20:22 CEST 2015


Author: jedick
Date: 2015-10-08 14:20:21 +0200 (Thu, 08 Oct 2015)
New Revision: 92

Added:
   pkg/CHNOSZ/tests/testthat/
   pkg/CHNOSZ/tests/testthat/test-EOSregress.R
   pkg/CHNOSZ/tests/testthat/test-IAPWS95.R
   pkg/CHNOSZ/tests/testthat/test-affinity.R
   pkg/CHNOSZ/tests/testthat/test-basis.R
   pkg/CHNOSZ/tests/testthat/test-diagram.R
   pkg/CHNOSZ/tests/testthat/test-eos.R
   pkg/CHNOSZ/tests/testthat/test-equilibrate.R
   pkg/CHNOSZ/tests/testthat/test-findit.R
   pkg/CHNOSZ/tests/testthat/test-info.R
   pkg/CHNOSZ/tests/testthat/test-ionize.aa.R
   pkg/CHNOSZ/tests/testthat/test-ionize.aa_pK.R
   pkg/CHNOSZ/tests/testthat/test-iprotein.R
   pkg/CHNOSZ/tests/testthat/test-makeup.R
   pkg/CHNOSZ/tests/testthat/test-more.aa.R
   pkg/CHNOSZ/tests/testthat/test-mosaic.R
   pkg/CHNOSZ/tests/testthat/test-protein.info.R
   pkg/CHNOSZ/tests/testthat/test-revisit.R
   pkg/CHNOSZ/tests/testthat/test-species.R
   pkg/CHNOSZ/tests/testthat/test-subcrt.R
   pkg/CHNOSZ/tests/testthat/test-swap.basis.R
   pkg/CHNOSZ/tests/testthat/test-thermo.R
   pkg/CHNOSZ/tests/testthat/test-util.R
   pkg/CHNOSZ/tests/testthat/test-util.affinity.R
   pkg/CHNOSZ/tests/testthat/test-util.data.R
   pkg/CHNOSZ/tests/testthat/test-util.list.R
   pkg/CHNOSZ/tests/testthat/test-util.program.R
   pkg/CHNOSZ/tests/testthat/test-util.seq.R
   pkg/CHNOSZ/tests/testthat/test-water.R
   pkg/CHNOSZ/tests/testthat/test-wjd.R
   pkg/CHNOSZ/tests/testthat/test-yeastgfp.R
Removed:
   pkg/CHNOSZ/inst/tests/test-EOSregress.R
   pkg/CHNOSZ/inst/tests/test-IAPWS95.R
   pkg/CHNOSZ/inst/tests/test-affinity.R
   pkg/CHNOSZ/inst/tests/test-basis.R
   pkg/CHNOSZ/inst/tests/test-diagram.R
   pkg/CHNOSZ/inst/tests/test-eos.R
   pkg/CHNOSZ/inst/tests/test-equilibrate.R
   pkg/CHNOSZ/inst/tests/test-findit.R
   pkg/CHNOSZ/inst/tests/test-info.R
   pkg/CHNOSZ/inst/tests/test-ionize.aa.R
   pkg/CHNOSZ/inst/tests/test-ionize.aa_pK.R
   pkg/CHNOSZ/inst/tests/test-iprotein.R
   pkg/CHNOSZ/inst/tests/test-makeup.R
   pkg/CHNOSZ/inst/tests/test-more.aa.R
   pkg/CHNOSZ/inst/tests/test-mosaic.R
   pkg/CHNOSZ/inst/tests/test-protein.info.R
   pkg/CHNOSZ/inst/tests/test-revisit.R
   pkg/CHNOSZ/inst/tests/test-species.R
   pkg/CHNOSZ/inst/tests/test-subcrt.R
   pkg/CHNOSZ/inst/tests/test-swap.basis.R
   pkg/CHNOSZ/inst/tests/test-thermo.R
   pkg/CHNOSZ/inst/tests/test-util.R
   pkg/CHNOSZ/inst/tests/test-util.affinity.R
   pkg/CHNOSZ/inst/tests/test-util.data.R
   pkg/CHNOSZ/inst/tests/test-util.list.R
   pkg/CHNOSZ/inst/tests/test-util.program.R
   pkg/CHNOSZ/inst/tests/test-util.seq.R
   pkg/CHNOSZ/inst/tests/test-water.R
   pkg/CHNOSZ/inst/tests/test-wjd.R
   pkg/CHNOSZ/inst/tests/test-yeastgfp.R
Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/tests/test-all.R
Log:
move tests from inst/tests to tests/testthat


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2015-07-10 12:00:15 UTC (rev 91)
+++ pkg/CHNOSZ/DESCRIPTION	2015-10-08 12:20:21 UTC (rev 92)
@@ -1,6 +1,6 @@
-Date: 2015-07-10
+Date: 2015-10-08
 Package: CHNOSZ
-Version: 1.0.5-4
+Version: 1.0.5-5
 Title: Chemical Thermodynamics and Activity Diagrams
 Author: Jeffrey Dick
 Maintainer: Jeffrey Dick <j3ffdick at gmail.com>

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2015-07-10 12:00:15 UTC (rev 91)
+++ pkg/CHNOSZ/inst/NEWS	2015-10-08 12:20:21 UTC (rev 92)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.0.5-4 (2015-07-10)
+CHANGES IN CHNOSZ 1.0.5-8 (2015-10-08)
 --------------------------------------
 
 - Rewrite rho.IAPWS95() to be able to invert density from IAPWS-95
@@ -36,6 +36,12 @@
 - Fix incorrect entry for entropy of aqueous methionine and [Met] in
   OBIGT.csv. Thanks to Apar Prasad for spotting this.
 
+- Some fixes to tests for compatibility with new version of testthat
+  (increase tolerance for one test in test-eos.R because of swapping
+  actual/expected values in equals(); move inst/tests to
+  inst/test/testthat; use test_check instead of test_package in
+  test-all.R (for R CMD check)).
+
 CHANGES IN CHNOSZ 1.0.5 (2015-05-19)
 ------------------------------------
 

Deleted: pkg/CHNOSZ/inst/tests/test-EOSregress.R
===================================================================
--- pkg/CHNOSZ/inst/tests/test-EOSregress.R	2015-07-10 12:00:15 UTC (rev 91)
+++ pkg/CHNOSZ/inst/tests/test-EOSregress.R	2015-10-08 12:20:21 UTC (rev 92)
@@ -1,48 +0,0 @@
-context("EOSregress")
-
-# since this is the first test (alphabetically)
-# we need to load the 'thermo' object (for R CMD check)
-suppressMessages(data(thermo))
-
-test_that("EOSvar stops with unknown variables", {
-  expect_error(EOSvar("TX", T=25, P=1), "can't find a variable named TX")
-  # why can't the test find these?
-  #TX <- 2
-  #expect_error(EOSvar("TX", T=25, P=1), "an object named TX is not a function")
-  #TX <- function(T) 2
-  #expect_error(EOSvar("TX", T=25, P=1), "the arguments of TX\\(\\) are not T, P")
-})
-
-test_that("regressions return known HKF parameters", { 
-  # regress computed values of heat capacity and volume of CH4(aq)
-  # calculated from HKF parameters on a T-P grid
-  T <- convert(seq(0, 350, 25), "K")
-  P <- seq(200, 1000, 100)
-  # convert=FALSE means that temperature has units of K
-  CH4.prop <- subcrt("CH4", T=T, P=P, grid="T", convert=FALSE)$out[[1]]
-  # terms in the HKF equations for Cp
-  Cp.var <- c("invTTheta2", "TXBorn")
-  # get coefficients in Cp regression
-  Cp.lm <- EOSregress(CH4.prop[, c("T", "P", "Cp")], Cp.var)
-  Cp.coeff <- Cp.lm$coefficients
-  # terms in the HKF equations for V
-  V.var <- c("invPPsi", "invTTheta", "invPPsiTTheta", "QBorn")
-  # get coefficients in V regression
-  V.lm <- EOSregress(CH4.prop[, c("T", "P", "V")], V.var)
-  # use same units as HKF: convert from cm3.bar to calories (divide by 41.84)
-  V.coeff <- convert(V.lm$coefficients, "calories")
-  ## the tests: did we get the HKF parameters that are in the database?
-  CH4.par <- info(info("CH4"))
-  # c1 and c2
-  expect_equal(Cp.coeff[1], CH4.par$c1, check.attributes=FALSE)
-  expect_equal(Cp.coeff[2], CH4.par$c2, check.attributes=FALSE)
-  # omega (from Cp)
-  expect_equal(Cp.coeff[3], CH4.par$omega, check.attributes=FALSE)
-  # a1, a2, a3 and a4
-  expect_equal(V.coeff[1], CH4.par$a1, check.attributes=FALSE)
-  expect_equal(V.coeff[2], CH4.par$a2, check.attributes=FALSE)
-  expect_equal(V.coeff[3], CH4.par$a3, check.attributes=FALSE)
-  expect_equal(V.coeff[4], CH4.par$a4, check.attributes=FALSE)
-  # omega (from V) - note negative sign
-  expect_equal(-V.coeff[5], CH4.par$omega, check.attributes=FALSE)
-})

Deleted: pkg/CHNOSZ/inst/tests/test-IAPWS95.R
===================================================================
--- pkg/CHNOSZ/inst/tests/test-IAPWS95.R	2015-07-10 12:00:15 UTC (rev 91)
+++ pkg/CHNOSZ/inst/tests/test-IAPWS95.R	2015-10-08 12:20:21 UTC (rev 92)
@@ -1,90 +0,0 @@
-context("IAPWS95")
-
-test_that("calculations of Helmholtz free energy and its derivatives are consistent with reference cases", {
-  ## reference values of these terms are listed Table 6.6 of Wagner and Pruss, 2002  
-  p <- c("phi", "phi.delta", "phi.delta.delta", "phi.tau", "phi.tau.tau", "phi.delta.tau")
-  # reference values for case 1: T=500 K, rho=838.025 kg m-3
-  idealgas.ref.1 <- c(0.204797734e1, 0.384236747, -0.147637878, 0.904611106e1, -0.193249185e1, 0)
-  residual.ref.1 <- c(-0.342693206e1, -0.364366650, 0.856063701, -0.581403435e1, -0.223440737e1, -0.112176915e1)
-  # reference values for case 1: T=647 K, rho=358 kg m-3
-  idealgas.ref.2 <- c(-0.156319605e1, 0.899441341, -0.808994726, 0.980343918e1, -0.343316334e1, 0)
-  residual.ref.2 <- c(-0.121202657e1, -0.714012024, 0.475730696, -0.321722501e1, -0.996029507e1, -0.133214720e1)
-  ## set up the problem
-  # critical point constants
-  T.critical <- 647.096 # K
-  rho.critical <- 322 # kg m-3
-  # T and rho for cases 1 and 2
-  T <- c(500, 647)
-  rho <- c(838.025, 358)
-  # delta and tau for cases 1 and 2
-  delta <- rho / rho.critical
-  tau <- T.critical / T
-  # calculated ideal gas and residual parts for case 1
-  idealgas.calc.1 <- sapply(p, IAPWS95.idealgas, delta[1], tau[1])
-  residual.calc.1 <- sapply(p, IAPWS95.residual, delta[1], tau[1])
-  # calculated ideal gas and residual parts for case 2
-  idealgas.calc.2 <- sapply(p, IAPWS95.idealgas, delta[2], tau[2])
-  residual.calc.2 <- sapply(p, IAPWS95.residual, delta[2], tau[2])
-  ## perform the tests
-  # we almost get away without increasing the tolerance in any test ...
-  expect_equal(idealgas.calc.1, idealgas.ref.1, check.attributes=FALSE)
-  expect_equal(residual.calc.1, residual.ref.1, check.attributes=FALSE)
-  expect_equal(idealgas.calc.2, idealgas.ref.2, check.attributes=FALSE)
-  # ... however an offset is apparent in the value of the residual phi.delta.delta for case 2
-  expect_equal(residual.calc.2, residual.ref.2, check.attributes=FALSE, tolerance=1e-5)
-})
-
-test_that("calculations of thermodynamic properties are consistent with reference values", {
-  ## these are the properties we test - from Table 13.1 of Wagner and Pruss, 2002
-  ## (speed of sound omitted as it's not currently implemented)
-  p <- c("P", "H", "S", "Cv", "Cp")
-  ## a selection of T and rho at vapor-liquid boundary
-  ## (NOTE: excluding triple and critical points; we have some unresolved issues there)
-  T <- c(274, 320, 368, 416, 464, 512, 560, 608, 647)
-  rho.liquid <- c(999.843, 989.387, 961.984, 923.577, 875.125, 814.982, 737.831, 626.74, 357.34)
-  rho.vapor <- c(0.00514, 0.07166, 0.50231, 2.1203, 6.5107, 16.409, 37.147, 84.173, 286.51)
-  ## reference values
-  P.ref <- c(0.000650, 0.010546, 0.084142, 0.39166, 1.2788, 3.2798, 7.1062, 13.681, 22.038)
-  H.liquid.ref <- c(3.544, 196.170, 397.457, 601.396, 811.225, 1032.06, 1273.11, 1558.42, 2029.44)
-  H.vapor.ref <- c(2502.46, 2585.71, 2667.37, 2737.09, 2785.91, 2803.05, 2771.24, 2646.01, 2148.56)
-  S.liquid.ref <- c(0.0130, 0.6629, 1.2487, 1.7687, 2.2436, 2.6914, 3.1319, 3.6034, 4.3224)
-  S.vapor.ref <- c(9.1331, 8.1302, 7.4169, 6.9025, 6.4994, 6.1504, 5.8071, 5.3922, 4.5065)
-  cv.liquid.ref <- c(4.2156, 4.0416, 3.7950, 3.5560, 3.3523, 3.1884, 3.0722, 3.0617, 6.2344)
-  cv.vapor.ref <- c(1.4191, 1.4627, 1.5428, 1.7138, 2.0015, 2.3697, 2.8225, 3.4538, 6.2740)
-  cp.liquid.ref <- c(4.2171, 4.1807, 4.2101, 4.2892, 4.4513, 4.7616, 5.4239, 7.6169, 3905.2)
-  cp.vapor.ref <- c(1.8852, 1.9417, 2.0601, 2.3334, 2.8561, 3.7263, 5.4099, 10.805, 5334.1)
-  ## calculated values
-  liquid.calc <- IAPWS95(p, T, rho.liquid)
-  vapor.calc <- IAPWS95(p, T, rho.vapor)
-  ## the tests
-  # take P to 5 significant digits but not more than 6 decimals
-  expect_equal(round(signif(liquid.calc$p, 5), 6), P.ref, tolerance=1e-3)
-  expect_equal(round(signif(vapor.calc$p, 5), 6), P.ref, tolerance=1e-4)
-  # take H to 6 significant digits but not more than 3 decimals
-  expect_equal(round(signif(liquid.calc$h, 6), 3), H.liquid.ref, tolerance=1e-5)
-  expect_that(round(signif(vapor.calc$h, 6), 3), equals(H.vapor.ref))  # spot on!
-  # round S to 4 decimals
-  expect_that(round(liquid.calc$s, 4), equals(S.liquid.ref))  # spot on!
-  expect_equal(round(vapor.calc$s, 4), S.vapor.ref, tolerance=1e-4)
-  # round cv to 4 decimals
-  expect_equal(round(liquid.calc$cv, 4), cv.liquid.ref, tolerance=1e-4)
-  expect_equal(round(vapor.calc$cv, 4), cv.vapor.ref, tolerance=1e-4)
-  # take cp to 5 significant digits but not more than 4 decimals
-  # note high tolerance setting: the highest temperature is the challenge
-  expect_equal(round(signif(liquid.calc$cp, 5), 4), cp.liquid.ref, tolerance=1e0)
-  expect_equal(round(signif(vapor.calc$cp, 5), 4), cp.vapor.ref, tolerance=1e-1)
-})
-
-test_that("calculations are possible at low temperatures", {
-  # the sequences start at the lowest whole-number temperature (K) 
-  # where the function returns a value of density at the given pressure
-  expect_that(any(is.na(water.IAPWS95("rho", T=seq(234, 274, 3), P=rep(1, 14)))), is_false())
-  expect_that(any(is.na(water.IAPWS95("rho", T=seq(227, 272, 3), P=rep(1000, 16)))), is_false())
-})
-
-# reference
-
-# Wagner, W. and Pruss, A. (2002)
-#   The IAPWS formulation 1995 for the thermodynamic properties of
-#   ordinary water substance for general and scientific use
-#   J. Phys. Chem. Ref. Data 31, 387--535. http://dx.doi.org/10.1063/1.1461829

Deleted: pkg/CHNOSZ/inst/tests/test-affinity.R
===================================================================
--- pkg/CHNOSZ/inst/tests/test-affinity.R	2015-07-10 12:00:15 UTC (rev 91)
+++ pkg/CHNOSZ/inst/tests/test-affinity.R	2015-10-08 12:20:21 UTC (rev 92)
@@ -1,161 +0,0 @@
-context("affinity")
-
-# clear out any previous basis definition or database alterations
-suppressMessages(data(thermo))
-
-test_that("errors come as expected, and output gives T and P in user's units", {
-  expect_error(affinity(iprotein=7), "basis species are not defined")
-  basis("CHNOS")
-  expect_error(affinity(), "species have not been defined")
-  species("5a(H),14b(H)-cholestane")
-  a.C_bar <- affinity(T=c(0, 100, 10), P=c(10, 1000, 10))
-  expect_equal(range(a.C_bar$vals[[1]]), c(0, 100))
-  expect_equal(range(a.C_bar$vals[[2]]), c(10, 1000))
-  T.units("K")
-  P.units("MPa")
-  a.K_MPa <- affinity(T=c(273.15, 373.15, 10), P=c(1, 100, 10))
-  expect_equal(range(a.K_MPa$vals[[1]]), c(273.15, 373.15))
-  expect_equal(range(a.K_MPa$vals[[2]]), c(1, 100))
-  # different units, same T,P ... same affinities
-  expect_equal(a.C_bar$values, a.K_MPa$values)
-  # go back to original units for the remaining tests
-  T.units("C")
-  P.units("bar")
-})
-
-test_that("pe, pH and Eh are correctly handled", {
-  basis("CHNOSe")
-  species(c("HS-", "H2S", "SO4-2"))
-  Eh <- c(-1, 1)
-  pe <- convert(Eh, "pe", T=convert(100, "K"))
-  a.Eh <- affinity(Eh=Eh, T=100)
-  a.pe <- affinity(pe=pe, T=100)
-  # they should give the same result
-  expect_equal(a.Eh$values, a.pe$values)
-  # the variables should have the right names
-  expect_equal(c(a.Eh$vars, a.pe$vars), c("Eh", "pe"))
-  # now for an Eh-pH example
-  pH <- c(0, 14)
-  a <- affinity(pH=pH, Eh=Eh)
-  expect_equal(a$vars, c("pH", "Eh"))
-  expect_equal(range(a$vals[[1]]), pH)
-  expect_equal(range(a$vals[[2]]), Eh)
-  expect_equal(length(a$vals[[2]]), 128)
-  # since Eh has to be reconstructed, check it's done correctly
-  a129 <- affinity(pH=pH, Eh=c(Eh, 129))
-  expect_equal(length(a129$vals[[2]]), 129)
-
-  ## a transect of hotter, more oxidizing and more acidic
-  ## has not been working since at least 0.9-7
-  ##T <- c(25, 50, 100, 125, 150)
-  ##Eh <- c(-1, -0.5, 0, 0.5, 1)
-  ##pH <- c(10, 8, 6, 4, 2)
-  ##a <- affinity(T=T, Eh=Eh, pH=pH)
-})
-
-test_that("affinity() in 3D returns values consistent with manual calculation", {
-  # our "manual" calculation will be for H2(aq) + 0.5O2(aq) = H2O(l)
-  # the equilibrium constants at 25 and 100 degrees C
-  # (the logK are tested against literature values in test-subcrt.R)
-  logK.25 <- subcrt(c("H2", "O2", "H2O"), "aq", c(-1, -0.5, 1), T=25)$out$logK
-  logK.100 <- subcrt(c("H2", "O2", "H2O"), "aq", c(-1, -0.5, 1), T=100)$out$logK
-  # the value of A/2.303RT at 25 degrees and logaH2=-10, logaO2=-10 and logaH2O=0
-  A.2303RT.25.10.10 <- logK.25 - ( (-1)*(-10) + (-0.5)*(-10) )
-  # the value of A/2.303RT at 100 degrees and logaH2=-5, logaO2=-10 and logaH2O=0
-  A.2303RT.100.5.10 <- logK.100 - ( (-1)*(-5) + (-0.5)*(-10) )
-  # set up basis and species
-  basis(c("H2", "O2"), "aq")
-  species("H2O")
-  # we will run affinity() in 3D
-  # T = 0, 25, 50, 75, 100, 125 degrees
-  # log_a(H2) = -20, -15, -10, -5, 0
-  # log_a(O2) = -20, -15, -10, -5, 0
-  # first test: the dimensions are correct
-  a.logK <- affinity(T=c(0, 125, 6), H2=c(-20, 0, 5), O2=c(-20, 0, 5), property="logK")
-  expect_equal(dim(a.logK$values[[1]]), c(6, 5, 5))
-  # second and third tests: the logK values used by affinity() are correct
-  expect_equal(a.logK$values[[1]][2, 3, 3], logK.25)
-  expect_equal(a.logK$values[[1]][5, 4, 3], logK.100)
-  # fourth and fifth tests: the A/2.303RT values returned by affinity() are correct
-  a.A <- affinity(T=c(0, 125, 6), H2=c(-20, 0, 5), O2=c(-20, 0, 5))
-  expect_equal(a.A$values[[1]][2, 3, 3], A.2303RT.25.10.10)
-  expect_equal(a.A$values[[1]][5, 4, 3], A.2303RT.100.5.10)
-})
-
-test_that("'iprotein' gives consistent results on a transect", {
-  # from Dick and Shock, 2011, values of A/2.303RT for the per-residue
-  # formation reactions of overall model proteins at five sampling sites
-  # at Bison Pool, with different temperature, pH and log_a(H2)
-  # these are the maximum values for each site from Table 5 in the paper
-  A.2303RT_ref <- c(-18.720, -27.894, -35.276, -36.657, -41.888)
-  # the measured temperatures and pHs
-  T <- c(93.3, 79.4, 67.5, 65.3, 57.1)
-  pH <- c(7.350, 7.678, 7.933, 7.995, 8.257)
-  # Eq. 24 of the paper
-  H2 <- -11+T*3/40
-  # remove "RESIDUE" entries in thermo$obigt (clutter from first test)
-  data(thermo)
-  basis(c("HCO3-", "H2O", "NH3", "HS-", "H2", "H+"),
-    "aq", c(-3, 0, -4, -7, 999, 999))
-  sites <- c("N", "S", "R", "Q", "P")
-  aa <- read.aa(system.file("extdata/protein/DS11.csv", package="CHNOSZ"))
-  ip <- add.protein(aa[1:5, ])
-  # to reproduce, we need use the "old" parameters for [Met]
-  add.obigt()
-  a <- affinity(T=T, pH=pH, H2=H2, iprotein=ip)
-  # divide A/2.303RT by protein length
-  pl <- protein.length(ip)
-  A.2303RT <- t(sapply(a$values, c)) / pl
-  # find the maximum for each site
-  A.2303RT_max <- apply(A.2303RT, 2, max)
-  # we're off a bit in the second decimal ... 
-  # maybe becuase of rounding of the aa composition?
-  expect_equal(A.2303RT_max, A.2303RT_ref, tolerance=1e-3)
-  # todo: add comparison with results from loading proteins via species()
-})
-
-test_that("affinity() for proteins (with/without 'iprotein') returns same value as in previous package versions", {
-  # our test case is CSG_HALJP because it has no methionine
-  # (aqueous [Met] was updated in 0.9-9)
-  # these values were calculated using versions 0.6, 0.8 and 0.9-7
-  # (25 degrees C, 1 bar, basis species "CHNOS" or "CHNOS+")
-  A.2303RT.nonionized <- -3795.297
-  A.2303RT.ionized <- -3075.222
-  # first for nonionized protein
-  basis("CHNOS")
-  # try it with iprotein
-  ip <- iprotein("CSG_HALJP")
-  expect_equal(affinity(iprotein=ip)$values[[1]][1], A.2303RT.nonionized, tolerance=1e-6)
-  # then with the protein loaded as a species
-  species("CSG_HALJP")
-  expect_equal(affinity()$values[[1]][1], A.2303RT.nonionized, tolerance=1e-6)
-  # now for ionized protein
-  basis("CHNOS+")
-  expect_equal(affinity(iprotein=ip)$values[[1]][1], A.2303RT.ionized, tolerance=1e-6)
-  species("CSG_HALJP")
-  expect_equal(affinity()$values[[1]][1], A.2303RT.ionized, tolerance=1e-6)
-})
-
-test_that("affinity() for proteins keeps track of pH on 2-D calculations", {
-  # (relates to the "thisperm" construction in A.ionization() )
-  basis("CHNOS+")
-  species("LYSC_CHICK")
-  a1 <- affinity(pH=c(6, 8, 3))
-  a2 <- affinity(pH=c(6, 8, 3), T=c(0, 75, 4))
-  expect_equal(as.numeric(a1$values[[1]]), a2$values[[1]][, 2])
-})
-
-test_that("IS can be constant or variable", {
-  # inspired by an error from demo("phosphate")
-  # > a25 <- affinity(IS=c(0, 0.14), T=T[1])
-  # ...
-  # Error in subcrt(species = c(1017L, 20L, 19L), property = "logK", T = 298.15,  : 
-  #   formal argument "IS" matched by multiple actual arguments
-  basis("CHNOPS+")
-  species(c("PO4-3", "HPO4-2", "H2PO4-"))
-  a0 <- affinity()
-  a1 <- affinity(IS=0.14)
-  a2 <- affinity(IS=c(0, 0.14))
-  expect_equal(unlist(lapply(a2$values, head, 1)), unlist(a0$values))
-  expect_equal(unlist(lapply(a2$values, tail, 1)), unlist(a1$values))
-})

Deleted: pkg/CHNOSZ/inst/tests/test-basis.R
===================================================================
--- pkg/CHNOSZ/inst/tests/test-basis.R	2015-07-10 12:00:15 UTC (rev 91)
+++ pkg/CHNOSZ/inst/tests/test-basis.R	2015-10-08 12:20:21 UTC (rev 92)
@@ -1,41 +0,0 @@
-context("basis")
-
-# clear out any previous basis definition or database alterations
-suppressMessages(data(thermo))
-
-test_that("invalid basis definitions cause an error", {
-  expect_error(basis(character()), "argument is empty")
-  expect_error(basis(c("CO2", "CO2")), "names are not unique")
-  expect_error(basis(c("CO2", "H2O")), "underdetermined")
-  expect_error(basis(c("H2O", "O2", "H2")), "overdetermined")
-  expect_error(basis(c("HCN", "H2O", "O2", "H2")), "singular")
-  expect_error(basis(c("CN", "H2O", "O2", "H2")), "species not available")
-  expect_error(basis(c("CN")), "species not available")
-  expect_error(basis("Fe", "cr"), "species not available: Fe\\(cr\\)")
-  ina <- nrow(thermo$obigt) + 1
-  expect_error(basis(ina), "species not available")
-  expect_error(preset.basis(c("CN")), "is not a keyword")
-  # after all that, the basis should still be undefined
-  expect_is(basis(), "NULL")
-})
-
-test_that("invalid basis modification requests cause an error", {
-  basis(delete=TRUE)
-  expect_error(mod.basis("CH4", "gas"), "basis is not defined")
-  b <- basis("CHNOS+")
-  expect_error(mod.basis("CH4", "gas"), "is not a formula of one of the basis species")
-  iCH4 <- info("CH4")
-  expect_error(mod.basis(iCH4, "gas"), "is not a species index of one of the basis species")
-  expect_error(mod.basis("CO2", "PPM"), "the elements .* in buffer .* are not in the basis")
-  expect_error(mod.basis("CO2", "liq"), "state .* not found")
-  # after all that, the basis should be unchanged
-  expect_equal(basis(), b)
-})
-
-test_that("changing state maintains species name", {
-  b1 <- basis(c("Al2O3", "quartz", "oxygen"))
-  b2 <- basis("SiO2", "cr2")
-  # we went from quartz cr1 to cr2, which is the next row in the database
-  expect_equal(sum(b2$ispecies - b1$ispecies), 1)
-  expect_error(basis("SiO2", "cr3"), "state or buffer 'cr3' not found for quartz")
-})

Deleted: pkg/CHNOSZ/inst/tests/test-diagram.R
===================================================================
--- pkg/CHNOSZ/inst/tests/test-diagram.R	2015-07-10 12:00:15 UTC (rev 91)
+++ pkg/CHNOSZ/inst/tests/test-diagram.R	2015-10-08 12:20:21 UTC (rev 92)
@@ -1,86 +0,0 @@
-context("diagram")
-
-test_that("expected errors are produced for inconsistent arguments", {
-  expect_error(diagram(list()), "'eout' does not look like output from equil\\(\\) or affinity\\(\\)")
-  basis("CHNOS")
-  species(c("glycine", "alanine"))
-  a <- affinity()
-  expect_message(diagram(a, plot.it=FALSE), "coefficients are moles of CO2 in formation reactions")
-  e <- equilibrate(a)
-  expect_error(diagram(e, "Z"), "Z is not a basis species")
-})
-
-test_that("expected messages, errors and results arise using output from affinity()", {
-  basis("CHNOS+")
-  # fugacity of O2 is buffered here
-  basis("O2", "CO2-AC")
-  species(c("formic acid", "formate", "acetic acid", "acetate"))
-  # 0-D
-  a <- affinity()
-  # equilibrium activities are not possible here
-  expect_error(diagram(a, "loga.equil"), "'eout' is not the output from equil\\(\\)")
-  # we can't calculate the equilibrium activity of a basis species if it's externally buffered
-  expect_error(diagram(a, "O2"), "is not numeric - was a buffer selected\\?")
-  # this one works - a barplot of A/2.303RT
-  expect_message(diagram(a, plot.it=FALSE), "coefficients are moles of CO2 in formation reactions")
-  # if we're plotting A/2.303RT the values can be divided by balancing coefficient or not
-  d.1 <- diagram(a, balance=1, plot.it=FALSE)
-  d.CO2 <- diagram(a, plot.it=FALSE)
-  expect_equal(as.numeric(d.CO2$plotvals), as.numeric(d.1$plotvals)/c(1, 1, 2, 2))
-  # now run the calculation over a range of O2 
-  basis("O2", -90)
-  # 1-D
-  a <- affinity(O2=c(-80, -70))
-  # ask for the equilibrium activity of CO2
-  expect_error(diagram(a, "CO2", groups=list(1:2, 3:4)), "can't plot equilibrium activities of basis species for grouped species")
-  expect_error(diagram(a, "CO2", alpha=TRUE), "equilibrium activities of basis species not available with alpha=TRUE")
-  d <- diagram(a, "CO2", plot.it=FALSE)
-  # test that the result does in fact correspond to zero affinity of formation, how about for acetate?
-  a <- affinity(O2=d$vals[[1]], CO2=d$plotvals[[4]])
-  expect_equal(a$values[[4]], array(numeric(128)))
-})
-
-test_that("'groups' and 'alpha' work as expected", {
-  basis("CHNOS+")
-  species(c("formic acid", "formate", "acetic acid", "acetate"))
-  # 1-D
-  a <- affinity(O2=c(-80, -60))
-  e <- equilibrate(a)
-  # group the species together
-  d <- diagram(e, groups=list(1:2, 3:4), plot.it=FALSE)
-  # we should find that their activities have been summed
-  expect_equal(d$plotvals[[1]], log10(10^e$loga.equil[[1]] + 10^e$loga.equil[[2]]))
-  expect_equal(d$plotvals[[2]], log10(10^e$loga.equil[[3]] + 10^e$loga.equil[[4]]))
-  # ask for degrees of formation instead of logarithms of activities
-  d <- diagram(e, alpha=TRUE, plot.it=FALSE)
-  # we should find that the sum of alphas is one
-  expect_equal(Reduce("+", d$plotvals), array(rep(1, 128)))
-})
-
-test_that("'normalize' and 'as.residue' work as expected", {
-  basis("CHNOS")
-  species(c("LYSC_CHICK", "MYG_PHYCA", "RNAS1_BOVIN", "CYC_BOVIN"))
-  # 1-D
-  a <- affinity(O2=c(-80, -70))
-  expect_error(diagram(a, normalize=TRUE), "can be TRUE only for a 2-D \\(predominance\\) diagram")
-  # 2-D
-  a <- affinity(H2O=c(-10, 0), O2=c(-80, -70))
-  d1 <- diagram(a, normalize=TRUE, plot.it=FALSE)
-  e <- equilibrate(a, normalize=TRUE)
-  d2 <- diagram(e, plot.it=FALSE)
-  expect_equal(d1$predominant, d2$predominant)
-  expect_error(diagram(e, normalize=TRUE), "can be TRUE only if 'eout' is the output from affinity\\(\\)")
-  d3 <- diagram(a, as.residue=TRUE, plot.it=FALSE)
-  e <- equilibrate(a, as.residue=TRUE)
-  d4 <- diagram(e, plot.it=FALSE)
-  expect_equal(d3$predominant, d4$predominant)
-})
-
-test_that("diagram() handles 2D plots with different x and y resolution and warns for >1 species in contour plot", {
-  basis("CHNOS")
-  species(c("alanine", "glycine", "serine", "methionine"))
-  a <- affinity(T=c(0, 200, 6), O2=c(-90, -60, 5))
-  # TODO: fix plot.line() function in diagram() so that the plot can be made
-  #expect_equal(diagram(a), diagram(a, plot.it=FALSE))
-  expect_warning(diagram(a, what="CO2", plot.it=FALSE), "showing only first species in 2-D property diagram")
-})

Deleted: pkg/CHNOSZ/inst/tests/test-eos.R
===================================================================
--- pkg/CHNOSZ/inst/tests/test-eos.R	2015-07-10 12:00:15 UTC (rev 91)
+++ pkg/CHNOSZ/inst/tests/test-eos.R	2015-10-08 12:20:21 UTC (rev 92)
@@ -1,72 +0,0 @@
-context("eos")
-
-test_that("gfun() gives expected results", {
-  # calculate values of g and its derivatives 
-  # up to 350 degrees C at Psat
-  Tc <- c(0, 25, 50, 100, 150, 200, 250, 300, 350)
-  # get the required properties of water
-  w <- water(c("rho", "alpha", "daldT", "beta", "Psat"), T=convert(Tc, "K"), P="Psat")
-  # calculate g and its derivatives
-  gfun.Psat <- gfun(w$rho/1000, Tc, w$Psat, w$alpha, w$daldT, w$beta)
-  # up to 450 degrees C at 500 bar
-  Tc <- c(Tc, 400, 450)
-  w <- water(c("rho", "alpha", "daldT", "beta"), T=convert(Tc, "K"), P=500)
-  gfun.500 <- gfun(w$rho/1000, Tc, rep(500, length(Tc)), w$alpha, w$daldT, w$beta)
-  # up to 600 degrees C at 1000 bar
-  Tc <- c(Tc, 500, 550, 600)
-  w <- water(c("rho", "alpha", "daldT", "beta"), T=convert(Tc, "K"), P=1000)
-  gfun.1000 <- gfun(w$rho/1000, Tc, rep(1000, length(Tc)), w$alpha, w$daldT, w$beta)
-  # up to 1000 degrees C at 4000 bar
-  Tc <- c(Tc, 700, 800, 900, 1000)
-  w <- water(c("rho", "alpha", "daldT", "beta"), T=convert(Tc, "K"), P=4000)
-  gfun.4000 <- gfun(w$rho/1000, Tc, rep(4000, length(Tc)), w$alpha, w$daldT, w$beta)
-
-  # values from table 5 of Shock et al., 1992
-  g.Psat.ref <- c(0, 0, 0, 0, -0.09, -1.40, -8.05, -35.23, -192.05)
-  g.500.ref <- c(0, 0, 0, 0, -0.02, -0.43, -3.55, -16.81, -56.78, -287.16, -1079.75)
-  g.1000.ref <- c(0, 0, 0, 0, 0, -0.12, -1.49, -8.44, -30.59, -85.09, -201.70, -427.17, -803.53, -1312.67)
-  g.4000.ref <- c(0, 0, 0, 0, 0, 0, 0, -0.01, -0.20, -1.14, -3.52, -7.84, -14.19, -22.21, -40.15, -54.28, -59.35, -55.17)
-  # compare the calculations with the reference values
-  # note: tolerance is set as low as possible (order of magnitude) for successful tests
-  expect_equal(gfun.Psat$g * 1e4, g.Psat.ref, tolerance=1e-4)
-  expect_equal(gfun.500$g  * 1e4, g.500.ref,  tolerance=1e-4)
-  expect_equal(gfun.1000$g * 1e4, g.1000.ref, tolerance=1e-5)
-  expect_equal(gfun.4000$g * 1e4, g.4000.ref, tolerance=1e-4)
-
-  # values from table 6 of Shock et al., 1992
-  dgdT.Psat.ref <- c(0, 0, 0, -0.01, -0.62, -6.13, -25.33, -123.20, -1230.59)
-  dgdT.500.ref <- c(0, 0, 0, 0, -0.13, -2.21, -12.54, -46.50, -110.45, -734.92, -2691.41)
-  dgdT.1000.ref <- c(0, 0, 0, 0, -0.02, -0.75, -6.12, -24.83, -69.29, -158.38, -324.13, -594.43, -904.41, -1107.84)
-  dgdT.4000.ref <- c(0, 0, 0, 0, 0, 0, 0, -0.08, -0.89, -3.09, -6.60, -10.72, -14.55, -17.29, -17.26, -10.06, -0.08, 7.82)
-  expect_equal(gfun.Psat$dgdT * 1e6, dgdT.Psat.ref, tolerance=1e-2)
-  expect_equal(gfun.500$dgdT  * 1e6, dgdT.500.ref,  tolerance=1e-2)
-  expect_equal(gfun.1000$dgdT * 1e6, dgdT.1000.ref, tolerance=1e-5)
-  expect_equal(gfun.4000$dgdT * 1e6, dgdT.4000.ref, tolerance=1e-3)
-
-  # values from table 7 of Shock et al., 1992
-  d2gdT2.Psat.ref <- c(0, 0, 0, -0.1, -3.7, -20.7, -74.3, -527.8, -15210.4)
-  d2gdT2.500.ref <- c(0, 0, 0, 0, -1.0, -9.3, -36.8, -109.4, -26.3, -2043.5, -4063.1)
-  d2gdT2.1000.ref <- c(0, 0, 0, 0, -0.2, -4.0, -20.5, -58.4, -125.4, -241.8, -433.9, -628.0, -550.0, -265.2)
-  d2gdT2.4000.ref <- c(0, 0, 0, 0, 0, 0, 0, -0.6, -2.9, -5.9, -7.9, -8.2, -6.8, -3.9, 4.0, 9.5, 9.6, 5.9)
-  expect_equal(gfun.Psat$d2gdT2 * 1e8, d2gdT2.Psat.ref, tolerance=1e-5)
-  expect_equal(gfun.500$d2gdT2  * 1e8, d2gdT2.500.ref,  tolerance=1e-4)
-  expect_equal(gfun.1000$d2gdT2 * 1e8, d2gdT2.1000.ref, tolerance=1e-4)
-  expect_equal(gfun.4000$d2gdT2 * 1e8, d2gdT2.4000.ref, tolerance=1e-2)
-
-  # values from table 8 of Shock et al., 1992
-  dgdP.Psat.ref <- c(0, 0, 0, 0, 0.03, 0.36, 1.92, 12.27, 227.21)
-  dgdP.500.ref <- c(0, 0, 0, 0, 0.01, 0.53, 1.75, 5.69, 107.61, 704.88, 1110.20)
-  dgdP.1000.ref <- c(0, 0, 0, 0, 0, 0.03, 0.31, 1.50, 5.25, 15.53, 4.78, 101.39, 202.25, 313.90)
-  dgdP.4000.ref <- c(0, 0, 0, 0, 0, 0, 0, 0, 0.05, 0.18, 0.46, 0.91, 1.54, 2.34, 4.26, 6.12, 7.29, 7.47)
-  expect_equal(gfun.Psat$dgdP * 1e6, dgdP.Psat.ref, tolerance=1e-0)
-  expect_equal(gfun.500$dgdP  * 1e6, dgdP.500.ref,  tolerance=1e-0)
-  expect_equal(gfun.1000$dgdP * 1e6, dgdP.1000.ref, tolerance=1e-1)
-  expect_equal(gfun.4000$dgdP * 1e6, dgdP.4000.ref, tolerance=1e-3)
-})
-
-# reference
-
-# Shock, E. L., Oelkers, E. H., Johnson, J. W., Sverjensky, D. A. and Helgeson, H. C. (1992) 
-#   Calculation of the thermodynamic properties of aqueous species at high pressures and temperatures: 
-#   Effective electrostatic radii, dissociation constants and standard partial molal properties to 1000 degrees C and 5 kbar. 
-#   J. Chem. Soc. Faraday Trans. 88, 803--826. http://dx.doi.org/10.1039/FT9928800803

Deleted: pkg/CHNOSZ/inst/tests/test-equilibrate.R
===================================================================
--- pkg/CHNOSZ/inst/tests/test-equilibrate.R	2015-07-10 12:00:15 UTC (rev 91)
+++ pkg/CHNOSZ/inst/tests/test-equilibrate.R	2015-10-08 12:20:21 UTC (rev 92)
@@ -1,88 +0,0 @@
-context("equilibrate")
-
-# set up some simple systems
-# one acid
-basis("CHNOS+")
-species("acetic acid")
-aone <- suppressMessages(affinity())
-# acids
-species(c("formic acid", "formate", "acetate"))
-aacid <- suppressMessages(affinity())
-# acids plus a sulfur species
-species("H2S")
-aacidS <- suppressMessages(affinity())
-# proteins
-species(delete=TRUE)
-species(c("LYSC_CHICK", "MYG_PHYCA", "RNAS1_BOVIN", "CYC_BOVIN"))
-aprot <- suppressMessages(affinity())
-
-test_that("equilibrate() gives expected messages and errors for balance calculation", {
-  # the following error is triggered by equil.react, not equil.boltzmann
-  expect_error(equilibrate(aone), "at least two species needed")
-  expect_message(equilibrate(aacid), "coefficients are moles of CO2")
-  expect_message(equilibrate(aacid), "balancing coefficients are 2 1 1 2 ")
-  expect_message(equilibrate(aacid), "logarithm of total moles of CO2 is -2.221848")
-  expect_message(equilibrate(aacid, loga.balance=-3), "logarithm of total moles of CO2 \\(from loga.balance\\) is -3")
-  expect_error(equilibrate(aacid, balance="length"), "some species are not proteins")
-  expect_message(equilibrate(aacidS), "coefficients are unity")
-  expect_message(equilibrate(aacidS), "balancing coefficients are 1 1 1 1 1")
-  expect_message(equilibrate(aacidS), "logarithm of total moles of species is -2.301029")
-  expect_error(equilibrate(aacidS, balance="CO2"), "some species have no CO2 in the formation reaction")
-  expect_message(equilibrate(aprot), "coefficients are protein length")
-  expect_message(equilibrate(aprot), "balancing coefficients are 129 153 124 104")
-  expect_message(equilibrate(aprot), "logarithm of total protein length is -0.292429")
-  expect_message(equilibrate(aprot, normalize=TRUE), "using 'normalize' for molar formulas")
-})
-
-test_that("equilibrate() gives expected messages and errors for species selection", {
-  # an error if we select no species
-  expect_error(equilibrate(aacid, ispecies=numeric()), "the length of ispecies is zero")
-  # an error if all affinities are NA
-  aNA <- aacid
-  aNA$values[1:2] <- NA
-  expect_error(equilibrate(aNA, ispecies=1:2), "all species have NA affinities")
-  # a message if we select only certain of the species
-  expect_message(equilibrate(aacid, ispecies=1:2), "using 2 of 4 species")
-})
-
-test_that("equilibrate() keeps the same total loga.balance for normalize=TRUE or FALSE", {
-  # use the proteins
-  e.norm <- equilibrate(aprot, normalize=TRUE)
-  e <- equilibrate(aprot)
-  # the total activity of the balance in the two cases
-  sumact.balance.norm <- sum(10^unlist(e.norm$loga.equil)*e.norm$m.balance)
-  sumact.balance <- sum(10^unlist(e$loga.equil)*e$n.balance)
-  expect_equal(sumact.balance.norm, sumact.balance)
-})
-
-test_that("equilibrate() reproduces an example from the literature", {
-  # the reference values are the equilibrium logarithms of activities
-  # of sulfur species at logfO2=-30 from Seewald, 2001
-  # we name them here because S5O6-2 isn't on the plot at logfO2=-30, 
-  # and to get them in order
-  species.ref <- c("S3O6-2", "S2O6-2", "S2O4-2", "S3-2", "S2-2", "S2O3-2", "HSO3-", "SO2", "HSO4-", "H2S")
-  # these values were read from the plot using g3data (http://www.frantz.fi/software/g3data.php)
-  loga.ref <- c(-28.82, -24.70, -22.10, -14.19, -12.12, -11.86, -8.40, -7.40, -6.54, -1.95)
-  # set up the system - see ?diagram for an example showing the entire plot
-  basis("CHNOS+")
-  basis(c("pH", "O2"), c(5, -30))
-  # we include here all the species shown by Seewald, 2001
-  species(c("H2S", "S2-2", "S3-2", "S2O3-2", "S2O4-2", "S3O6-2", "S5O6-2", "S2O6-2", "HSO3-", "SO2", "HSO4-"))
-  a <- affinity(T=325, P=350)
-  # loga.balance=-2 signifies 10 mmolal total sulfur
-  e <- equilibrate(a, loga.balance=-2)
-  # get the calculated activities of the reference species
-  loga.equil <- unlist(e$loga.equil[match(species.ref, e$species$name)])
-  # the test... the tolerance may seem high, but consider that the reference values
-  # were read from a plot with 30 logfO2 units spanning 4 inches
-  expect_true(all(abs(loga.equil-loga.ref) < 0.36))
-})
-
-#}
-
-# references
-
-# Seewald, J. S. (2001) 
-#   Aqueous geochemistry of low molecular weight hydrocarbons at elevated temperatures and
-#   pressures: Constraints from mineral buffered laboratory experiments
-#   Geochim. Cosmochim. Acta 65, 1641--1664. http://dx.doi.org/10.1016/S0016-7037(01)00544-0

Deleted: pkg/CHNOSZ/inst/tests/test-findit.R
===================================================================
--- pkg/CHNOSZ/inst/tests/test-findit.R	2015-07-10 12:00:15 UTC (rev 91)
+++ pkg/CHNOSZ/inst/tests/test-findit.R	2015-10-08 12:20:21 UTC (rev 92)
@@ -1,42 +0,0 @@
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/chnosz -r 92


More information about the CHNOSZ-commits mailing list