Skip to content

Commit 73eac1a

Browse files
committed
Move inlineDataParts tests to new GenerateContentResponseTests file
1 parent 7ffdacb commit 73eac1a

File tree

2 files changed

+109
-91
lines changed

2 files changed

+109
-91
lines changed

FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,97 +1538,6 @@ final class GenerativeModelTests: XCTestCase {
15381538
XCTAssertEqual(response.totalTokens, 6)
15391539
}
15401540

1541-
// MARK: - GenerateContentResponse Computed Properties
1542-
1543-
func testGenerateContentResponse_inlineDataParts_success() throws {
1544-
// 1. Create mock parts
1545-
let imageData = Data("sample image data".utf8) // Placeholder data
1546-
let inlineDataPart = InlineDataPart(data: imageData, mimeType: "image/png")
1547-
let textPart = TextPart("This is the text part.")
1548-
1549-
// 2. Create ModelContent
1550-
let modelContent = ModelContent(parts: [textPart, inlineDataPart]) // Mixed parts
1551-
1552-
// 3. Create Candidate
1553-
let candidate = Candidate(
1554-
content: modelContent,
1555-
safetyRatings: [], // Assuming negligible for this test
1556-
finishReason: .stop,
1557-
citationMetadata: nil
1558-
)
1559-
1560-
// 4. Create GenerateContentResponse
1561-
let response = GenerateContentResponse(candidates: [candidate])
1562-
1563-
// 5. Assertions for inlineDataParts
1564-
let inlineParts = response.inlineDataParts
1565-
XCTAssertFalse(inlineParts.isEmpty, "inlineDataParts should not be empty.")
1566-
XCTAssertEqual(inlineParts.count, 1, "There should be exactly one InlineDataPart.")
1567-
1568-
let firstInlinePart = try XCTUnwrap(inlineParts.first, "Could not get the first inline part.")
1569-
XCTAssertEqual(firstInlinePart.mimeType, "image/png", "MimeType should match.")
1570-
XCTAssertFalse(firstInlinePart.data.isEmpty, "Inline data should not be empty.")
1571-
XCTAssertEqual(firstInlinePart.data, imageData) // Verify data content
1572-
1573-
// 6. Assertion for text (ensure other properties still work)
1574-
XCTAssertEqual(response.text, "This is the text part.")
1575-
1576-
// 7. Assertion for function calls (ensure it's empty)
1577-
XCTAssertTrue(response.functionCalls.isEmpty, "functionCalls should be empty.")
1578-
}
1579-
1580-
func testGenerateContentResponse_inlineDataParts_noInlineData() throws {
1581-
// 1. Create mock parts (only text)
1582-
let textPart = TextPart("This is the text part.")
1583-
let funcCallPart = FunctionCallPart(name: "testFunc", args: [:]) // Add another part type
1584-
1585-
// 2. Create ModelContent
1586-
let modelContent = ModelContent(parts: [textPart, funcCallPart])
1587-
1588-
// 3. Create Candidate
1589-
let candidate = Candidate(
1590-
content: modelContent,
1591-
safetyRatings: [],
1592-
finishReason: .stop,
1593-
citationMetadata: nil
1594-
)
1595-
1596-
// 4. Create GenerateContentResponse
1597-
let response = GenerateContentResponse(candidates: [candidate])
1598-
1599-
// 5. Assertions for inlineDataParts
1600-
let inlineParts = response.inlineDataParts
1601-
XCTAssertTrue(inlineParts.isEmpty, "inlineDataParts should be empty.")
1602-
1603-
// 6. Assertion for text
1604-
XCTAssertEqual(response.text, "This is the text part.")
1605-
1606-
// 7. Assertion for function calls
1607-
XCTAssertEqual(response.functionCalls.count, 1)
1608-
XCTAssertEqual(response.functionCalls.first?.name, "testFunc")
1609-
}
1610-
1611-
func testGenerateContentResponse_inlineDataParts_noCandidates() throws {
1612-
// 1. Create GenerateContentResponse with no candidates
1613-
let response = GenerateContentResponse(candidates: [])
1614-
1615-
// 2. Assertions for inlineDataParts
1616-
let inlineParts = response.inlineDataParts
1617-
XCTAssertTrue(
1618-
inlineParts.isEmpty,
1619-
"inlineDataParts should be empty when there are no candidates."
1620-
)
1621-
1622-
// 3. Assertion for text
1623-
XCTAssertNil(response.text, "Text should be nil when there are no candidates.")
1624-
1625-
// 4. Assertion for function calls
1626-
XCTAssertTrue(
1627-
response.functionCalls.isEmpty,
1628-
"functionCalls should be empty when there are no candidates."
1629-
)
1630-
}
1631-
16321541
// MARK: - Helpers
16331542

