Skip to content

Commit e1d62b0

Browse files
committed
add test case
Change-Id: I25b584d9877e14beba50111c50eacd58a13f2f86
1 parent 4fc1d53 commit e1d62b0

2 files changed

Lines changed: 180 additions & 4 deletions

File tree

agentscope-core/src/main/java/io/agentscope/core/model/tts/Qwen3TTSFlashVoice.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
/*
2-
* Qwen3 TTS Flash / Realtime voices enumeration.
2+
* Copyright 2024-2026 the original author or authors.
33
*
4-
* This enum lists the officially documented 17 timbres for
5-
* qwen3-tts-flash / qwen3-tts-flash-realtime models.
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
615
*/
716
package io.agentscope.core.model.tts;
817

@@ -51,7 +60,7 @@ public enum Qwen3TTSFlashVoice {
5160
/**
5261
* 墨讲师 (Elias) - 兼具严谨与叙事性的讲师音色。
5362
*/
54-
ELIAS("Elias", "墨讲师", Gender.FEMALE, "兼具严谨与叙事性的讲师音色"),
63+
ELIAS("Elias", "墨讲师", Gender.MALE, "兼具严谨与叙事性的讲师音色"),
5564

5665
/**
5766
* 上海-阿珍 (Jada) - 风风火火的沪上阿姐。
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
* Copyright 2024-2026 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.agentscope.core.model.tts;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
23+
import java.util.HashSet;
24+
import java.util.Random;
25+
import java.util.Set;
26+
import org.junit.jupiter.api.DisplayName;
27+
import org.junit.jupiter.api.Test;
28+
29+
/**
30+
* Unit tests for Qwen3TTSFlashVoice enum.
31+
*/
32+
class Qwen3TTSFlashVoiceTest {
33+
34+
@Test
35+
@DisplayName("should have 17 voice constants defined")
36+
void shouldHave17Voices() {
37+
assertEquals(17, Qwen3TTSFlashVoice.values().length);
38+
}
39+
40+
@Test
41+
@DisplayName("should have correct voiceId for CHERRY")
42+
void shouldHaveCorrectVoiceIdForCherry() {
43+
assertEquals("Cherry", Qwen3TTSFlashVoice.CHERRY.getVoiceId());
44+
assertEquals("芊悦", Qwen3TTSFlashVoice.CHERRY.getDisplayName());
45+
assertEquals(Qwen3TTSFlashVoice.Gender.FEMALE, Qwen3TTSFlashVoice.CHERRY.getGender());
46+
assertNotNull(Qwen3TTSFlashVoice.CHERRY.getDescription());
47+
}
48+
49+
@Test
50+
@DisplayName("should have correct voiceId for ETHAN")
51+
void shouldHaveCorrectVoiceIdForEthan() {
52+
assertEquals("Ethan", Qwen3TTSFlashVoice.ETHAN.getVoiceId());
53+
assertEquals("晨煦", Qwen3TTSFlashVoice.ETHAN.getDisplayName());
54+
assertEquals(Qwen3TTSFlashVoice.Gender.MALE, Qwen3TTSFlashVoice.ETHAN.getGender());
55+
assertNotNull(Qwen3TTSFlashVoice.ETHAN.getDescription());
56+
}
57+
58+
@Test
59+
@DisplayName("should have correct gender for ELIAS")
60+
void shouldHaveCorrectGenderForElias() {
61+
assertEquals("Elias", Qwen3TTSFlashVoice.ELIAS.getVoiceId());
62+
assertEquals(Qwen3TTSFlashVoice.Gender.MALE, Qwen3TTSFlashVoice.ELIAS.getGender());
63+
}
64+
65+
@Test
66+
@DisplayName("should find voice by voiceId case-insensitively")
67+
void shouldFindVoiceByVoiceId() {
68+
assertEquals(Qwen3TTSFlashVoice.CHERRY, Qwen3TTSFlashVoice.fromVoiceId("Cherry"));
69+
assertEquals(Qwen3TTSFlashVoice.CHERRY, Qwen3TTSFlashVoice.fromVoiceId("cherry"));
70+
assertEquals(Qwen3TTSFlashVoice.CHERRY, Qwen3TTSFlashVoice.fromVoiceId("CHERRY"));
71+
72+
assertEquals(Qwen3TTSFlashVoice.ETHAN, Qwen3TTSFlashVoice.fromVoiceId("Ethan"));
73+
assertEquals(Qwen3TTSFlashVoice.LI, Qwen3TTSFlashVoice.fromVoiceId("li"));
74+
assertEquals(Qwen3TTSFlashVoice.KIKI, Qwen3TTSFlashVoice.fromVoiceId("Kiki"));
75+
}
76+
77+
@Test
78+
@DisplayName("should return null for non-existent voiceId")
79+
void shouldReturnNullForNonExistentVoiceId() {
80+
assertNull(Qwen3TTSFlashVoice.fromVoiceId("NonExistent"));
81+
assertNull(Qwen3TTSFlashVoice.fromVoiceId("Unknown"));
82+
}
83+
84+
@Test
85+
@DisplayName("should return null for null or empty voiceId")
86+
void shouldReturnNullForNullOrEmptyVoiceId() {
87+
assertNull(Qwen3TTSFlashVoice.fromVoiceId(null));
88+
assertNull(Qwen3TTSFlashVoice.fromVoiceId(""));
89+
}
90+
91+
@Test
92+
@DisplayName("should return random voice using ThreadLocalRandom")
93+
void shouldReturnRandomVoice() {
94+
Qwen3TTSFlashVoice voice1 = Qwen3TTSFlashVoice.random();
95+
assertNotNull(voice1);
96+
97+
// Call multiple times to verify randomness (not guaranteed to be different but should
98+
// work)
99+
Set<Qwen3TTSFlashVoice> voices = new HashSet<>();
100+
for (int i = 0; i < 50; i++) {
101+
voices.add(Qwen3TTSFlashVoice.random());
102+
}
103+
// With 17 voices and 50 calls, we should get at least 2 different voices
104+
assertTrue(voices.size() >= 2);
105+
}
106+
107+
@Test
108+
@DisplayName("should return random voice using provided Random instance")
109+
void shouldReturnRandomVoiceWithProvidedRandom() {
110+
Random random = new Random(12345); // Fixed seed for reproducibility
111+
Qwen3TTSFlashVoice voice1 = Qwen3TTSFlashVoice.random(random);
112+
assertNotNull(voice1);
113+
114+
// Reset random with same seed to get same result
115+
random = new Random(12345);
116+
Qwen3TTSFlashVoice voice2 = Qwen3TTSFlashVoice.random(random);
117+
assertEquals(voice1, voice2);
118+
}
119+
120+
@Test
121+
@DisplayName("should have all voices with non-null properties")
122+
void shouldHaveAllVoicesWithNonNullProperties() {
123+
for (Qwen3TTSFlashVoice voice : Qwen3TTSFlashVoice.values()) {
124+
assertNotNull(voice.getVoiceId(), "voiceId should not be null for " + voice);
125+
assertNotNull(voice.getDisplayName(), "displayName should not be null for " + voice);
126+
assertNotNull(voice.getGender(), "gender should not be null for " + voice);
127+
assertNotNull(voice.getDescription(), "description should not be null for " + voice);
128+
}
129+
}
130+
131+
@Test
132+
@DisplayName("should have unique voiceIds for all voices")
133+
void shouldHaveUniqueVoiceIds() {
134+
Set<String> voiceIds = new HashSet<>();
135+
for (Qwen3TTSFlashVoice voice : Qwen3TTSFlashVoice.values()) {
136+
assertTrue(
137+
voiceIds.add(voice.getVoiceId()),
138+
"Duplicate voiceId found: " + voice.getVoiceId());
139+
}
140+
assertEquals(17, voiceIds.size());
141+
}
142+
143+
@Test
144+
@DisplayName("Gender enum should have MALE and FEMALE")
145+
void genderEnumShouldHaveMaleAndFemale() {
146+
assertEquals(2, Qwen3TTSFlashVoice.Gender.values().length);
147+
assertEquals(Qwen3TTSFlashVoice.Gender.MALE, Qwen3TTSFlashVoice.Gender.valueOf("MALE"));
148+
assertEquals(Qwen3TTSFlashVoice.Gender.FEMALE, Qwen3TTSFlashVoice.Gender.valueOf("FEMALE"));
149+
}
150+
151+
@Test
152+
@DisplayName("should have correct distribution of male and female voices")
153+
void shouldHaveCorrectGenderDistribution() {
154+
int maleCount = 0;
155+
int femaleCount = 0;
156+
for (Qwen3TTSFlashVoice voice : Qwen3TTSFlashVoice.values()) {
157+
if (voice.getGender() == Qwen3TTSFlashVoice.Gender.MALE) {
158+
maleCount++;
159+
} else if (voice.getGender() == Qwen3TTSFlashVoice.Gender.FEMALE) {
160+
femaleCount++;
161+
}
162+
}
163+
assertEquals(17, maleCount + femaleCount, "Total male + female should equal total voices");
164+
assertTrue(maleCount > 0, "Should have at least one male voice");
165+
assertTrue(femaleCount > 0, "Should have at least one female voice");
166+
}
167+
}

0 commit comments

Comments
 (0)