test_that("read_pam_2500_data 20260422_pam_2500.CSV - default", {
  test_data_file <- testthat::test_path("data", "pam_2500_data", "20260422_pam_2500.CSV")
  data <- read_pam_2500_data(test_data_file)

  par <- data$par
  expect_equal(par[1], 0)
  expect_equal(par[2], 7)
  expect_equal(par[3], 36)
  expect_equal(par[4], 106)
  expect_equal(par[5], 203)
  expect_equal(par[6], 368)
  expect_equal(par[7], 624)
  expect_equal(par[8], 986)
  expect_equal(par[9], 1391)
  expect_equal(par[10], 2020)

  yield_1 <- data$yield_1
  expect_equal(yield_1[1], NA_real_)
  expect_equal(yield_1[2], NA_real_)
  expect_equal(yield_1[3], NA_real_)
  expect_equal(yield_1[4], NA_real_)
  expect_equal(yield_1[5], NA_real_)
  expect_equal(yield_1[6], NA_real_)
  expect_equal(yield_1[7], NA_real_)
  expect_equal(yield_1[8], NA_real_)
  expect_equal(yield_1[9], NA_real_)
  expect_equal(yield_1[10], NA_real_)

  yield_2 <- data$yield_2
  expect_equal(yield_2[1], 0.802)
  expect_equal(yield_2[2], 0.466)
  expect_equal(yield_2[3], 0.432)
  expect_equal(yield_2[4], 0.405)
  expect_equal(yield_2[5], 0.338)
  expect_equal(yield_2[6], 0.251)
  expect_equal(yield_2[7], 0.178)
  expect_equal(yield_2[8], 0.126)
  expect_equal(yield_2[9], 0.097)
  expect_equal(yield_2[10], 0.069)

  etr_1 <- data$etr_1
  expect_equal(etr_1[1], NA_real_)
  expect_equal(etr_1[2], NA_real_)
  expect_equal(etr_1[3], NA_real_)
  expect_equal(etr_1[4], NA_real_)
  expect_equal(etr_1[5], NA_real_)
  expect_equal(etr_1[6], NA_real_)
  expect_equal(etr_1[7], NA_real_)
  expect_equal(etr_1[8], NA_real_)
  expect_equal(etr_1[9], NA_real_)
  expect_equal(etr_1[10], NA_real_)

  etr_2 <- data$etr_2
  expect_equal(etr_2[1], 0)
  expect_equal(etr_2[2], 1.37004)
  expect_equal(etr_2[3], 6.53184)
  expect_equal(etr_2[4], 18.03060)
  expect_equal(etr_2[5], 28.81788)
  expect_equal(etr_2[6], 38.79456)
  expect_equal(etr_2[7], 46.65024)
  expect_equal(etr_2[8], 52.17912)
  expect_equal(etr_2[9], 56.66934)
  expect_equal(etr_2[10], 58.53960)
})

test_that("read_pam_2500_data 20260422_pam_2500.CSV - etr-factor 0.5", {
  test_data_file <- testthat::test_path("data", "pam_2500_data", "20260422_pam_2500.CSV")
  data <- read_pam_2500_data(test_data_file, etr_factor = 0.5)

  par <- data$par
   expect_equal(par[1], 0)
  expect_equal(par[2], 7)
  expect_equal(par[3], 36)
  expect_equal(par[4], 106)
  expect_equal(par[5], 203)
  expect_equal(par[6], 368)
  expect_equal(par[7], 624)
  expect_equal(par[8], 986)
  expect_equal(par[9], 1391)
  expect_equal(par[10], 2020)

  yield_1 <- data$yield_1
  expect_equal(yield_1[1], NA_real_)
  expect_equal(yield_1[2], NA_real_)
  expect_equal(yield_1[3], NA_real_)
  expect_equal(yield_1[4], NA_real_)
  expect_equal(yield_1[5], NA_real_)
  expect_equal(yield_1[6], NA_real_)
  expect_equal(yield_1[7], NA_real_)
  expect_equal(yield_1[8], NA_real_)
  expect_equal(yield_1[9], NA_real_)
  expect_equal(yield_1[10], NA_real_)

  yield_2 <- data$yield_2
  expect_equal(yield_2[1], 0.802)
  expect_equal(yield_2[2], 0.466)
  expect_equal(yield_2[3], 0.432)
  expect_equal(yield_2[4], 0.405)
  expect_equal(yield_2[5], 0.338)
  expect_equal(yield_2[6], 0.251)
  expect_equal(yield_2[7], 0.178)
  expect_equal(yield_2[8], 0.126)
  expect_equal(yield_2[9], 0.097)
  expect_equal(yield_2[10], 0.069)

  etr_1 <- data$etr_1
  expect_equal(etr_1[1], NA_real_)
  expect_equal(etr_1[2], NA_real_)
  expect_equal(etr_1[3], NA_real_)
  expect_equal(etr_1[4], NA_real_)
  expect_equal(etr_1[5], NA_real_)
  expect_equal(etr_1[6], NA_real_)
  expect_equal(etr_1[7], NA_real_)
  expect_equal(etr_1[8], NA_real_)
  expect_equal(etr_1[9], NA_real_)
  expect_equal(etr_1[10], NA_real_)

  etr_2 <- data$etr_2
  expect_equal(etr_2[1], 0)
  expect_equal(etr_2[2], 0.81550)
  expect_equal(etr_2[3], 3.88800)
  expect_equal(etr_2[4], 10.73250)
  expect_equal(etr_2[5], 17.15350)
  expect_equal(etr_2[6], 23.09200)
  expect_equal(etr_2[7], 27.76800)
  expect_equal(etr_2[8], 31.05900)
  expect_equal(etr_2[9], 33.73175)
  expect_equal(etr_2[10], 34.84500)
})

