@Test public void testIsEqualTo() { for (int i = 0; i < 100; i++) { intColumn.add(i); } assertEquals(1, intColumn.isEqualTo(10).size()); }
@Test public void testIsLessThan() { for (int i = 0; i < 100; i++) { intColumn.add(i); } assertEquals(50, intColumn.isLessThan(50).size()); }
@Test public void testIsGreaterThan() { for (int i = 0; i < 100; i++) { intColumn.add(i); } assertEquals(49, intColumn.isGreaterThan(50).size()); }
@Test public void testMin() { for (int i = 0; i < 100; i++) { intColumn.add(i); } assertEquals(0.0, intColumn.min(), .001); }
@Test public void testMax() { for (int i = 0; i < 100; i++) { intColumn.add(i); } assertEquals(99, intColumn.max(), .001); }
@Test public void testSum() { for (int i = 0; i < 100; i++) { intColumn.add(1); } assertEquals(100, intColumn.sum()); }
@Test public void testPercents() { for (int i = 0; i < 100; i++) { intColumn.add(i); } FloatColumn floatColumn = intColumn.asRatio(); assertEquals(1.0, floatColumn.sum(), 0.1); }
@Test public void testIsLessThanOrEqualTo() { for (int i = 0; i < 100; i++) { intColumn.add(i); } assertEquals(51, intColumn.isLessThanOrEqualTo(50).size()); assertEquals(49, intColumn.isLessThanOrEqualTo(50).get(49)); }
@Test public void testIsGreaterThanOrEqualTo() { for (int i = 0; i < 100; i++) { intColumn.add(i); } assertEquals(50, intColumn.isGreaterThanOrEqualTo(50).size()); assertEquals(50, intColumn.isGreaterThanOrEqualTo(50).get(0)); }
@Test public void testDivide2() { int[] originalValues = new int[] {32, 42, 40, 57, 52, -2}; IntColumn originals = IntColumn.create("Originals", new IntArrayList(originalValues)); Table t = Table.create("t", originals); FloatColumn divided = originals.divide(3.3); System.out.println(divided.print()); }
@Test public void testSelectIf() { for (int i = 0; i < 100; i++) { intColumn.add(i); } IntPredicate predicate = value -> value < 10; IntColumn column1 = intColumn.selectIf(predicate); assertEquals(10, column1.size()); for (int i = 0; i < 10; i++) { assertTrue(column1.get(i) < 10); } }
@Test public void testIntIsIn() { int[] originalValues = new int[] {32, 42, 40, 57, 52, -2}; int[] inValues = new int[] {10, -2, 57, -5}; IntColumn inColumn = IntColumn.create("In", new IntArrayList(inValues)); IntColumn initial = new IntColumn("Test", originalValues.length); Table t = Table.create("t", initial); for (int value : originalValues) { initial.add(value); } Filter filter = column("Test").isIn(inColumn); Table result = t.selectWhere(filter); System.out.println(result.print()); }
/** * Returns a representation of of the population in the form of a table, where each row represents * one individual, one parameter per column, and the last column containing the objective value. * * @returns a table represeting the population. */ public Table getTable() { Table vt; int rowCount = solutions.length; int colCount = ranges.length + 1; Column[] cols = new Column[colCount]; // make a column for each range for (int i = 0; i < ranges.length; i++) { Column c; if (ranges[i] instanceof DoubleRange) { c = new DoubleColumn(rowCount); for (int j = 0; j < rowCount; j++) { double d = solutions[j].getDoubleParameter(i); ((DoubleColumn) c).setDouble(d, j); } } else if (ranges[i] instanceof IntRange) { c = new IntColumn(rowCount); for (int j = 0; j < rowCount; j++) { int in = (int) solutions[j].getDoubleParameter(i); ((IntColumn) c).setInt(in, j); } } else if (ranges[i] instanceof BinaryRange) { c = new BooleanColumn(rowCount); for (int j = 0; j < rowCount; j++) { boolean b = (solutions[j].getDoubleParameter(i) > 0); ((BooleanColumn) c).setBoolean(b, j); } } else { // i guess default to a double column c = new DoubleColumn(rowCount); for (int j = 0; j < rowCount; j++) { double d = solutions[j].getDoubleParameter(i); ((DoubleColumn) c).setDouble(d, j); } } c.setLabel(ranges[i].getName()); cols[i] = c; } // now the objective DoubleColumn objC = new DoubleColumn(rowCount); objC.setLabel(objConstraints.getName()); for (int j = 0; j < rowCount; j++) { objC.setDouble(solutions[j].getObjective(), j); } cols[colCount - 1] = objC; vt = new MutableTableImpl(cols); return vt; }
@Test public void testDifference() { int[] originalValues = new int[] {32, 42, 40, 57, 52}; int[] expectedValues = new int[] {IntColumn.MISSING_VALUE, 10, -2, 17, -5}; IntColumn initial = new IntColumn("Test", originalValues.length); for (int value : originalValues) { initial.add(value); } IntColumn difference = initial.difference(); assertEquals( "Both sets of data should be the same size.", expectedValues.length, difference.size()); for (int index = 0; index < difference.size(); index++) { int actual = difference.get(index); assertEquals( "difference operation at index:" + index + " failed", expectedValues[index], actual); } }