test_that("read_junior_pam_data 2026_04_22_junior_pam.csv - default", {
  test_data_file <- testthat::test_path("data", "junior_pam_data", "2026_04_22_junior_pam.csv")
  data <- read_junior_pam_data(test_data_file)

  par <- data$par
  expect_equal(par[1], 0)
  expect_equal(par[2], 50)
  expect_equal(par[3], 90)
  expect_equal(par[4], 130)
  expect_equal(par[5], 180)
  expect_equal(par[6], 250)
  expect_equal(par[7], 380)
  expect_equal(par[8], 570)
  expect_equal(par[9], 840)
  expect_equal(par[10], 1250)
  expect_equal(par[11], 1640)
  expect_equal(par[12], 2300)
  expect_equal(par[13], 3000)

  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_)
  expect_equal(yield_1[11], NA_real_)
  expect_equal(yield_1[12], NA_real_)
  expect_equal(yield_1[13], NA_real_)

  yield_2 <- data$yield_2
  expect_equal(yield_2[1], 0.743)
  expect_equal(yield_2[2], 0.4310)
  expect_equal(yield_2[3], 0.3280)
  expect_equal(yield_2[4], 0.3830)
  expect_equal(yield_2[5], 0.414)
  expect_equal(yield_2[6], 0.423)
  expect_equal(yield_2[7], 0.359)
  expect_equal(yield_2[8], 0.295)
  expect_equal(yield_2[9], 0.213)
  expect_equal(yield_2[10], 0.146)
  expect_equal(yield_2[11], 0.1000)
  expect_equal(yield_2[12], 0.084)
  expect_equal(yield_2[13], 0.066)

  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_)
  expect_equal(etr_1[11], NA_real_)
  expect_equal(etr_1[12], NA_real_)
  expect_equal(etr_1[13], NA_real_)

  etr_2 <- data$etr_2
  expect_equal(etr_2[1], 0)
  expect_equal(etr_2[2], 9.0510)
  expect_equal(etr_2[3], 12.3984)
  expect_equal(etr_2[4], 20.9118)
  expect_equal(etr_2[5], 31.2984)
  expect_equal(etr_2[6], 44.4150)
  expect_equal(etr_2[7], 57.2964)
  expect_equal(etr_2[8], 70.6230)
  expect_equal(etr_2[9], 75.1464)
  expect_equal(etr_2[10], 76.6500)
  expect_equal(etr_2[11], 68.8800)
  expect_equal(etr_2[12], 81.1440)
  expect_equal(etr_2[13], 83.1600)
})

test_that("read_junior_pam_data 2026_04_22_junior_pam.csv - etr_factor 0.5", {
  test_data_file <- testthat::test_path("data", "junior_pam_data", "2026_04_22_junior_pam.csv")
  data <- read_junior_pam_data(test_data_file, etr_factor = 0.5)

  par <- data$par
  expect_equal(par[1], 0)
  expect_equal(par[2], 50)
  expect_equal(par[3], 90)
  expect_equal(par[4], 130)
  expect_equal(par[5], 180)
  expect_equal(par[6], 250)
  expect_equal(par[7], 380)
  expect_equal(par[8], 570)
  expect_equal(par[9], 840)
  expect_equal(par[10], 1250)
  expect_equal(par[11], 1640)
  expect_equal(par[12], 2300)
  expect_equal(par[13], 3000)

  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_)
  expect_equal(yield_1[11], NA_real_)
  expect_equal(yield_1[12], NA_real_)
  expect_equal(yield_1[13], NA_real_)

  yield_2 <- data$yield_2
  expect_equal(yield_2[1], 0.743)
  expect_equal(yield_2[2], 0.4310)
  expect_equal(yield_2[3], 0.3280)
  expect_equal(yield_2[4], 0.3830)
  expect_equal(yield_2[5], 0.414)
  expect_equal(yield_2[6], 0.423)
  expect_equal(yield_2[7], 0.359)
  expect_equal(yield_2[8], 0.295)
  expect_equal(yield_2[9], 0.213)
  expect_equal(yield_2[10], 0.146)
  expect_equal(yield_2[11], 0.1000)
  expect_equal(yield_2[12], 0.084)
  expect_equal(yield_2[13], 0.066)

  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_)
  expect_equal(etr_1[11], NA_real_)
  expect_equal(etr_1[12], NA_real_)
  expect_equal(etr_1[13], NA_real_)

  etr_2 <- data$etr_2
  expect_equal(etr_2[1], 0)
  expect_equal(etr_2[2], 5.3875)
  expect_equal(etr_2[3], 7.3800)
  expect_equal(etr_2[4], 12.4475)
  expect_equal(etr_2[5], 18.6300)
  expect_equal(etr_2[6], 26.4375)
  expect_equal(etr_2[7], 34.1050)
  expect_equal(etr_2[8], 42.0375)
  expect_equal(etr_2[9], 44.7300)
  expect_equal(etr_2[10], 45.6250)
  expect_equal(etr_2[11], 41.0000)
  expect_equal(etr_2[12], 48.3000)
  expect_equal(etr_2[13], 49.5000)
})

