-
-
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.
test(api): add test cases for CreateMessageResponse, Usage, ContentMe…
…ssage, and Delta Added test cases for CreateMessageResponse, Usage, ContentMessage, and Delta classes. The tests cover creation, dummy data generation, JSON serialization, and JSON deserialization for each respective class.
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...way-core/src/jvmTest/kotlin/com/tddworks/anthropic/api/messages/api/ContentMessageTest.kt
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,15 @@ | ||
package com.tddworks.anthropic.api.messages.api | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
|
||
class ContentMessageTest { | ||
|
||
@Test | ||
fun `should create a ContentMessage`() { | ||
val dummyMessage = ContentMessage("Hi! My name is Claude.", "text") | ||
|
||
assertEquals("Hi! My name is Claude.", dummyMessage.text) | ||
assertEquals("text", dummyMessage.type) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...e/src/jvmTest/kotlin/com/tddworks/anthropic/api/messages/api/CreateMessageResponseTest.kt
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,24 @@ | ||
package com.tddworks.anthropic.api.messages.api | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
|
||
|
||
internal class CreateMessageResponseTest { | ||
|
||
@Test | ||
fun `should create a dummy CreateMessageResponse`() { | ||
|
||
val dummyResponse = CreateMessageResponse.dummy() | ||
|
||
assertEquals("msg_1nZdL29xx5MUA1yADyHTEsnR8uuvGzszyY", dummyResponse.id) | ||
assertEquals("claude-3-opus-20240229", dummyResponse.model) | ||
assertEquals("assistant", dummyResponse.role) | ||
assertNull(dummyResponse.stopReason) | ||
assertNull(dummyResponse.stopSequence) | ||
assertEquals("message", dummyResponse.type) | ||
assertEquals(Usage(25, 1), dummyResponse.usage) | ||
assertEquals(listOf(ContentMessage("Hi! My name is Claude.", "text")), dummyResponse.content) | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...enai-gateway-core/src/jvmTest/kotlin/com/tddworks/anthropic/api/messages/api/DeltaTest.kt
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,19 @@ | ||
package com.tddworks.anthropic.api.messages.api | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
|
||
|
||
class DeltaTest { | ||
|
||
@Test | ||
fun `should create dummy Delta`() { | ||
val delta = Delta.dummy() | ||
assertEquals("text_delta", delta.type) | ||
assertEquals("Hello", delta.text) | ||
assertEquals("end_turn", delta.stopReason) | ||
assertEquals(null, delta.stopSequence) | ||
assertEquals(Usage(outputTokens = 15), delta.usage) | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...enai-gateway-core/src/jvmTest/kotlin/com/tddworks/anthropic/api/messages/api/UsageTest.kt
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,35 @@ | ||
package com.tddworks.anthropic.api.messages.api | ||
|
||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class UsageTest { | ||
@Test | ||
fun `should create a empty Usage`() { | ||
val usage = Usage() | ||
val json = Json.encodeToString(usage) | ||
|
||
val expectedJson = "{}" | ||
assertEquals(expectedJson, json) | ||
} | ||
|
||
@Test | ||
fun `should create a dummy Usage`() { | ||
val usage = Usage(inputTokens = 10, outputTokens = 20) | ||
val json = Json.encodeToString(usage) | ||
|
||
val expectedJson = "{\"input_tokens\":10,\"output_tokens\":20}" | ||
assertEquals(expectedJson, json) | ||
} | ||
|
||
@Test | ||
fun `should parse a Usage from json`() { | ||
val json = "{\"input_tokens\":5,\"output_tokens\":15}" | ||
val usage = Json.decodeFromString<Usage>(json) | ||
|
||
assertEquals(5, usage.inputTokens) | ||
assertEquals(15, usage.outputTokens) | ||
} | ||
} |