1 package com.acumenvelocity.ath.mt.confidence;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.junit.jupiter.api.Assertions.assertNotNull;
5 import static org.junit.jupiter.api.Assertions.assertTrue;
6
7 import org.junit.jupiter.api.AfterAll;
8 import org.junit.jupiter.api.BeforeAll;
9 import org.junit.jupiter.api.Disabled;
10 import org.junit.jupiter.api.DisplayName;
11 import org.junit.jupiter.api.Test;
12
13 import com.acumenvelocity.ath.common.Const;
14 import com.acumenvelocity.ath.common.ControllerUtil;
15 import com.acumenvelocity.ath.common.Log;
16 import com.acumenvelocity.ath.gct.v3.AthTranslation;
17 import com.acumenvelocity.ath.mt.confidence.HybridDataStructures.HybridTranslationScore;
18
19 @DisplayName("HybridQualityEstimator - Single Translation Evaluation")
20 class TestHybridQualityEstimator_IT {
21
22 private static HybridQualityEstimator estimator;
23
24 @BeforeAll
25 static void setUp() throws Exception {
26
27 String projectId = ControllerUtil.getProjectId();
28 String location = Const.US_CENTRAL1_PROJECT_LOCATION;
29
30 assertTrue(projectId != null && location != null,
31 "GCP_PROJECT_ID and GCP_LOCATION must be set to run integration tests");
32
33 AthTranslation.init();
34 estimator = new HybridQualityEstimator(projectId, location, true);
35 }
36
37 @AfterAll
38 static void tearDown() throws Exception {
39 if (estimator != null) {
40 estimator.close();
41 }
42
43 AthTranslation.done();
44 }
45
46 @Test
47 @DisplayName("Perfect translation → Gemini trusted, confidence ~1.0")
48 void testPerfectTranslation() {
49 HybridTranslationScore score = estimator.evaluateTranslation(
50 "The quick brown fox jumps over the lazy dog.",
51 "Der schnelle braune Fuchs springt über den faulen Hund.",
52 "en", "de");
53
54 assertNotNull(score);
55 assertEquals("gemini_trusted", score.getMethod());
56 assertTrue(score.getConfidence() >= 0.90, "Perfect translation should have high confidence");
57 assertNotNull(score.getMetricXScore());
58 assertTrue(score.getMetricXScore() >= 90.0, "Gemini raw score should be high");
59 }
60
61 @Test
62 @DisplayName("Garbage translation → fallback to heuristics, low confidence")
63 void testGarbageTranslation() {
64 HybridTranslationScore score = estimator.evaluateTranslation(
65 "Hello world",
66 "xyz abc 123 !!!",
67 "en", "fr");
68
69
70 assertTrue(score.getConfidence() < 0.70,
71 "Garbage should have low confidence: " + score.getConfidence());
72 assertTrue(
73 "heuristic_fallback".equals(score.getMethod()) ||
74 score.getConfidence() < 0.50,
75 "Should fallback or be very low");
76 }
77
78 @Test
79 @DisplayName("Creative but correct LLM translation → high Gemini score")
80 void testCreativeLLMTranslation() {
81 HybridTranslationScore score = estimator.evaluateTranslation(
82 "Life is what happens when you're busy making other plans.",
83 "Das Leben ist das, was passiert, während du eifrig andere Pläne schmiedest.",
84 "en", "de");
85
86 assertNotNull(score);
87 assertTrue(score.getConfidence() >= 0.85,
88 "Natural, idiomatic LLM translation should rank high: " + score.getConfidence());
89 assertEquals("gemini_trusted", score.getMethod());
90 }
91
92 @Test
93 @Disabled("Vertex AI cannot detect a wrong language, a language detector is needed")
94 @DisplayName("Wrong language → heuristics fallback")
95 void testWrongLanguage() {
96 Log.info(getClass(), "1. Evaluation started");
97
98 HybridTranslationScore score = estimator.evaluateTranslation(
99 "Hello world",
100 "Bonjour le monde",
101 "en", "de");
102
103 Log.info(getClass(), "1. Evaluation finisheded");
104
105 assertTrue(score.getConfidence() < 0.80,
106 "Wrong target language should be penalized");
107 }
108
109 @Test
110 @DisplayName("Empty input → returns 0.0 confidence")
111 void testEmptyInput() {
112 HybridTranslationScore score = estimator.evaluateTranslation(
113 "", "Hello", "en", "fr");
114
115 assertEquals(0.0, score.getConfidence(), 0.001);
116 assertTrue(score.getMethod().contains("empty") || score.getMethod().contains("error"));
117 }
118 }