`edge_completion(ctx, "Hello", n_predict = "invalid")` did not throw the expected error.

test_that("Text completion functions work correctly", {
ctx <- edge_load_model(model_path, n_ctx = 512)
result <- edge_completion(ctx, "Hello", n_predict = 5)
test_that("edge_completion with different prompts", {
result <- edge_completion(ctx, prompt, n_predict = 10)
test_that("edge_completion with different n_predict values", {
result1 <- edge_completion(ctx, prompt, n_predict = 1)
result2 <- edge_completion(ctx, prompt, n_predict = 10)
result3 <- edge_completion(ctx, prompt, n_predict = 20)
test_that("edge_completion with empty prompt", {
# Empty string should still generate text
result <- edge_completion(ctx, "", n_predict = 5)
test_that("edge_completion with long prompt", {
long_prompt <- paste(rep("This is a test sentence.", 10), collapse = " ")
result <- edge_completion(ctx, long_prompt, n_predict = 5)
# Test invalid prompts - these should error
# Test edge case n_predict values - implementation handles these gracefully
result1 <- edge_completion(ctx, "Hello", n_predict = -1)
result2 <- edge_completion(ctx, "Hello", n_predict = 0)
# Test invalid n_predict types - these should error
expect_error(edge_completion(ctx, "Hello", n_predict = "invalid"))
expect_error(edge_completion(ctx, "Hello", n_predict = NULL))
# Test edge case temperature values - implementation handles these gracefully
result3 <- edge_completion(ctx, "Hello", temperature = -0.1)
# Test invalid temperature types - these should error
expect_error(edge_completion(ctx, "Hello", temperature = "invalid"))
expect_error(edge_completion(ctx, "Hello", temperature = NULL))
# Test edge case top_p values - implementation handles these gracefully
result4 <- edge_completion(ctx, "Hello", top_p = -0.1)
result5 <- edge_completion(ctx, "Hello", top_p = 1.1)  # May be clamped to 1.0
# Test invalid top_p types - these should error
expect_error(edge_completion(ctx, "Hello", top_p = "invalid"))
expect_error(edge_completion(ctx, "Hello", top_p = NULL))
test_that("edge_completion with special characters", {
result <- edge_completion(ctx, prompt, n_predict = 5)
test_that("edge_completion with different temperature settings", {
result_low <- edge_completion(ctx, prompt, n_predict = 10, temperature = 0.1)
result_high <- edge_completion(ctx, prompt, n_predict = 10, temperature = 1.0)
# Very high temperature (maximum randomness)
result_max <- edge_completion(ctx, prompt, n_predict = 10, temperature = 2.0)
test_that("edge_completion with different top_p settings", {
# Low top_p (nucleus sampling with small nucleus)
result_low <- edge_completion(ctx, prompt, n_predict = 5, top_p = 0.1)
result_med <- edge_completion(ctx, prompt, n_predict = 5, top_p = 0.5)
# High top_p (almost no nucleus filtering)
result_high <- edge_completion(ctx, prompt, n_predict = 5, top_p = 0.95)
result_large <- edge_completion(ctx, "Hello", n_predict = 500)
result_zero_temp <- edge_completion(ctx, "Test", n_predict = 5, temperature = 0.001)
result_low_top_p <- edge_completion(ctx, "Test", n_predict = 5, top_p = 0.01)
result_high_top_p <- edge_completion(ctx, "Test", n_predict = 5, top_p = 0.99)
test_that("edge_completion with Unicode and international text", {
# Some models may not handle Unicode well - accept any error message
long_prompt <- paste(rep("This is a test sentence with multiple words. ", 50), collapse = "")
# May fail if prompt exceeds context window - accept any error message
# Repeated generations (memory leak test)
result <- edge_completion(ctx, "Quick test", n_predict = 3)
# Test that the same prompt produces consistent results (within reason)
results <- replicate(3, edge_completion(ctx, prompt, n_predict = 10, temperature = 0.1))
# All should be strings starting with the prompt
# With low temperature, results should be more similar
# (though not necessarily identical due to sampling)
expect_true(length(unique(results)) <= 3)  # At most 3 different results
# Test that multiple completions work in sequence
test_that("Sequential completions work correctly", {
prompts <- c("Hello", "World", "Test", "Final")
result <- edge_completion(ctx, prompt, n_predict = 3)
skip("No test model available for text completion tests")
edge_completion(NULL, "Hello", n_predict = 5)
edge_completion("invalid", "Hello", n_predict = 5)
edge_completion(123, "Hello", n_predict = 5)
edge_completion(list(), "Hello", n_predict = 5)
ctx <- edge_load_model(model_path, n_ctx = 256)
# Note: In current implementation, freed contexts may still be valid
# This is acceptable behavior for this R package
# Test boundary conditions and edge cases
result_min <- edge_completion(ctx, "Hello", n_predict = 1)
medium_prompt <- "This is a medium length prompt with several words"
long_prompt <- paste(rep("word", 100), collapse = " ")
result_short <- edge_completion(ctx, short_prompt, n_predict = 5)
result_medium <- edge_completion(ctx, medium_prompt, n_predict = 5)
result_long <- edge_completion(ctx, long_prompt, n_predict = 5)
skip("No test model available for boundary condition tests")