package lab.art; import static org.junit.Assert.*; import java.util.Random; import org.junit.Test; public class AverageTester { @Test public void testConstructor() { final int NUMBER =10; Expression expression = new VariableX(); Expression second = new VariableX(); for (int n = 0; n < NUMBER; n++) { expression = new Average(expression, second); } } @Test public void testEvaluate() { Random random = new Random(System.currentTimeMillis()); int NUMBER = 10; double DELTA = 0.0001; for (int n = 0; n < NUMBER; n++) { Expression expression = new VariableX(); Expression second = new VariableY(); double x = random.nextDouble(); if (random.nextBoolean()) { x = -x; } double y = random.nextDouble(); if (random.nextBoolean()) { y = -y; } double value = x; for (int m = 0; m < NUMBER; m++) { expression = new Average(expression, second); value = (value + y) / 2; assertEquals("evaluate method failed", value, expression.evaluate(x, y), DELTA); } } } @Test public void testToString() { Expression expression = new VariableX(); Expression second = new VariableY(); String representation = "x"; int NUMBER = 10; for (int n = 0; n < NUMBER; n++) { expression = new Average(expression, second); representation = "average(" + representation + ", y)"; assertEquals("toString method failed", representation, expression.toString()); } } }