|
| 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 | + |
0 commit comments