Skip to content

Commit cd4e0fe

Browse files
committed
test(core): add test
1 parent 004b226 commit cd4e0fe

4 files changed

Lines changed: 80 additions & 9 deletions

File tree

agentscope-core/src/main/java/io/agentscope/core/formatter/openai/dto/OpenAIReasoningDetail.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
1919
import com.fasterxml.jackson.annotation.JsonInclude;
2020
import com.fasterxml.jackson.annotation.JsonProperty;
21+
import java.util.Objects;
2122

2223
/**
2324
* OpenAI Reasoning Detail DTO (OpenRouter specific for Gemini).
@@ -90,4 +91,26 @@ public Integer getIndex() {
9091
public void setIndex(Integer index) {
9192
this.index = index;
9293
}
94+
95+
@Override
96+
public boolean equals(Object o) {
97+
if (this == o) {
98+
return true;
99+
}
100+
if (!(o instanceof OpenAIReasoningDetail)) {
101+
return false;
102+
}
103+
OpenAIReasoningDetail that = (OpenAIReasoningDetail) o;
104+
return Objects.equals(this.id, that.id)
105+
&& Objects.equals(this.type, that.type)
106+
&& Objects.equals(this.data, that.data)
107+
&& Objects.equals(this.text, that.text)
108+
&& Objects.equals(this.format, that.format)
109+
&& Objects.equals(this.index, that.index);
110+
}
111+
112+
@Override
113+
public int hashCode() {
114+
return Objects.hash(this.id, this.type, this.data, this.text, this.format, this.index);
115+
}
93116
}

agentscope-core/src/test/java/io/agentscope/core/formatter/openai/dto/OpenAIMessageReasoningFieldTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.agentscope.core.formatter.openai.dto;
1717

1818
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1920
import static org.junit.jupiter.api.Assertions.assertNull;
2021
import static org.junit.jupiter.api.Assertions.assertTrue;
2122

@@ -168,4 +169,31 @@ void testDeserializeVllmStreamingChunk() {
168169

169170
assertEquals("Step 1: parse the input...", delta.getReasoningContent());
170171
}
172+
173+
@Test
174+
@DisplayName("Should compare reasoning details by value")
175+
void testReasoningDetailEqualsAndHashCodeUseValues() {
176+
OpenAIReasoningDetail first = reasoningDetail("reasoning.text");
177+
OpenAIReasoningDetail second = reasoningDetail("reasoning.text");
178+
OpenAIReasoningDetail different = reasoningDetail("reasoning.summary");
179+
180+
assertEquals(first, first);
181+
assertNotEquals(first, null);
182+
assertNotEquals(first, "other");
183+
assertEquals(first, second);
184+
assertEquals(second, first);
185+
assertEquals(first.hashCode(), second.hashCode());
186+
assertNotEquals(first, different);
187+
}
188+
189+
private OpenAIReasoningDetail reasoningDetail(String type) {
190+
OpenAIReasoningDetail detail = new OpenAIReasoningDetail();
191+
detail.setId("reasoning-1");
192+
detail.setType(type);
193+
detail.setData("encrypted-data");
194+
detail.setText("visible reasoning");
195+
detail.setFormat("openai-responses-v1");
196+
detail.setIndex(0);
197+
return detail;
198+
}
171199
}

agentscope-core/src/test/java/io/agentscope/core/model/OpenAIChatModelTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static org.junit.jupiter.api.Assertions.assertEquals;
1919
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2021
import static org.junit.jupiter.api.Assertions.assertNotNull;
2122
import static org.junit.jupiter.api.Assertions.assertTrue;
2223

@@ -248,6 +249,21 @@ void testGetModelName() {
248249
assertEquals("gpt-4", model.getModelName());
249250
}
250251

252+
@Test
253+
@DisplayName("Should compare chat usage by value")
254+
void testChatUsageEqualsAndHashCodeUseValues() {
255+
ChatUsage first = ChatUsage.builder().inputTokens(10).outputTokens(20).time(1.5).build();
256+
ChatUsage second = ChatUsage.builder().inputTokens(10).outputTokens(20).time(1.5).build();
257+
ChatUsage different =
258+
ChatUsage.builder().inputTokens(10).outputTokens(21).time(1.5).build();
259+
260+
assertEquals(first, first);
261+
assertNotEquals(first, null);
262+
assertEquals(first, second);
263+
assertEquals(first.hashCode(), second.hashCode());
264+
assertNotEquals(first, different);
265+
}
266+
251267
@Test
252268
@DisplayName("Should build model with custom endpoint path")
253269
void testBuildModelWithEndpointPath() throws Exception {

agentscope-core/src/test/java/io/agentscope/core/session/ListHashUtilTest.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,6 @@ void testComputeHashEquivalentMessagesWithChatUsage() {
150150

151151
@Test
152152
void testComputeHashEquivalentThinkingBlocksWithReasoningDetails() {
153-
OpenAIReasoningDetail detail = new OpenAIReasoningDetail();
154-
detail.setId("reasoning-1");
155-
detail.setType("reasoning.text");
156-
detail.setData("encrypted-data");
157-
detail.setText("visible reasoning");
158-
detail.setFormat("openai-responses-v1");
159-
detail.setIndex(0);
160153
List<Msg> first =
161154
List.of(
162155
Msg.builder()
@@ -170,7 +163,7 @@ void testComputeHashEquivalentThinkingBlocksWithReasoningDetails() {
170163
Map.of(
171164
ThinkingBlock
172165
.METADATA_REASONING_DETAILS,
173-
List.of(detail)))
166+
List.of(createReasoningDetail())))
174167
.build())
175168
.build());
176169

@@ -187,7 +180,7 @@ void testComputeHashEquivalentThinkingBlocksWithReasoningDetails() {
187180
Map.of(
188181
ThinkingBlock
189182
.METADATA_REASONING_DETAILS,
190-
List.of(detail)))
183+
List.of(createReasoningDetail())))
191184
.build())
192185
.build());
193186

@@ -344,4 +337,15 @@ private List<Msg> createMsgList(int size) {
344337
}
345338
return list;
346339
}
340+
341+
private OpenAIReasoningDetail createReasoningDetail() {
342+
OpenAIReasoningDetail detail = new OpenAIReasoningDetail();
343+
detail.setId("reasoning-1");
344+
detail.setType("reasoning.text");
345+
detail.setData("encrypted-data");
346+
detail.setText("visible reasoning");
347+
detail.setFormat("openai-responses-v1");
348+
detail.setIndex(0);
349+
return detail;
350+
}
347351
}

0 commit comments

Comments
 (0)