package com.wesleyhome.math.equation;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.wesleyhome.math.equation.AbsoluteValueFunction;
import com.wesleyhome.math.equation.SmartNumber;
@RunWith(Parameterized.class)
public class AbsoluteValueFunctionTest {
private final Number value;
@Parameters
public static List<Object[]> data() throws Exception {
return Arrays.asList(new Object[][] {
{
-25
}, {
25
}, {
-25.2
}, {
25.2
}
});
}
public AbsoluteValueFunctionTest(final Number value) {
this.value = value;
}
private AbsoluteValueFunction function;
@Before
public void setUp() throws Exception {
function = new AbsoluteValueFunction();
}
@Test
public void testEvaluate() throws Exception {
Number evaluate = function.evaluate(value, null);
assertThat(evaluate, is(equalTo(SmartNumber.eq(value).absoluteValue())));
}
}