test_that("read_pam_2500_data 20260422_pam_2500.CSV - fraction_photosystem_I = 0.2, fraction_photosystem_II = 0.8", {
  test_data_file <- testthat::test_path("data", "pam_2500_data", "20260422_pam_2500.CSV")
  expect_error(read_pam_2500_data(test_data_file, fraction_photosystem_I = 0.9, fraction_photosystem_II = 0.2))
})

test_that("read_pam_2500_data 20260422_pam_2500.CSV - fraction_photosystem_I = 0.2, fraction_photosystem_II = 0.8", {
  test_data_file <- testthat::test_path("data", "pam_2500_data", "20260422_pam_2500.CSV")
  data <- read_pam_2500_data(test_data_file, fraction_photosystem_I = 0.2, fraction_photosystem_II = 0.8)

  par <- data$par
  expect_equal(par[1], 0)
  expect_equal(par[2], 7)
  expect_equal(par[3], 36)
  expect_equal(par[4], 106)
  expect_equal(par[5], 203)
  expect_equal(par[6], 368)
  expect_equal(par[7], 624)
  expect_equal(par[8], 986)
  expect_equal(par[9], 1391)
  expect_equal(par[10], 2020)

  yield_1 <- data$yield_1
  expect_equal(yield_1[1], NA_real_)
  expect_equal(yield_1[2], NA_real_)
  expect_equal(yield_1[3], NA_real_)
  expect_equal(yield_1[4], NA_real_)
  expect_equal(yield_1[5], NA_real_)
  expect_equal(yield_1[6], NA_real_)
  expect_equal(yield_1[7], NA_real_)
  expect_equal(yield_1[8], NA_real_)
  expect_equal(yield_1[9], NA_real_)
  expect_equal(yield_1[10], NA_real_)

  yield_2 <- data$yield_2
  expect_equal(yield_2[1], 0.802)
  expect_equal(yield_2[2], 0.466)
  expect_equal(yield_2[3], 0.432)
  expect_equal(yield_2[4], 0.405)
  expect_equal(yield_2[5], 0.338)
  expect_equal(yield_2[6], 0.251)
  expect_equal(yield_2[7], 0.178)
  expect_equal(yield_2[8], 0.126)
  expect_equal(yield_2[9], 0.097)
  expect_equal(yield_2[10], 0.069)

  etr_1 <- data$etr_1
  expect_equal(etr_1[1], NA_real_)
  expect_equal(etr_1[2], NA_real_)
  expect_equal(etr_1[3], NA_real_)
  expect_equal(etr_1[4], NA_real_)
  expect_equal(etr_1[5], NA_real_)
  expect_equal(etr_1[6], NA_real_)
  expect_equal(etr_1[7], NA_real_)
  expect_equal(etr_1[8], NA_real_)
  expect_equal(etr_1[9], NA_real_)
  expect_equal(etr_1[10], NA_real_)

  etr_2 <- data$etr_2
  expect_equal(etr_2[1], 0)
  expect_equal(etr_2[2], 2.192064)
  expect_equal(etr_2[3], 10.450944)
  expect_equal(etr_2[4], 28.848960)
  expect_equal(etr_2[5], 46.108608)
  expect_equal(etr_2[6], 62.071296)
  expect_equal(etr_2[7], 74.640384)
  expect_equal(etr_2[8], 83.486592)
  expect_equal(etr_2[9], 90.670944)
  expect_equal(etr_2[10], 93.663360)
})
