@@ -270,4 +270,96 @@ protected void toStringTestHelper(ExecMode platform, String testName, String exp
270270 DMLScript .USE_LOCAL_SPARK_CONFIG = sparkConfigOld ;
271271 }
272272 }
273+
274+ @ Test
275+ public void testPrintWithDecimal (){
276+ String testName = "ToString12" ;
277+
278+ String decimalPoints = "2" ;
279+ String value = "22" ;
280+ String expectedOutput = "22.00\n " ;
281+
282+ addTestConfiguration (testName , new TestConfiguration (TEST_CLASS_DIR , testName ));
283+ toStringTestHelper2 (ExecMode .SINGLE_NODE , testName , expectedOutput , decimalPoints , value );
284+ }
285+
286+
287+ @ Test
288+ public void testPrintWithDecimal2 (){
289+ String testName = "ToString12" ;
290+
291+ String decimalPoints = "2" ;
292+ String value = "5.244058388023880" ;
293+ String expectedOutput = "5.24\n " ;
294+
295+ addTestConfiguration (testName , new TestConfiguration (TEST_CLASS_DIR , testName ));
296+ toStringTestHelper2 (ExecMode .SINGLE_NODE , testName , expectedOutput , decimalPoints , value );
297+ }
298+
299+
300+ @ Test
301+ public void testPrintWithDecimal3 (){
302+ String testName = "ToString12" ;
303+
304+ String decimalPoints = "10" ;
305+ String value = "5.244058388023880" ;
306+ String expectedOutput = "5.2440583880\n " ;
307+
308+ addTestConfiguration (testName , new TestConfiguration (TEST_CLASS_DIR , testName ));
309+ toStringTestHelper2 (ExecMode .SINGLE_NODE , testName , expectedOutput , decimalPoints , value );
310+ }
311+
312+
313+ @ Test
314+ public void testPrintWithDecimal4 (){
315+ String testName = "ToString12" ;
316+
317+ String decimalPoints = "4" ;
318+ String value = "5.244058388023880" ;
319+ String expectedOutput = "5.2441\n " ;
320+
321+ addTestConfiguration (testName , new TestConfiguration (TEST_CLASS_DIR , testName ));
322+ toStringTestHelper2 (ExecMode .SINGLE_NODE , testName , expectedOutput , decimalPoints , value );
323+ }
324+
325+
326+ @ Test
327+ public void testPrintWithDecimal5 (){
328+ String testName = "ToString12" ;
329+
330+ String decimalPoints = "10" ;
331+ String value = "0.000000008023880" ;
332+ String expectedOutput = "0.0000000080\n " ;
333+
334+ addTestConfiguration (testName , new TestConfiguration (TEST_CLASS_DIR , testName ));
335+ toStringTestHelper2 (ExecMode .SINGLE_NODE , testName , expectedOutput , decimalPoints , value );
336+ }
337+
338+ protected void toStringTestHelper2 (ExecMode platform , String testName , String expectedOutput , String decimalPoints , String value ) {
339+ ExecMode platformOld = rtplatform ;
340+
341+ rtplatform = platform ;
342+ boolean sparkConfigOld = DMLScript .USE_LOCAL_SPARK_CONFIG ;
343+ if (rtplatform == ExecMode .SPARK )
344+ DMLScript .USE_LOCAL_SPARK_CONFIG = true ;
345+ try {
346+ // Create and load test configuration
347+ getAndLoadTestConfiguration (testName );
348+ String HOME = SCRIPT_DIR + TEST_DIR ;
349+ fullDMLScriptName = HOME + testName + ".dml" ;
350+ programArgs = new String []{"-args" , output (OUTPUT_NAME ), value , decimalPoints };
351+
352+ // Run DML and R scripts
353+ runTest (true , false , null , -1 );
354+
355+ // Compare output strings
356+ String output = TestUtils .readDMLString (output (OUTPUT_NAME ));
357+ TestUtils .compareScalars (expectedOutput , output );
358+ }
359+ finally {
360+ // Reset settings
361+ rtplatform = platformOld ;
362+ DMLScript .USE_LOCAL_SPARK_CONFIG = sparkConfigOld ;
363+ }
364+ }
273365}
0 commit comments