16341543
private func testFirebaseInfo(appCheck: AppCheckInterop? = nil,
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright 2025 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 GenerateContentResponseTests: XCTestCase {
20+
// MARK: - GenerateContentResponse Computed Properties
21+
22+
func testGenerateContentResponse_inlineDataParts_success() throws {
23+
let imageData = Data("sample image data".utf8)
24+
let inlineDataPart = InlineDataPart(data: imageData, mimeType: "image/png")
25+
let textPart = TextPart("This is the text part.")
26+
let modelContent = ModelContent(parts: [textPart, inlineDataPart])
27+
let candidate = Candidate(
28+
content: modelContent,
29+
safetyRatings: [],
30+
finishReason: nil,
31+
citationMetadata: nil
32+
)
33+
let response = GenerateContentResponse(candidates: [candidate])
34+
35+
let inlineParts = response.inlineDataParts
36+
37+
XCTAssertFalse(inlineParts.isEmpty, "inlineDataParts should not be empty.")
38+
XCTAssertEqual(inlineParts.count, 1, "There should be exactly one InlineDataPart.")
39+
let firstInlinePart = try XCTUnwrap(inlineParts.first, "Could not get the first inline part.")
40+
XCTAssertEqual(firstInlinePart.mimeType, inlineDataPart.mimeType, "MimeType should match.")
41+
XCTAssertEqual(firstInlinePart.data, imageData)
42+
XCTAssertEqual(response.text, textPart.text)
43+
XCTAssertTrue(response.functionCalls.isEmpty, "functionCalls should be empty.")
44+
}
45+
46+
func testGenerateContentResponse_inlineDataParts_multipleInlineDataParts_success() throws {
47+
let imageData1 = Data("sample image data 1".utf8)
48+
let inlineDataPart1 = InlineDataPart(data: imageData1, mimeType: "image/png")
49+
let imageData2 = Data("sample image data 2".utf8)
50+
let inlineDataPart2 = InlineDataPart(data: imageData2, mimeType: "image/jpeg")
51+
let modelContent = ModelContent(parts: [inlineDataPart1, inlineDataPart2])
52+
let candidate = Candidate(
53+
content: modelContent,
54+
safetyRatings: [],
55+
finishReason: nil,
56+
citationMetadata: nil
57+
)
58+
let response = GenerateContentResponse(candidates: [candidate])
59+
60+
let inlineParts = response.inlineDataParts
61+
62+
XCTAssertFalse(inlineParts.isEmpty, "inlineDataParts should not be empty.")
63+
XCTAssertEqual(inlineParts.count, 2, "There should be exactly two InlineDataParts.")
64+
let firstInlinePart = try XCTUnwrap(inlineParts.first, "Could not get the first inline part.")
65+
XCTAssertEqual(firstInlinePart.mimeType, inlineDataPart1.mimeType, "MimeType should match.")
66+
XCTAssertEqual(firstInlinePart.data, imageData1)
67+
let secondInlinePart = try XCTUnwrap(inlineParts.last, "Could not get the second inline part.")
68+
XCTAssertEqual(secondInlinePart.mimeType, inlineDataPart2.mimeType, "MimeType should match.")
69+
XCTAssertEqual(secondInlinePart.data, imageData2)
70+
XCTAssertNil(response.text)
71+
XCTAssertTrue(response.functionCalls.isEmpty, "functionCalls should be empty.")
72+
}
73+
74+
func testGenerateContentResponse_inlineDataParts_noInlineData() throws {
75+
let textPart = TextPart("This is the text part.")
76+
let functionCallPart = FunctionCallPart(name: "testFunc", args: [:])
77+
let modelContent = ModelContent(parts: [textPart, functionCallPart])
78+
let candidate = Candidate(
79+
content: modelContent,
80+
safetyRatings: [],
81+
finishReason: nil,
82+
citationMetadata: nil
83+
)
84+
let response = GenerateContentResponse(candidates: [candidate])
85+
86+
let inlineParts = response.inlineDataParts
87+
88+
XCTAssertTrue(inlineParts.isEmpty, "inlineDataParts should be empty.")
89+
XCTAssertEqual(response.text, "This is the text part.")
90+
XCTAssertEqual(response.functionCalls.count, 1)
91+
XCTAssertEqual(response.functionCalls.first?.name, "testFunc")
92+
}
93+
94+
func testGenerateContentResponse_inlineDataParts_noCandidates() throws {
95+
let response = GenerateContentResponse(candidates: [])
96+
97+
let inlineParts = response.inlineDataParts
98+
99+
XCTAssertTrue(
100+
inlineParts.isEmpty,
101+
"inlineDataParts should be empty when there are no candidates."
102+
)
103+
XCTAssertNil(response.text, "Text should be nil when there are no candidates.")
104+
XCTAssertTrue(
105+
response.functionCalls.isEmpty,
106+
"functionCalls should be empty when there are no candidates."
107+
)
108+
}
109+
}

0 commit comments

Comments
 (0)