@Test public void testMakingField() { Field f = Data.makeColumnField("a", "label", new Object[] {"1", "2", "a", "2", null, 1}); assertEquals("a", f.name); assertEquals("label", f.label); assertEquals(6, f.rowCount()); assertEquals(5, f.valid()); }
@Test public void testAutoConvertDate() { // Make some dates Date d1 = Data.asDate("1971-1-3"); Date d2 = Data.asDate("1971-1-9"); Date d3 = Data.asDate("1971-1-31"); Field a = Data.makeColumnField("field", null, new Object[] {d1, d2, d3, null}); Field b = Auto.convert(a); Assert.assertEquals(true, b.isNumeric()); Assert.assertEquals(true, b.isDate()); // Should ignore one error a = Data.makeColumnField("field", null, new Object[] {d1, d2, "oops", d3, null, null}); b = Auto.convert(a); Assert.assertEquals(true, b.isNumeric()); Assert.assertEquals(true, b.isDate()); assertEquals(3, b.valid()); a = Data.makeColumnField("field", null, new Object[] {"1971-1-3", "1971-1-12"}); b = Auto.convert(a); Assert.assertEquals(true, b.isNumeric()); Assert.assertEquals(true, b.isDate()); assertEquals(2, b.valid()); assertEquals(9.0, b.max() - b.min(), 0.001); a = Data.makeColumnField("field", null, new Object[] {1970, 1972, 1978}); b = Auto.convert(a); Assert.assertEquals(true, b.isNumeric()); Assert.assertEquals(true, b.isDate()); assertEquals(3, b.valid()); assertEquals(8 * 365 + 2, b.max() - b.min(), 0.001); a = Data.makeColumnField("field", null, new Object[] {1970, 1971.5, 1978}); b = Auto.convert(a); Assert.assertEquals(true, b.isNumeric()); Assert.assertEquals(false, b.isDate()); assertEquals(3, b.valid()); assertEquals(8, b.max() - b.min(), 0.001); }
@Test public void testDateConversionForBadDates() { Object[] data = new Object[1000]; for (int i = 0; i < data.length; i++) data[i] = i % 10 == 0 ? "name" : "-"; Field f = Data.makeColumnField("a", "label", data); Field g = Data.toDate(f); assertNotEquals(f, g); assertEquals("a", g.name); assertEquals("label", g.label); assertEquals(1000, g.rowCount()); assertEquals(0, g.valid()); }
@Test public void testNumericConversion() { Field f = Data.makeColumnField("a", "label", new Object[] {"1", "2", "a", "2", null, 1}); Field g = Data.toNumeric(f); assertNotEquals(f, g); assertEquals("a", g.name); assertEquals("label", g.label); assertEquals(6, g.rowCount()); assertEquals(4, g.valid()); // Should not change assertEquals(g, Data.toNumeric(g)); }
@Test public void testDateConversion() { Field f = Data.makeColumnField( "a", "label", new Object[] {"Jan 4, 1980", "Jan 4, 1988", "a", "2", null, "Jan 9, 1978"}); Field g = Data.toDate(f, null); assertNotEquals(f, g); assertEquals("a", g.name); assertEquals("label", g.label); assertEquals(6, g.rowCount()); assertEquals(3, g.valid()); // Should not change assertEquals(g, Data.toDate(g, null)); }