Skip to content

Commit c3c48ce

Browse files
committed
added range check
1 parent cdc4117 commit c3c48ce

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

translate/src/test/java/com/google/cloud/translate/samples/TranslateTextTest.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ public class TranslateTextTest {
7575

7676
// Assert
7777
String got = bout.toString();
78-
assertThat(got).contains("language=en, confidence=0.79742646");
78+
assertThat(got).contains("language=en");
79+
80+
// Assert
81+
Double confidence = Double.parseDouble(
82+
got.split("confidence=")[1].split("}")[0]
83+
);
84+
assertThat(confidence).isLessThan(1.0);
85+
assertThat(confidence).isGreaterThan(0.7);
7986
}
8087

8188
@Test public void testGermanLangDetection() throws Exception {
@@ -88,8 +95,14 @@ public class TranslateTextTest {
8895

8996
// Assert
9097
String got = bout.toString();
91-
assertThat(got).contains("language=de, confidence=0.9293963");
98+
assertThat(got).contains("language=de");
9299

100+
// Assert
101+
Double confidence = Double.parseDouble(
102+
got.split("confidence=")[1].split("}")[0]
103+
);
104+
assertThat(confidence).isLessThan(1.0);
105+
assertThat(confidence).isGreaterThan(0.9);
93106
}
94107

95108
@Test public void testDefaultIdentityTranslation() throws Exception {

0 commit comments

Comments
 (0)