Renamed a unit test class name
Project: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/commit/7a6595c0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/tree/7a6595c0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/diff/7a6595c0 Branch: refs/heads/master Commit: 7a6595c01a09d06b217dccccb02419be434622d6 Parents: 79a099e Author: Makoto Yui <[email protected]> Authored: Thu Apr 26 14:52:53 2018 +0900 Committer: Makoto Yui <[email protected]> Committed: Thu Apr 26 15:49:28 2018 +0900 ---------------------------------------------------------------------- .../ftvec/trans/BinarizeLabelUDTFTest.java | 122 +++++++++++++++++++ .../ftvec/trans/TestBinarizeLabelUDTF.java | 122 ------------------- 2 files changed, 122 insertions(+), 122 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/7a6595c0/core/src/test/java/hivemall/ftvec/trans/BinarizeLabelUDTFTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/hivemall/ftvec/trans/BinarizeLabelUDTFTest.java b/core/src/test/java/hivemall/ftvec/trans/BinarizeLabelUDTFTest.java new file mode 100644 index 0000000..cc55098 --- /dev/null +++ b/core/src/test/java/hivemall/ftvec/trans/BinarizeLabelUDTFTest.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package hivemall.ftvec.trans; + +import static org.mockito.AdditionalMatchers.aryEq; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.powermock.api.mockito.PowerMockito.doNothing; +import static org.powermock.api.mockito.PowerMockito.spy; +import static org.powermock.api.mockito.PowerMockito.verifyPrivate; + +import hivemall.TestUtils; +import hivemall.utils.hadoop.WritableUtils; + +import java.util.Arrays; +import java.util.List; + +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({BinarizeLabelUDTF.class}) +public class BinarizeLabelUDTFTest { + + // ignored to avoid + // org.apache.hadoop.hive.shims.ShimLoader.getMajorVersion(ShimLoader.java:141) ExceptionInInitializerError + // in Hive v0.13.0 + //@Test(expected = UDFArgumentException.class) + public void testInsufficientLabelColumn() throws HiveException { + BinarizeLabelUDTF udtf = new BinarizeLabelUDTF(); + ObjectInspector[] argOIs = new ObjectInspector[2]; + argOIs[0] = PrimitiveObjectInspectorFactory.javaIntObjectInspector; + List<String> featureNames = Arrays.asList("positive", "features"); + argOIs[1] = ObjectInspectorFactory.getStandardConstantListObjectInspector( + PrimitiveObjectInspectorFactory.javaStringObjectInspector, featureNames); + + udtf.initialize(argOIs); + } + + @Test + public void test2Positive3NegativeSample() throws Exception { + BinarizeLabelUDTF udtf = spy(new BinarizeLabelUDTF()); + ObjectInspector[] argOIs = new ObjectInspector[3]; + argOIs[0] = PrimitiveObjectInspectorFactory.javaIntObjectInspector; + argOIs[1] = PrimitiveObjectInspectorFactory.javaIntObjectInspector; + List<String> featureNames = Arrays.asList("positive", "negative", "features"); + argOIs[2] = ObjectInspectorFactory.getStandardConstantListObjectInspector( + PrimitiveObjectInspectorFactory.javaStringObjectInspector, featureNames); + + doNothing().when(udtf, "forward", any()); + udtf.initialize(argOIs); + + Object[] arguments = new Object[3]; + arguments[0] = new Integer(2); + arguments[1] = new Integer(3); + arguments[2] = WritableUtils.val("a:1", "b:2"); + udtf.process(arguments); + + verifyPrivate(udtf, times(5)).invoke("forward", any(Object[].class)); + verifyPrivate(udtf, times(2)).invoke("forward", + aryEq(new Object[] {WritableUtils.val("a:1", "b:2"), 1})); + verifyPrivate(udtf, times(3)).invoke("forward", + aryEq(new Object[] {WritableUtils.val("a:1", "b:2"), 0})); + } + + @Test + public void test0Positive0NegativeSample() throws Exception { + BinarizeLabelUDTF udtf = spy(new BinarizeLabelUDTF()); + ObjectInspector[] argOIs = new ObjectInspector[3]; + argOIs[0] = PrimitiveObjectInspectorFactory.javaIntObjectInspector; + argOIs[1] = PrimitiveObjectInspectorFactory.javaIntObjectInspector; + List<String> featureNames = Arrays.asList("positive", "negative", "features"); + argOIs[2] = ObjectInspectorFactory.getStandardConstantListObjectInspector( + PrimitiveObjectInspectorFactory.javaStringObjectInspector, featureNames); + + doNothing().when(udtf, "forward", any()); + udtf.initialize(argOIs); + + Object[] arguments = new Object[3]; + arguments[0] = new Integer(0); + arguments[1] = new Integer(0); + arguments[2] = WritableUtils.val("a:1", "b:2"); + udtf.process(arguments); + + verifyPrivate(udtf, times(0)).invoke("forward", any(Object[].class)); + } + + @Test + public void testSerialization() throws HiveException { + final List<String> featureNames = Arrays.asList("positive", "negative", "features"); + TestUtils.testGenericUDTFSerialization( + BinarizeLabelUDTF.class, + new ObjectInspector[] { + PrimitiveObjectInspectorFactory.javaIntObjectInspector, + PrimitiveObjectInspectorFactory.javaIntObjectInspector, + ObjectInspectorFactory.getStandardConstantListObjectInspector( + PrimitiveObjectInspectorFactory.javaStringObjectInspector, featureNames)}, + new Object[][] {{new Integer(0), new Integer(0), WritableUtils.val("a:1", "b:2")}}); + } +} http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/7a6595c0/core/src/test/java/hivemall/ftvec/trans/TestBinarizeLabelUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/hivemall/ftvec/trans/TestBinarizeLabelUDTF.java b/core/src/test/java/hivemall/ftvec/trans/TestBinarizeLabelUDTF.java deleted file mode 100644 index 67e0a3e..0000000 --- a/core/src/test/java/hivemall/ftvec/trans/TestBinarizeLabelUDTF.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package hivemall.ftvec.trans; - -import static org.mockito.AdditionalMatchers.aryEq; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.times; -import static org.powermock.api.mockito.PowerMockito.doNothing; -import static org.powermock.api.mockito.PowerMockito.spy; -import static org.powermock.api.mockito.PowerMockito.verifyPrivate; - -import hivemall.TestUtils; -import hivemall.utils.hadoop.WritableUtils; - -import java.util.Arrays; -import java.util.List; - -import org.apache.hadoop.hive.ql.metadata.HiveException; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; -import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({BinarizeLabelUDTF.class}) -public class TestBinarizeLabelUDTF { - - // ignored to avoid - // org.apache.hadoop.hive.shims.ShimLoader.getMajorVersion(ShimLoader.java:141) ExceptionInInitializerError - // in Hive v0.13.0 - //@Test(expected = UDFArgumentException.class) - public void testInsufficientLabelColumn() throws HiveException { - BinarizeLabelUDTF udtf = new BinarizeLabelUDTF(); - ObjectInspector[] argOIs = new ObjectInspector[2]; - argOIs[0] = PrimitiveObjectInspectorFactory.javaIntObjectInspector; - List<String> featureNames = Arrays.asList("positive", "features"); - argOIs[1] = ObjectInspectorFactory.getStandardConstantListObjectInspector( - PrimitiveObjectInspectorFactory.javaStringObjectInspector, featureNames); - - udtf.initialize(argOIs); - } - - @Test - public void test2Positive3NegativeSample() throws Exception { - BinarizeLabelUDTF udtf = spy(new BinarizeLabelUDTF()); - ObjectInspector[] argOIs = new ObjectInspector[3]; - argOIs[0] = PrimitiveObjectInspectorFactory.javaIntObjectInspector; - argOIs[1] = PrimitiveObjectInspectorFactory.javaIntObjectInspector; - List<String> featureNames = Arrays.asList("positive", "negative", "features"); - argOIs[2] = ObjectInspectorFactory.getStandardConstantListObjectInspector( - PrimitiveObjectInspectorFactory.javaStringObjectInspector, featureNames); - - doNothing().when(udtf, "forward", any()); - udtf.initialize(argOIs); - - Object[] arguments = new Object[3]; - arguments[0] = new Integer(2); - arguments[1] = new Integer(3); - arguments[2] = WritableUtils.val("a:1", "b:2"); - udtf.process(arguments); - - verifyPrivate(udtf, times(5)).invoke("forward", any(Object[].class)); - verifyPrivate(udtf, times(2)).invoke("forward", - aryEq(new Object[] {WritableUtils.val("a:1", "b:2"), 1})); - verifyPrivate(udtf, times(3)).invoke("forward", - aryEq(new Object[] {WritableUtils.val("a:1", "b:2"), 0})); - } - - @Test - public void test0Positive0NegativeSample() throws Exception { - BinarizeLabelUDTF udtf = spy(new BinarizeLabelUDTF()); - ObjectInspector[] argOIs = new ObjectInspector[3]; - argOIs[0] = PrimitiveObjectInspectorFactory.javaIntObjectInspector; - argOIs[1] = PrimitiveObjectInspectorFactory.javaIntObjectInspector; - List<String> featureNames = Arrays.asList("positive", "negative", "features"); - argOIs[2] = ObjectInspectorFactory.getStandardConstantListObjectInspector( - PrimitiveObjectInspectorFactory.javaStringObjectInspector, featureNames); - - doNothing().when(udtf, "forward", any()); - udtf.initialize(argOIs); - - Object[] arguments = new Object[3]; - arguments[0] = new Integer(0); - arguments[1] = new Integer(0); - arguments[2] = WritableUtils.val("a:1", "b:2"); - udtf.process(arguments); - - verifyPrivate(udtf, times(0)).invoke("forward", any(Object[].class)); - } - - @Test - public void testSerialization() throws HiveException { - final List<String> featureNames = Arrays.asList("positive", "negative", "features"); - TestUtils.testGenericUDTFSerialization( - BinarizeLabelUDTF.class, - new ObjectInspector[] { - PrimitiveObjectInspectorFactory.javaIntObjectInspector, - PrimitiveObjectInspectorFactory.javaIntObjectInspector, - ObjectInspectorFactory.getStandardConstantListObjectInspector( - PrimitiveObjectInspectorFactory.javaStringObjectInspector, featureNames)}, - new Object[][] {{new Integer(0), new Integer(0), WritableUtils.val("a:1", "b:2")}}); - } -}
