Skip to content

Commit 01c893e

Browse files
committed
to String inconsistency
1 parent 1130fc1 commit 01c893e

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

src/test/java/org/apache/sysds/test/functions/misc/ToStringTest.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#-------------------------------------------------------------
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
#-------------------------------------------------------------
21+
22+
X = matrix($2, rows=1, cols=1)
23+
str = toString(X, rows=3, cols=3, decimal=$3)
24+
write(str, $1)

0 commit comments

Comments
 (0)