This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/main by this push:
     new 63013e6aa ORC-1478: Adding Unit Tests for 
org.apache.orc.impl.DynamicIntArray
63013e6aa is described below

commit 63013e6aae974c066c4b773cfcaac13d1cb18608
Author: mystic-lama <[email protected]>
AuthorDate: Thu Aug 17 17:29:19 2023 -0700

    ORC-1478: Adding Unit Tests for org.apache.orc.impl.DynamicIntArray
    
    ### What changes were proposed in this pull request?
    The PR adds Unit Test for org.apache.orc.impl.DynamicIntArray class
    
    ### Why are the changes needed?
    Unit tests helps catching issues early and acts as safety net while 
refactoring code
    
    ### How was this patch tested?
    The build passes and the added test cases pass.
    
    Closes #1584 from mystic-lama/dynamicintarray_tests.
    
    Lead-authored-by: mystic-lama <[email protected]>
    Co-authored-by: Ash <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 .../org/apache/orc/impl/TestDynamicIntArray.java   | 80 ++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/java/core/src/test/org/apache/orc/impl/TestDynamicIntArray.java 
b/java/core/src/test/org/apache/orc/impl/TestDynamicIntArray.java
new file mode 100644
index 000000000..2c0f882e0
--- /dev/null
+++ b/java/core/src/test/org/apache/orc/impl/TestDynamicIntArray.java
@@ -0,0 +1,80 @@
+/*
+ * 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 org.apache.orc.impl;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class TestDynamicIntArray {
+
+    @Test
+    public void simpleDynamicIntArrayTest() {
+        DynamicIntArray dynamicIntArray = new DynamicIntArray();
+        dynamicIntArray.add(10);
+        assertEquals(10, dynamicIntArray.get(0));
+        assertEquals(1, dynamicIntArray.size());
+        assertEquals(32768, dynamicIntArray.getSizeInBytes());
+        dynamicIntArray.add(20);
+        assertEquals(20, dynamicIntArray.get(1));
+        assertEquals(2, dynamicIntArray.size());
+        assertEquals(32768, dynamicIntArray.getSizeInBytes());
+        dynamicIntArray.clear();
+        assertEquals(0, dynamicIntArray.size());
+        assertEquals(0, dynamicIntArray.getSizeInBytes());
+    }
+
+    @Test
+    public void testDynamicIntArrayGrow() {
+        // keep chunk size small to test
+        DynamicIntArray dynamicIntArray = new DynamicIntArray(10);
+
+        for(int i = 0; i < 25; i++) {
+            dynamicIntArray.add(i);
+        }
+        assertEquals(25, dynamicIntArray.size());
+        assertEquals(120, dynamicIntArray.getSizeInBytes());
+    }
+
+    @Test
+    public void testIncrement() {
+        DynamicIntArray dynamicIntArray = new DynamicIntArray(10);
+        dynamicIntArray.add(10);
+        assertEquals(10, dynamicIntArray.get(0));
+        dynamicIntArray.increment(0, 10);
+        assertEquals(20, dynamicIntArray.get(0));
+    }
+
+    @Test
+    public void testSet() {
+        DynamicIntArray dynamicIntArray = new DynamicIntArray(10);
+        dynamicIntArray.add(10);
+        assertEquals(10, dynamicIntArray.get(0));
+        dynamicIntArray.set(0, 25);
+        assertEquals(25, dynamicIntArray.get(0));
+    }
+
+    @Test
+    public void testInvalidGetIndex() {
+        DynamicIntArray dynamicIntArray = new DynamicIntArray(10);
+        dynamicIntArray.add(10);
+        assertThrows(IndexOutOfBoundsException.class, () -> 
dynamicIntArray.get(11));
+    }
+}

Reply via email to