2024-06-27 23:26:53 -05:00
|
|
|
namespace AnthropicClient.Tests.Unit.Models;
|
|
|
|
|
|
2024-07-03 16:57:27 -05:00
|
|
|
public class UsageTests : SerializationTest
|
2024-06-27 23:26:53 -05:00
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Constructor_WhenCalled_ShouldInitializeProperties()
|
|
|
|
|
{
|
|
|
|
|
var expectedInputTokens = 1;
|
|
|
|
|
var expectedOutputTokens = 2;
|
2024-08-16 09:21:43 -05:00
|
|
|
var expectedCacheCreationInputTokens = 3;
|
|
|
|
|
var expectedCacheReadInputTokens = 4;
|
2024-06-27 23:26:53 -05:00
|
|
|
|
2024-07-03 16:57:27 -05:00
|
|
|
var usage = new Usage
|
2024-06-27 23:26:53 -05:00
|
|
|
{
|
|
|
|
|
InputTokens = expectedInputTokens,
|
2024-08-16 09:21:43 -05:00
|
|
|
OutputTokens = expectedOutputTokens,
|
|
|
|
|
CacheCreationInputTokens = expectedCacheCreationInputTokens,
|
|
|
|
|
CacheReadInputTokens = expectedCacheReadInputTokens
|
2024-06-27 23:26:53 -05:00
|
|
|
};
|
|
|
|
|
|
2024-07-03 16:57:27 -05:00
|
|
|
usage.InputTokens.Should().Be(expectedInputTokens);
|
|
|
|
|
usage.OutputTokens.Should().Be(expectedOutputTokens);
|
2024-08-16 09:21:43 -05:00
|
|
|
usage.CacheCreationInputTokens.Should().Be(expectedCacheCreationInputTokens);
|
|
|
|
|
usage.CacheReadInputTokens.Should().Be(expectedCacheReadInputTokens);
|
2024-06-27 23:26:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void JsonSerialization_WhenCalled_ItShouldSerializeCorrectly()
|
|
|
|
|
{
|
2024-08-16 09:21:43 -05:00
|
|
|
var expectedJson = @"{
|
|
|
|
|
""input_tokens"": 1,
|
|
|
|
|
""output_tokens"": 2,
|
|
|
|
|
""cache_creation_input_tokens"": 3,
|
|
|
|
|
""cache_read_input_tokens"": 4
|
|
|
|
|
}";
|
2024-06-27 23:26:53 -05:00
|
|
|
|
2024-07-03 16:57:27 -05:00
|
|
|
var usage = new Usage
|
2024-06-27 23:26:53 -05:00
|
|
|
{
|
|
|
|
|
InputTokens = 1,
|
2024-08-16 09:21:43 -05:00
|
|
|
OutputTokens = 2,
|
|
|
|
|
CacheCreationInputTokens = 3,
|
|
|
|
|
CacheReadInputTokens = 4
|
2024-06-27 23:26:53 -05:00
|
|
|
};
|
|
|
|
|
|
2024-07-03 16:57:27 -05:00
|
|
|
var actual = Serialize(usage);
|
2024-06-27 23:26:53 -05:00
|
|
|
|
|
|
|
|
JsonAssert.Equal(expectedJson, actual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void JsonDeserialization_WhenCalled_ItShouldDeserializeCorrectly()
|
|
|
|
|
{
|
2024-08-16 09:21:43 -05:00
|
|
|
var json = @"{
|
|
|
|
|
""input_tokens"": 1,
|
|
|
|
|
""output_tokens"": 2,
|
|
|
|
|
""cache_creation_input_tokens"": 3,
|
|
|
|
|
""cache_read_input_tokens"": 4
|
|
|
|
|
}";
|
2024-06-27 23:26:53 -05:00
|
|
|
|
2024-07-03 16:57:27 -05:00
|
|
|
var usage = Deserialize<Usage>(json);
|
2024-06-27 23:26:53 -05:00
|
|
|
|
2024-07-03 16:57:27 -05:00
|
|
|
usage!.InputTokens.Should().Be(1);
|
|
|
|
|
usage.OutputTokens.Should().Be(2);
|
2024-08-16 09:21:43 -05:00
|
|
|
usage.CacheCreationInputTokens.Should().Be(3);
|
|
|
|
|
usage.CacheReadInputTokens.Should().Be(4);
|
2024-06-27 23:26:53 -05:00
|
|
|
}
|
|
|
|
|
}
|