library(testthat)
library(peticontrast)

test_that("apply_peticontrast works correctly", {
  # Generate dummy data
  df <- data.frame(Negyedev = factor(c("Q1", "Q2", "Q3", "Q4"), levels = c("Q1", "Q2", "Q3", "Q4")))
  
  # Apply function
  df_result <- apply_peticontrast(df, "Negyedev")
  mat <- contrasts(df_result$Negyedev)
  
  # a) Check if matrix has 3 columns (k-1 where k=4)
  expect_equal(ncol(mat), 3)
  
  # b) Check if the last row (Q4) is exclusively -1
  expect_true(all(mat["Q4", ] == -1))
  
  # c) Check if column names follow the _vs_trend schema
  expect_equal(colnames(mat), c("Q1_vs_trend", "Q2_vs_trend", "Q3_vs_trend"))
  
  # Additional checks
  expect_equal(nrow(mat), 4)
  expect_equal(mat["Q1", "Q1_vs_trend"], 1)
  expect_equal(mat["Q1", "Q2_vs_trend"], 0)
})
