Skip to content

Commit c6d0b13

Browse files
committed
Add test with dml script for setNames and getNames function
1 parent a46fad3 commit c6d0b13

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.sysds.test.functions.builtin.part1;
21+
22+
import org.apache.sysds.test.TestConfiguration;
23+
import org.apache.sysds.test.AutomatedTestBase;
24+
import org.junit.Test;
25+
import java.io.IOException;
26+
import java.nio.file.Files;
27+
import java.nio.file.Paths;
28+
29+
import org.apache.commons.logging.Log;
30+
import org.apache.commons.logging.LogFactory;
31+
32+
import static org.junit.Assert.fail;
33+
import static org.junit.Assert.assertArrayEquals;
34+
35+
public class BuiltinGetSetNamesScriptTest extends AutomatedTestBase {
36+
37+
private static final Log LOG = LogFactory.getLog(BuiltinGetSetNamesScriptTest.class);
38+
39+
private static final String TEST_NAME = "BuiltinGetSetNamesTest";
40+
private static final String TEST_DIR = "functions/builtin/part1/";
41+
private static final String TEST_CLASS_DIR = TEST_DIR + BuiltinGetSetNamesScriptTest.class.getSimpleName() + "/";
42+
43+
@Override
44+
public void setUp() {
45+
addTestConfiguration(TEST_NAME,
46+
new TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[]{"N"}));
47+
}
48+
49+
@Test
50+
public void testSetNamesAndGetNames() {
51+
TestConfiguration config = getTestConfiguration(TEST_NAME);
52+
loadTestConfiguration(config);
53+
54+
fullDMLScriptName = SCRIPT_DIR + TEST_DIR + TEST_NAME + ".dml";
55+
programArgs = new String[] { "-args", output("N") };
56+
57+
runTest(true, false, null, -1);
58+
59+
String actualOutputPath = output("N");
60+
String actualContent;
61+
62+
try {
63+
actualContent = new String(Files.readAllBytes(Paths.get(actualOutputPath))).trim();
64+
String[] actualNames = actualContent.split(",");
65+
66+
String[] expectedNames = new String[]{"name", "age"};
67+
68+
assertArrayEquals("Column names mismatch.", expectedNames, actualNames);
69+
70+
} catch (IOException e) {
71+
LOG.error("Failed to read test files: " + e.getMessage(), e);
72+
fail("Failed to read test files: " + e.getMessage());
73+
}
74+
}
75+
}
76+

src/test/java/org/apache/sysds/test/functions/builtin/BuiltinGetSetNamesTest/BuiltinGetSetNamesTest.java renamed to src/test/java/org/apache/sysds/test/functions/builtin/part1/BuiltinGetSetNamesTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.apache.sysds.test.functions.builtin.BuiltinGetSetNamesTest;
19+
package org.apache.sysds.test.functions.builtin.part1;
2020
import org.apache.sysds.runtime.frame.data.FrameBlock;
21-
import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex;
2221
import org.apache.sysds.common.Types.ValueType;
2322
import org.apache.sysds.runtime.DMLRuntimeException;
2423
import org.junit.Test;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 = as.frame(matrix(c("Alice", "25", "Bob", "30"), rows=2),
23+
types=["string", "string"])
24+
25+
X = setNames(X, matrix(c("name", "age"), rows=1))
26+
27+
N = getNames(X)
28+
29+
write(N, $OUTPUT, format="csv")

0 commit comments

Comments
 (0)