tests/testthat/test_Methods_lnorm_x0.R

library(testthat)

testthat::local_edition(3)


test_that("Spaethe (1991) - Example 2", {
  skip_on_cran()
  use_multicore <- .Platform$OS.type != "windows" &&
    future::supportsMulticore()

  future_strategy <- if (use_multicore) {
    future::multicore
  } else {
    future::multisession
  }

  Force <- PROB_BASEVAR(
    Name = "Force", DistributionType = "gumbel", Package = "evd", Mean = 18, Sd = 2
  )

  # yield strength in kN
  fy <- PROB_BASEVAR(
    Name = "fy", DistributionType = "slnorm", Package = "TesiproV", Mean = 265000, Sd = 25000, x0 = 160000
  )

  # plastic moment of resistance in m³ - considered deterministic in this example
  W_pl <- 2.5e-4
  # length of cantilever beam in m - considered deterministic in this example
  l <- 2

  lsf_param <- SYS_LSF(vars = list(Force, fy), name = "Spaethe (1992) - Beispiel 2")
  lsf_param$func <- function(Force, fy) {
    return(W_pl * fy - l * Force)
  }
  lsf_param$check()

  machine_form <- PROB_MACHINE(name = "FORM", fCall = "FORM")
  machine_sorm <- PROB_MACHINE(name = "SORM", fCall = "SORM")
  machine_MCIS <- PROB_MACHINE("MCIS", "MC_IS",
    options = list(
      cov_user = 0.025,
      n_max = 200000, # statt Millionen
      n_batch = 20000,
      backend = "future",
      seed = 1234
    )
  )
  machine_SubSam <- PROB_MACHINE("MC_SubSam", "MC_SubSam")
  machine_MCCrude <- PROB_MACHINE("MC_Crude", "MC_CRUDE")


  ps_param <- SYS_PROB(
    sys_input = list(lsf_param),
    probMachines = list(machine_form, machine_sorm, machine_MCIS, machine_SubSam, machine_MCCrude)
  )

  with_test_future_plan(
    future_strategy,
    {
      expect_equal(
        as.integer(future::nbrOfWorkers()),
        4L
      )

      ps_param$runMachines()
    },
    workers = 4L
  )

  pf_expected <- 1.398e-4
  beta_expected <- -qnorm(pf_expected)

  rel_error <- c(1, 2, 3, 4, 5)
  for (i in rel_error) {
    rel_error[i] <- abs(ps_param$beta_single[i] - beta_expected) / beta_expected
    expect_lt(rel_error[i], 0.025) # Abweichung 2.5% erlaubt
  }
})


test_that("lnorm with x0 reduces to standard case when x0 = 0", {
  fy1 <- PROB_BASEVAR(Name = "fy", DistributionType = "slnorm", Package = "brms", Mean = 100, Sd = 10, x0 = 0)
  fy2 <- PROB_BASEVAR(Name = "fy", DistributionType = "lnorm", Mean = 100, Sd = 10)

  expect_equal(fy1$DistributionParameters[1], fy2$DistributionParameters[1])
  expect_equal(fy1$DistributionParameters[2], fy2$DistributionParameters[2])
  expect_equal(fy1$DistributionParameters[3], 0)
})

Try the TesiproV package in your browser

Any scripts or data that you put into this service are public.

TesiproV documentation built on Oct. 28, 2026, 5:13 p.m.