Пример #1
0
  @Test
  public void testBasicFieldStats() {
    Field f = Data.makeColumnField("a", "label", new Object[] {"1", "2", "a", "2", null, 0});
    Field g = Data.makeColumnField("a", "label", new Object[] {100, 200, 400, 500, 600});
    Field h = Data.makeColumnField("a", "label", new Object[] {"a", "b", "c", "c"});
    Field i = Data.makeIndexingField("a", "label", 20);
    Field c = Data.makeConstantField("a", "label", 5.0, 2000);

    assertEquals(0, f.min(), 0.01);
    assertEquals(2, f.max(), 0.01);

    assertEquals(100, g.min(), 0.01);
    assertEquals(600, g.max(), 0.01);

    assertEquals(null, h.min());
    assertEquals(null, h.max());

    assertEquals(1, i.min(), 0.01);
    assertEquals(20, i.max(), 0.01);

    assertEquals(5.0, c.min(), 0.01);
    assertEquals(5.0, c.max(), 0.01);

    int[] counts = (int[]) h.property("categoryCounts");
    Assert.assertEquals(1, counts[0]);
    Assert.assertEquals(1, counts[1]);
    Assert.assertEquals(2, counts[2]);

    assertEquals(4, f.uniqueValuesCount());
    assertEquals(5, g.uniqueValuesCount());
    assertEquals(3, h.uniqueValuesCount());
    assertEquals(20, i.uniqueValuesCount());
    assertEquals(1, c.uniqueValuesCount());
  }
Пример #2
0
 @Test
 public void testIndexing() {
   Field a = Data.makeIndexingField("a", "b", 30);
   assertEquals("a", a.name);
   assertEquals("b", a.label);
   assertEquals(30, a.rowCount());
   assertEquals(30, a.getNumericProperty("valid"), 0.001);
   assertEquals(30, a.getNumericProperty("validNumeric"), 0.001);
   assertEquals(30, a.getNumericProperty("unique"), 0.001);
   assertEquals(15.5, a.getNumericProperty("mean"), 0.001);
   assertEquals(3, a.value(2));
   assertEquals(8, a.value(7));
   assertEquals(true, a.hasProperty("numeric"));
 }
Пример #3
0
 @Test
 public void testPermute() {
   Field base = Data.makeIndexingField("a", "b", 10);
   Field a = Data.permute(base, new int[] {0, 0, 0, 1, 1, 2, 2, 3}, false);
   assertEquals(true, a.hasProperty("numeric"));
   assertEquals("a", a.name);
   assertEquals("b", a.label);
   assertEquals(8, a.rowCount());
   assertEquals(8, a.getNumericProperty("valid"), 0.001);
   assertEquals(8, a.getNumericProperty("validNumeric"), 0.001);
   assertEquals(4, a.getNumericProperty("unique"), 0.001);
   assertEquals((1 + 1 + 1 + 2 + 2 + 3 + 3 + 4) / 8.0, a.getNumericProperty("mean"), 0.001);
   assertEquals(1, a.value(1));
   assertEquals(1, a.value(2));
   assertEquals(4, a.value(7));
   assertEquals("1, 2, 3, 4", Data.join(a.categories()));
 }