test_that("read_junior_pam_data 2026_04_22_junior_pam.csv - fraction_photosystem > 1", {
  test_data_file <- testthat::test_path("data", "junior_pam_data", "2026_04_22_junior_pam.csv")
  expect_error(read_junior_pam_data(test_data_file, fraction_photosystem_I = 0.9, fraction_photosystem_II = 0.2))
})

test_that("read_junior_pam_data 2026_04_22_junior_pam.csv - fraction_photosystem_I = 0.2, fraction_photosystem_II = 0.8", {
  test_data_file <- testthat::test_path("data", "junior_pam_data", "2026_04_22_junior_pam.csv")
  data <- read_junior_pam_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], 50)
  expect_equal(par[3], 90)
  expect_equal(par[4], 130)
  expect_equal(par[5], 180)
  expect_equal(par[6], 250)
  expect_equal(par[7], 380)
  expect_equal(par[8], 570)
  expect_equal(par[9], 840)
  expect_equal(par[10], 1250)
  expect_equal(par[11], 1640)
  expect_equal(par[12], 2300)
  expect_equal(par[13], 3000)

  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_)
  expect_equal(yield_1[11], NA_real_)
  expect_equal(yield_1[12], NA_real_)
  expect_equal(yield_1[13], NA_real_)

  yield_2 <- data$yield_2
  expect_equal(yield_2[1], 0.743)
  expect_equal(yield_2[2], 0.4310)
  expect_equal(yield_2[3], 0.3280)
  expect_equal(yield_2[4], 0.3830)
  expect_equal(yield_2[5], 0.414)
  expect_equal(yield_2[6], 0.423)
  expect_equal(yield_2[7], 0.359)
  expect_equal(yield_2[8], 0.295)
  expect_equal(yield_2[9], 0.213)
  expect_equal(yield_2[10], 0.146)
  expect_equal(yield_2[11], 0.1000)
  expect_equal(yield_2[12], 0.084)
  expect_equal(yield_2[13], 0.066)

  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_)
  expect_equal(etr_1[11], NA_real_)
  expect_equal(etr_1[12], NA_real_)
  expect_equal(etr_1[13], NA_real_)

  etr_2 <- data$etr_2
  expect_equal(etr_2[1], 0)
  expect_equal(etr_2[2], 14.48160)
  expect_equal(etr_2[3], 19.83744)
  expect_equal(etr_2[4], 33.45888)
  expect_equal(etr_2[5], 50.07744)
  expect_equal(etr_2[6], 71.06400)
  expect_equal(etr_2[7], 91.67424)
  expect_equal(etr_2[8], 112.99680)
  expect_equal(etr_2[9], 120.23424)
  expect_equal(etr_2[10], 122.64000)
  expect_equal(etr_2[11], 110.20800)
  expect_equal(etr_2[12], 129.83040)
  expect_equal(etr_2[13], 133.05600)
})
