### Question:
Equilateral implements Serializable { public final double[] encode(final int set) { if (set < 0 || set > this.matrix.length) { throw new AIFHError("Class out of range for equilateral: " + set); } return this.matrix[set]; } Equilateral(final int count, final double low, final double high); final int decode(final double[] activations); final double[] encode(final int set); final double getDistance(final double[] data, final int set); static final int MIN_EQ; }### Answer:
@Test public void testEncode() { final Equilateral eq = new Equilateral(3, -1, 1); final double[] d = eq.encode(1); assertEquals(0.8660254037844386, d[0], AIFH.DEFAULT_PRECISION); assertEquals(-0.5, d[1], AIFH.DEFAULT_PRECISION); }
@Test(expected = AIFHError.class) public void testError() { final Equilateral eq = new Equilateral(3, -1, 1); eq.encode(10); }
@Test public void testAllEqual() { final Equilateral eq = new Equilateral(10, -1, 1); final CalculateDistance dc = new EuclideanDistance(); double compareDist = 0; for (int x = 0; x < 10; x++) { double[] baseClass = eq.encode(x); for (int y = 0; y < 10; y++) { if (x != y) { double[] otherClass = eq.encode(y); double dist = dc.calculate(baseClass, otherClass); if (compareDist < AIFH.DEFAULT_PRECISION) { compareDist = dist; } else { assertEquals(compareDist, dist, AIFH.DEFAULT_PRECISION); } } } } }