public void testToList() throws Exception { StringBuilder result = new StringBuilder(); double[] doubleData = {0.5, 10000, 10.5}; NumberList.toList(CSVFormat.DECIMAL_POINT, result, doubleData); Assert.assertEquals("0.5,10000,10.5", result.toString()); result.setLength(0); NumberList.toList(CSVFormat.DECIMAL_COMMA, result, doubleData); Assert.assertEquals("0,5;10000;10,5", result.toString()); }
@Test public void testSingleDigit() { list1 = new NumberList("1"); assertNotNull("List is null while it shouldn't!", list1); assertFalse("List is empty while it shouldn't!", list1.isEmpty()); assertEquals("Wrong size", 1, list1.size()); assertEquals("Wrong value", new Byte((byte) 1), list1.get(0)); }
@After public void tearDown() { if (list1 != null) { list1.clear(); list1 = null; } if (list2 != null) { list2.clear(); list2 = null; } }
@Test public void testToString() { String value = "79483758967495604375647803561675463655464562565464565654634156134636"; list1 = new NumberList(value); assertNotNull("List is null while it shouldn't!", list1); assertFalse("List is empty while it shouldn't!", list1.isEmpty()); String res = list1.toDecimalString(); assertNotNull("Result is null while it shouldn't!", res); assertEquals("Wrong value", value, res); }
public void testFromList() throws Exception { double[] d = NumberList.fromList(CSVFormat.DECIMAL_POINT, "1,2.5,3000"); Assert.assertEquals(3, d.length); Assert.assertEquals(1, d[0], 0.1); Assert.assertEquals(2.5, d[1], 0.1); Assert.assertEquals(3000, d[2], 0.1); double[] d2 = NumberList.fromList(CSVFormat.DECIMAL_COMMA, "1;2,5;3000"); Assert.assertEquals(3, d2.length); Assert.assertEquals(1, d2[0], 0.1); Assert.assertEquals(2.5, d2[1], 0.1); Assert.assertEquals(3000, d2[2], 0.1); }
@Test public void testInvalidStringInput() { String value = "7948375896749s5604375fd647803561675463655464562565464565654634156134636"; list1 = new NumberList(value); assertNotNull("List is null while it shouldn't!", list1); assertTrue("List should be empty!", list1.isEmpty()); value = "-4"; list1 = new NumberList(value); assertNotNull("List is null while it shouldn't!", list1); assertTrue("List should be empty!", list1.isEmpty()); }