|
3 | 3 | import com.alibaba.fastjson2.JSONObject; |
4 | 4 | import com.xxdb.DBConnection; |
5 | 5 | import com.xxdb.io.*; |
| 6 | +import org.junit.Assert; |
6 | 7 | import org.junit.Test; |
7 | 8 |
|
8 | 9 | import java.awt.*; |
|
15 | 16 | import java.util.*; |
16 | 17 | import java.util.List; |
17 | 18 |
|
| 19 | +import static com.xxdb.data.Entity.DATA_TYPE.*; |
18 | 20 | import static org.junit.Assert.*; |
19 | 21 |
|
20 | 22 | public class BasicArrayVectorTest { |
@@ -1787,4 +1789,154 @@ public void test_BasicArrayVector_getScale() throws IOException { |
1787 | 1789 | BasicArrayVector bav1 = (BasicArrayVector)conn.run(script); |
1788 | 1790 | assertEquals(4, bav1.getScale()); |
1789 | 1791 | } |
| 1792 | + |
| 1793 | + @Test |
| 1794 | + public void test_BasicArrayVector_BOOL_set_entity() throws Exception { |
| 1795 | + BasicArrayVector bav = new BasicArrayVector(DT_BOOL_ARRAY, 2); |
| 1796 | + bav.set(0,new BasicBooleanVector(0,0)); |
| 1797 | + List<Byte> list = new ArrayList<>(); |
| 1798 | + list.add(0,(byte) 1); |
| 1799 | + list.add(1,(byte) 1); |
| 1800 | + list.add(2,null); |
| 1801 | + list.add(3,Byte.MAX_VALUE); |
| 1802 | + list.add(4,(byte) 0); |
| 1803 | + list.add(5,(byte) 0); |
| 1804 | + BasicBooleanVector bbv = new BasicBooleanVector(list); |
| 1805 | + bav.set(1,bbv); |
| 1806 | + assertEquals(Entity.DATA_TYPE.DT_BOOL_ARRAY,bav.getDataType()); |
| 1807 | + System.out.println(bav.getString()); |
| 1808 | + assertEquals("[[],[true,true,,true,false,false]]",bav.getString()); |
| 1809 | + } |
| 1810 | + |
| 1811 | + @Test |
| 1812 | + public void test_BasicArrayVector_BOOL_set_entity_not_support() throws Exception { |
| 1813 | + BasicArrayVector bav = new BasicArrayVector(DT_BOOL_ARRAY, 2); |
| 1814 | + String re = null; |
| 1815 | + try{ |
| 1816 | + bav.set(0,new BasicDecimal64Vector(0,0)); |
| 1817 | + }catch(Exception ex){ |
| 1818 | + re = ex.getMessage(); |
| 1819 | + } |
| 1820 | + assertEquals("BasicArrayVector.set requires same data type. Expected: DT_BOOL, Got: DT_DECIMAL64",re); |
| 1821 | + |
| 1822 | + String re1 = null; |
| 1823 | + try{ |
| 1824 | + bav.set(0,new BasicBoolean((byte)0)); |
| 1825 | + }catch(Exception ex){ |
| 1826 | + re1 = ex.getMessage(); |
| 1827 | + } |
| 1828 | + assertEquals("BasicArrayVector.set requires a Vector value, got: BasicBoolean",re1); |
| 1829 | + |
| 1830 | + String re2 = null; |
| 1831 | + try{ |
| 1832 | + bav.set(-1,new BasicBooleanVector(0,0)); |
| 1833 | + }catch(Exception ex){ |
| 1834 | + re2 = ex.getMessage(); |
| 1835 | + } |
| 1836 | + assertEquals("Index -1 out of bounds for capacity 2",re2); |
| 1837 | + |
| 1838 | + String re3 = null; |
| 1839 | + try{ |
| 1840 | + bav.set(3,new BasicBooleanVector(0,0)); |
| 1841 | + }catch(Exception ex){ |
| 1842 | + re3 = ex.getMessage(); |
| 1843 | + } |
| 1844 | + assertEquals("Index 3 out of bounds for capacity 2",re3); |
| 1845 | + } |
| 1846 | + |
| 1847 | + @Test |
| 1848 | + public void test_BasicArrayVector_BOOL_set_object() throws Exception { |
| 1849 | + BasicArrayVector bav = new BasicArrayVector(DT_BOOL_ARRAY, 2); |
| 1850 | + bav.set(0,(Object) new BasicBooleanVector(0,0)); |
| 1851 | + List<Byte> list = new ArrayList<>(); |
| 1852 | + list.add(0,(byte) 1); |
| 1853 | + list.add(1,(byte) 1); |
| 1854 | + list.add(2,null); |
| 1855 | + list.add(3,Byte.MAX_VALUE); |
| 1856 | + list.add(4,(byte) 0); |
| 1857 | + list.add(5,(byte) 0); |
| 1858 | + BasicBooleanVector bbv = new BasicBooleanVector(list); |
| 1859 | + bav.set(1,(Object) bbv); |
| 1860 | + assertEquals(Entity.DATA_TYPE.DT_BOOL_ARRAY,bav.getDataType()); |
| 1861 | + System.out.println(bav.getString()); |
| 1862 | + assertEquals("[[],[true,true,,true,false,false]]",bav.getString()); |
| 1863 | + } |
| 1864 | + |
| 1865 | + @Test |
| 1866 | + public void test_BasicArrayVector_BOOL_set_object_null() throws Exception { |
| 1867 | + BasicArrayVector bav = new BasicArrayVector(DT_BOOL_ARRAY, 3); |
| 1868 | + String re = null; |
| 1869 | + try{ |
| 1870 | + bav.set(0,(Object)null); |
| 1871 | + }catch(Exception ex){ |
| 1872 | + re = ex.getMessage(); |
| 1873 | + } |
| 1874 | + Assert.assertEquals("Error in BasicArrayVector.set(Object): BasicArrayVector.set(Object) requires a Vector, got: null", re); |
| 1875 | + } |
| 1876 | + |
| 1877 | + @Test |
| 1878 | + public void test_BasicArrayVector_BOOL_set_object_not_support() throws Exception { |
| 1879 | + BasicArrayVector bav = new BasicArrayVector(DT_BOOL_ARRAY, 3); |
| 1880 | + List<Byte> list = new ArrayList<>(); |
| 1881 | + list.add(0,(byte) 1); |
| 1882 | + list.add(1,(byte) 1); |
| 1883 | + list.add(2,null); |
| 1884 | + list.add(3,Byte.MAX_VALUE); |
| 1885 | + list.add(4,(byte) 0); |
| 1886 | + list.add(5,(byte) 0); |
| 1887 | + String re = null; |
| 1888 | + try{ |
| 1889 | + bav.set(1,list); |
| 1890 | + }catch(Exception ex){ |
| 1891 | + re = ex.getMessage(); |
| 1892 | + } |
| 1893 | + Assert.assertEquals("Error in BasicArrayVector.set(Object): BasicArrayVector.set(Object) requires a Vector, got: ArrayList", re); |
| 1894 | + } |
| 1895 | + @Test |
| 1896 | + public void test_BasicArrayVector_decimal_set_entity() throws Exception { |
| 1897 | + BasicArrayVector bav = new BasicArrayVector(DT_DECIMAL32_ARRAY, 3,2); |
| 1898 | + bav.set(0,new BasicDecimal32Vector(0,0,2)); |
| 1899 | + bav.set(1,new BasicDecimal32Vector(2,3,2)); |
| 1900 | + String[] tmp_string_v = {"0.0","-123.00432","132.204234","100.0"}; |
| 1901 | + BasicDecimal32Vector tmp_32_v = new BasicDecimal32Vector(tmp_string_v,2); |
| 1902 | + tmp_32_v.setNull(2); |
| 1903 | + bav.set(2,tmp_32_v); |
| 1904 | + assertEquals("[[],[0.00,0.00],[0.00,-123.00,,100.00]]",bav.getString()); |
| 1905 | + } |
| 1906 | + |
| 1907 | + @Test |
| 1908 | + public void test_BasicArrayVector_decimal_set_entity_not_support() throws Exception { |
| 1909 | + BasicArrayVector bav = new BasicArrayVector(DT_DECIMAL32_ARRAY, 2,2); |
| 1910 | + String re = null; |
| 1911 | + try{ |
| 1912 | + bav.set(0,new BasicDecimal32Vector(0,0,0)); |
| 1913 | + }catch(Exception ex){ |
| 1914 | + re = ex.getMessage(); |
| 1915 | + } |
| 1916 | + Assert.assertEquals("BasicArrayVector.set requires same scale for decimal types. Expected: 2, Got: 0", re); |
| 1917 | + |
| 1918 | + String re1 = null; |
| 1919 | + try{ |
| 1920 | + bav.set(0,new BasicDecimal64Vector(0,0,2)); |
| 1921 | + }catch(Exception ex){ |
| 1922 | + re1 = ex.getMessage(); |
| 1923 | + } |
| 1924 | + Assert.assertEquals("BasicArrayVector.set requires same data type. Expected: DT_DECIMAL32, Got: DT_DECIMAL64", re1); |
| 1925 | + |
| 1926 | + String re2 = null; |
| 1927 | + try{ |
| 1928 | + bav.set(0,new BasicBoolean((byte)0)); |
| 1929 | + }catch(Exception ex){ |
| 1930 | + re2 = ex.getMessage(); |
| 1931 | + } |
| 1932 | + Assert.assertEquals("BasicArrayVector.set requires a Vector value, got: BasicBoolean", re2); |
| 1933 | + |
| 1934 | + String re3 = null; |
| 1935 | + try{ |
| 1936 | + bav.set(0,new BasicDecimal32(0,2)); |
| 1937 | + }catch(Exception ex){ |
| 1938 | + re3 = ex.getMessage(); |
| 1939 | + } |
| 1940 | + Assert.assertEquals("BasicArrayVector.set requires a Vector value, got: BasicDecimal32", re3); |
| 1941 | + } |
1790 | 1942 | } |
0 commit comments