tests/testthat/test-Delta.R

context("Delta")

p1 = Process(a*t, a = 2)
p2 = Process(b*t, b = 1)
p3 = Process(c*sqrt(t), c = 0.5)
p4 = Process(d*log(t), d = 2)
s1 = p1 + p2
s2 = p3 + p4
d  = s1 - s2

test_that("A scenario - a scenario gives a delta", {
  expect_true(is(d, "DeltaCarbon"))
  expect_equal(names(d@scenarios), c("s1", "s2"))
})

test_that("geseval on a delta works", {
  v = geseval(d)
  t = 0:100

  expect_equal(names(v), c("t", "total.s1", "total.s2", "delta"))
  expect_equal(v$total.s1, 3*t)
  expect_equal(v$total.s2, 0.5*sqrt(t) + 2* log(t))
  expect_equal(v$delta, 3*t - (0.5*sqrt(t) + 2* log(t)))
})

test_that("geseval on a delta works if efficiency is set on a scenario", {
  efficiency(s2) <- 0.9
  d = s1 - s2
  v = geseval(d)
  t = 0:100

  expect_equal(names(v), c("t", "total.s1", "total.s2", "delta"))
  expect_equal(v$total.s1, 3*t)
  expect_equal(v$total.s2, 0.9*(0.5*sqrt(t) + 2*log(t)))
  expect_equal(v$delta, 3*t - 0.9*(0.5*sqrt(t) + 2* log(t)))
})
Jean-Romain/BilanGES documentation built on April 7, 2018, 12:15 p.m.