|
12 | 12 | // See the License for the specific language governing permissions and
|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 |
| -import FirebaseAI |
| 15 | +@testable import FirebaseAI |
16 | 16 | import XCTest
|
17 | 17 |
|
18 | 18 | @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
|
@@ -157,4 +157,40 @@ final class GenerateContentResponseTests: XCTestCase {
|
157 | 157 | XCTAssertFalse(textPart.isThought)
|
158 | 158 | XCTAssertEqual(candidate.finishReason, .stop)
|
159 | 159 | }
|
| 160 | + |
| 161 | + // MARK: - Candidate.isEmpty |
| 162 | + |
| 163 | + func testCandidateIsEmpty_allEmpty_isTrue() throws { |
| 164 | + let candidate = Candidate( |
| 165 | + content: ModelContent(parts: []), |
| 166 | + safetyRatings: [], |
| 167 | + finishReason: nil, |
| 168 | + citationMetadata: nil, |
| 169 | + groundingMetadata: nil, |
| 170 | + urlContextMetadata: nil |
| 171 | + ) |
| 172 | + |
| 173 | + XCTAssertTrue(candidate.isEmpty, "A candidate with no content should be empty.") |
| 174 | + } |
| 175 | + |
| 176 | + func testCandidateIsEmpty_withURLContextMetadata_isFalse() throws { |
| 177 | + let urlMetadata = try URLMetadata( |
| 178 | + retrievedURL: XCTUnwrap(URL(string: "https://google.com")), |
| 179 | + retrievalStatus: .success |
| 180 | + ) |
| 181 | + let urlContextMetadata = URLContextMetadata(urlMetadata: [urlMetadata]) |
| 182 | + let candidate = Candidate( |
| 183 | + content: ModelContent(parts: []), |
| 184 | + safetyRatings: [], |
| 185 | + finishReason: nil, |
| 186 | + citationMetadata: nil, |
| 187 | + groundingMetadata: nil, |
| 188 | + urlContextMetadata: urlContextMetadata |
| 189 | + ) |
| 190 | + |
| 191 | + XCTAssertFalse( |
| 192 | + candidate.isEmpty, |
| 193 | + "A candidate with only `urlContextMetadata` should not be empty." |
| 194 | + ) |
| 195 | + } |
160 | 196 | }
|
0 commit comments