Skip to content

Commit 5a23268

Browse files
committed
Add Equatable conformance and check equality in test
1 parent 5c5a629 commit 5a23268

File tree

4 files changed

+61
-22
lines changed

4 files changed

+61
-22
lines changed

FirebaseVertexAI/Sources/FunctionCalling.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Foundation
1919
/// This `FunctionDeclaration` is a representation of a block of code that can be used as a ``Tool``
2020
/// by the model and executed by the client.
2121
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
22-
public struct FunctionDeclaration {
22+
public struct FunctionDeclaration: Equatable {
2323
/// The name of the function.
2424
let name: String
2525

FirebaseVertexAI/Sources/Types/Public/Schema.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,15 @@ extension Schema: Codable {
331331
case requiredProperties = "required"
332332
}
333333
}
334+
335+
// MARK: - Equatable Conformance
336+
337+
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
338+
extension Schema: Equatable {
339+
public static func == (lhs: Schema, rhs: Schema) -> Bool {
340+
return lhs.dataType == rhs.dataType && lhs.format == rhs.format
341+
&& lhs.description == rhs.description && lhs.nullable == rhs.nullable
342+
&& lhs.enumValues == rhs.enumValues && lhs.items == rhs.items
343+
&& lhs.properties == rhs.properties && lhs.requiredProperties == rhs.requiredProperties
344+
}
345+
}

FirebaseVertexAI/Tests/Unit/Snippets/FunctionCallingSnippets.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ final class FunctionCallingSnippets: XCTestCase {
2929
await FirebaseApp.deleteDefaultAppForSnippets()
3030
}
3131

32-
func testFunctionDeclaration_jsonString() throws {
33-
let json = """
34-
{
35-
"name": "getWeather",
36-
"description": "gets the weather for a requested city",
37-
"parameters": {
38-
"type": "OBJECT",
39-
"properties": {
40-
"city": {
41-
"type": "STRING"
42-
}
43-
}
44-
}
45-
}
46-
"""
47-
48-
let functionDeclaration = try FunctionDeclaration(jsonString: json)
49-
50-
print(functionDeclaration)
51-
}
52-
5332
func testFunctionCalling() async throws {
5433
// This function calls a hypothetical external API that returns
5534
// a collection of weather information for a given location on a given date.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import FirebaseVertexAI
16+
import XCTest
17+
18+
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
19+
final class FunctionDeclarationTests: XCTestCase {
20+
func testFunctionDeclaration_jsonString() throws {
21+
let json = """
22+
{
23+
"name": "getWeather",
24+
"description": "gets the weather for a requested city",
25+
"parameters": {
26+
"type": "OBJECT",
27+
"properties": {
28+
"city": {
29+
"type": "STRING",
30+
"nullable": false
31+
}
32+
},
33+
"nullable": false,
34+
"required": ["city"]
35+
}
36+
}
37+
"""
38+
let expectedFunctionDeclaration = FunctionDeclaration(
39+
name: "getWeather",
40+
description: "gets the weather for a requested city",
41+
parameters: ["city": .string()]
42+
)
43+
44+
let functionDeclaration = try FunctionDeclaration(jsonString: json)
45+
46+
XCTAssertEqual(functionDeclaration, expectedFunctionDeclaration)
47+
}
48+
}

0 commit comments

Comments
 (0)