2017-01-14 18:01:14 -05:00
|
|
|
package function.builtin.math;
|
2016-12-29 13:32:45 -05:00
|
|
|
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import function.ArgumentValidator.*;
|
|
|
|
|
|
|
|
public class DIVIDETester {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDivideWithOne() {
|
|
|
|
String input = "(/ 1)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDivideWithTwo() {
|
|
|
|
String input = "(/ 2)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("0"), evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDivideTwoNumbers() {
|
|
|
|
String input = "(/ 24 3)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("8"), evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDivideSeveralNumbers() {
|
|
|
|
String input = "(/ 256 2 2 8)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("8"), evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDivideTwoNumbersWithRemainder() {
|
|
|
|
String input = "(/ 9 2)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("4"), evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDivideSeveralNumbersWithRemainder() {
|
|
|
|
String input = "(/ 19 2 5)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
|
|
|
public void testDivideWithNonNumber() {
|
|
|
|
evaluateString("(/ 'x)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
|
|
|
public void testDivideWithTooFewArguments() {
|
|
|
|
evaluateString("(/)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|