Beispiel #1
0
  @Test
  public void testAutoConvertNumeric() {
    Field a = Data.makeColumnField("field", null, new Object[] {1, 2, 3, 4});
    Field b = Auto.convert(a);
    assertEquals(a, b);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(false, b.isDate());
    Assert.assertEquals(2.5, b.numericProperty("mean"), 0.001);

    a = Data.makeColumnField("field", null, new Object[] {"1", "2", "3", "4"});
    b = Auto.convert(a);
    Assert.assertEquals(false, a == b);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(false, b.isDate());
    Assert.assertEquals(2.5, b.numericProperty("mean"), 0.001);

    a = Data.makeColumnField("field", null, new Object[] {"a", "2", "3", "4"});
    b = Auto.convert(a);
    Assert.assertEquals(false, a == b);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(false, b.isDate());
    Assert.assertEquals(3.0, b.numericProperty("mean"), 0.001);

    a = Data.makeColumnField("field", null, new Object[] {"a", "2", "c", "4"});
    b = Auto.convert(a);
    Assert.assertEquals(true, a == b);
    Assert.assertEquals(false, b.isNumeric());
    Assert.assertEquals(false, b.isDate());
  }
Beispiel #2
0
  @Test
  public void testChooseTransform() {
    Field a = Data.makeColumnField("a", "label", new Object[] {100, 200, 300, 400, 500, 600});
    Field b = Data.makeColumnField("b", "label", new Object[] {"a", "b", "c"});
    Field c = Data.makeColumnField("d", "label", new Object[] {1, 2, 2, 2, 2, 2, 2, 3});
    Field d = Data.makeColumnField("d", "label", new Object[] {1, 1, 1, 1, 1, 2, 2, 2, 5, 10});
    Field e =
        Data.makeColumnField("e", "label", new Object[] {1, 1, 1, 1, 1, 2, 2, 2, 5, 10, 100, 1000});
    Field f =
        Data.makeColumnField("f", "label", new Object[] {0, 1, 1, 1, 1, 2, 2, 2, 5, 10, 100, 1000});
    Field g =
        Data.makeColumnField(
            "g", "label", new Object[] {-1, 1, 1, 1, 1, 2, 2, 2, 5, 10, 100, 1000});

    Auto.setTransform(a);
    Auto.setTransform(b);
    Auto.setTransform(c);
    Auto.setTransform(d);
    Auto.setTransform(e);
    Auto.setTransform(f);
    Auto.setTransform(g);

    Assert.assertEquals("linear", a.stringProperty("transform"));
    Assert.assertEquals("linear", b.stringProperty("transform"));
    Assert.assertEquals("linear", c.stringProperty("transform"));
    Assert.assertEquals("root", d.stringProperty("transform"));
    Assert.assertEquals("log", e.stringProperty("transform"));
    Assert.assertEquals("root", f.stringProperty("transform"));
    Assert.assertEquals("linear", g.stringProperty("transform"));
  }
Beispiel #3
0
  @Test
  public void testLinearScale() {
    double[] pad = {0, 0};

    Field a = Data.makeColumnField("a", "label", new Object[] {2, 4, 7, 120, 45, 120, 200, 3345});
    a = Data.toNumeric(a);
    a.set("transform", "linear");
    Assert.assertEquals(
        "linear : 2 3345 : |500|1000|1500|2000|2500|3000",
        asString(NumericScale.makeLinearScale(a, false, 0.0, pad, 5, false), a));
    Assert.assertEquals(
        "linear : 2 3345 : |200|400|600|800|1000|1200|1400|1600|1800|2000|2200|2400|2600|2800|3000|3200",
        asString(NumericScale.makeLinearScale(a, false, 0.0, pad, 15, false), a));
    Assert.assertEquals(
        "linear : 2 3345 : |1000|2000|3000",
        asString(NumericScale.makeLinearScale(a, false, 0.0, pad, 2, false), a));
    Assert.assertEquals(
        "linear : 2 3345 : |2000",
        asString(NumericScale.makeLinearScale(a, false, 0.0, pad, 1, false), a));
    Assert.assertEquals(
        "linear : 0 3345 : |0|500|1000|1500|2000|2500|3000",
        asString(NumericScale.makeLinearScale(a, false, 0.01, pad, 7, false), a));
    Assert.assertEquals(
        "linear : 0 3500 : |0|500|1000|1500|2000|2500|3000|3500",
        asString(NumericScale.makeLinearScale(a, true, 0.0, pad, 7, false), a));

    a = Data.makeColumnField("a", "label", new Object[] {-22.2, -22.201, -22.9, -22.7});
    a = Data.toNumeric(a);
    Assert.assertEquals(
        "linear : -23 -22 : |-23|-22.8|-22.6|-22.4|-22.2|-22",
        asString(Auto.makeNumericScale(a, true, pad, 0.0, 5, false), a));
    Assert.assertEquals(
        "linear : -22.9 -22.2 : |-22.8|-22.6|-22.4|-22.2",
        asString(NumericScale.makeLinearScale(a, false, 0.0, pad, 4, false), a));
    Assert.assertEquals(
        "linear : -23 -22 : |-23|-22.5|-22",
        asString(Auto.makeNumericScale(a, true, pad, 0.0, 4, false), a));
    Assert.assertEquals(
        "linear : -23 -22 : |-23|-22.5|-22",
        asString(Auto.makeNumericScale(a, true, pad, 0.95, 4, false), a));
    Assert.assertEquals(
        "linear : -30 0 : |-30|-20|-10|0",
        asString(NumericScale.makeLinearScale(a, true, 0.99, pad, 4, false), a));
  }
Beispiel #4
0
  @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);
  }