forked from langchain4j/langchain4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
langchain4j-core/src/test/java/dev/langchain4j/model/output/ResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package dev.langchain4j.model.output; | ||
|
||
import org.assertj.core.api.WithAssertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ResponseTest implements WithAssertions { | ||
@Test | ||
public void test_methods() { | ||
{ | ||
Response<String> response = new Response<>("content"); | ||
assertThat(response.content()).isEqualTo("content"); | ||
assertThat(response.tokenUsage()).isNull(); | ||
assertThat(response.finishReason()).isNull(); | ||
assertThat(response).hasToString("Response { content = content, tokenUsage = null, finishReason = null }"); | ||
} | ||
{ | ||
TokenUsage tokenUsage = new TokenUsage(1, 2, 3); | ||
Response<String> response = new Response<>("content", tokenUsage, null); | ||
assertThat(response.content()).isEqualTo("content"); | ||
assertThat(response.tokenUsage()).isEqualTo(tokenUsage); | ||
assertThat(response.finishReason()).isNull(); | ||
assertThat(response) | ||
.hasToString( | ||
"Response { " + | ||
"content = content, tokenUsage = TokenUsage { " + | ||
"inputTokenCount = 1, outputTokenCount = 2, totalTokenCount = 3 }, " + | ||
"finishReason = null }"); | ||
} | ||
{ | ||
TokenUsage tokenUsage = new TokenUsage(1, 2, 3); | ||
Response<String> response = new Response<>("content", tokenUsage, FinishReason.LENGTH); | ||
assertThat(response.content()).isEqualTo("content"); | ||
assertThat(response.tokenUsage()).isEqualTo(tokenUsage); | ||
assertThat(response.finishReason()).isEqualTo(FinishReason.LENGTH); | ||
assertThat(response) | ||
.hasToString( | ||
"Response { " + | ||
"content = content, tokenUsage = TokenUsage { " + | ||
"inputTokenCount = 1, outputTokenCount = 2, totalTokenCount = 3 }, " + | ||
"finishReason = LENGTH }"); | ||
} | ||
} | ||
|
||
@Test | ||
public void test_equals_hashCode() { | ||
String content1 = "content"; | ||
String content2 = "changed"; | ||
TokenUsage tokenUsage1 = new TokenUsage(1, 2, 3); | ||
TokenUsage tokenUsage2 = new TokenUsage(10, 2, 3); | ||
|
||
assertThat(new Response<>(content1, null, null)) | ||
.isEqualTo(new Response<>(content1, null, null)) | ||
.hasSameHashCodeAs(new Response<>(content1, null, null)) | ||
.isNotEqualTo(null) | ||
.isNotEqualTo(new Object()) | ||
.isNotEqualTo(new Response<>(content2, null, null)) | ||
.doesNotHaveSameHashCodeAs(new Response<>(content2, null, null)) | ||
.isNotEqualTo(new Response<>(content1, tokenUsage1, null)) | ||
.doesNotHaveSameHashCodeAs(new Response<>(content1, tokenUsage1, null)) | ||
.isNotEqualTo(new Response<>(content1, null, FinishReason.LENGTH)) | ||
.doesNotHaveSameHashCodeAs(new Response<>(content1, null, FinishReason.LENGTH)) | ||
.isNotEqualTo(new Response<>(content1, tokenUsage1, FinishReason.LENGTH)) | ||
.doesNotHaveSameHashCodeAs(new Response<>(content1, tokenUsage1, FinishReason.LENGTH)); | ||
|
||
assertThat(new Response<>(content1, tokenUsage1, FinishReason.LENGTH)) | ||
.isEqualTo(new Response<>(content1, tokenUsage1, FinishReason.LENGTH)) | ||
.hasSameHashCodeAs(new Response<>(content1, tokenUsage1, FinishReason.LENGTH)) | ||
.isNotEqualTo(new Response<>(content2, tokenUsage1, FinishReason.LENGTH)) | ||
.isNotEqualTo(new Response<>(content1, tokenUsage2, FinishReason.LENGTH)) | ||
.isNotEqualTo(new Response<>(content1, tokenUsage1, FinishReason.STOP)); | ||
} | ||
|
||
@Test | ||
public void test_builders() { | ||
assertThat(new Response<>("content")) | ||
.isEqualTo(Response.from("content")); | ||
|
||
TokenUsage tokenUsage = new TokenUsage(1, 2, 3); | ||
|
||
assertThat(new Response<>("content", tokenUsage, null)) | ||
.isEqualTo(Response.from("content", tokenUsage)) | ||
.isEqualTo(Response.from("content", tokenUsage, null)); | ||
|
||
assertThat(new Response<>("content", tokenUsage, FinishReason.LENGTH)) | ||
.isEqualTo(Response.from("content", tokenUsage, FinishReason.LENGTH)); | ||
|
||
} | ||
} |