From d018ad404f7646a54f2360b8abe23e7ea9813739 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 27 Aug 2025 14:34:37 +0000 Subject: [PATCH] This commit adds a new test to `ToolTests.kt` to verify the handling of enum parameters in tool function schemas. The new test, `testTools_enumParameter`, defines a function with a parameter that is constrained to a list of enum values. It then verifies that the model correctly calls this function with one of the allowed enum values when prompted. This increases the test coverage of the tool functionality in the Firebase AI library. --- .../com/google/firebase/ai/ToolTests.kt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/firebase-ai/src/androidTest/kotlin/com/google/firebase/ai/ToolTests.kt b/firebase-ai/src/androidTest/kotlin/com/google/firebase/ai/ToolTests.kt index 5aef0f429c6..cf70f79e045 100644 --- a/firebase-ai/src/androidTest/kotlin/com/google/firebase/ai/ToolTests.kt +++ b/firebase-ai/src/androidTest/kotlin/com/google/firebase/ai/ToolTests.kt @@ -293,6 +293,33 @@ class ToolTests { } } + @Test + fun testTools_enumParameter() { + val enumValues = listOf("red", "green", "blue") + val schema = + mapOf( + Pair("color", Schema.enumeration(enumValues, "A color from the provided list")) + ) + val model = + setupModel( + FunctionDeclaration( + name = "getHexCode", + description = "returns the hex code for a given color", + parameters = schema + ), + ) + runBlocking { + val response = model.generateContent("what is the hex code for green?") + validator.validateResponse((response)) + assert(response.functionCalls.size == 1) + val call = response.functionCalls[0] + assert(call.name == "getHexCode") + validateSchema(schema, call.args) + val color = call.args["color"]!!.jsonPrimitive.content + assert(color in enumValues) + } + } + companion object { @JvmStatic fun setupModel(vararg functions: FunctionDeclaration): GenerativeModel {