2017-01-14 18:01:14 -05:00
|
|
|
package function.builtin.math;
|
2016-12-29 13:32:45 -05:00
|
|
|
|
2017-11-18 18:01:00 -05:00
|
|
|
import static testutil.TestUtilities.assertIsErrorWithMessage;
|
2017-11-12 09:42:25 -05:00
|
|
|
import static testutil.TestUtilities.assertSExpressionsMatch;
|
|
|
|
import static testutil.TestUtilities.evaluateString;
|
|
|
|
import static testutil.TestUtilities.parseString;
|
2016-12-29 13:32:45 -05:00
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2017-11-12 09:42:25 -05:00
|
|
|
import function.ArgumentValidator.BadArgumentTypeException;
|
|
|
|
import function.ArgumentValidator.TooFewArgumentsException;
|
2017-11-18 18:01:00 -05:00
|
|
|
import function.builtin.math.DIVIDE.DivideByZeroException;
|
2017-07-19 15:23:15 -04:00
|
|
|
import testutil.SymbolAndFunctionCleaner;
|
2016-12-29 13:32:45 -05:00
|
|
|
|
2017-07-19 15:23:15 -04:00
|
|
|
public class DIVIDETest extends SymbolAndFunctionCleaner {
|
2016-12-29 13:32:45 -05:00
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void divideWithOne() {
|
2016-12-29 13:32:45 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void divideWithTwo() {
|
2016-12-29 13:32:45 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void divideTwoNumbers() {
|
2016-12-29 13:32:45 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void divideSeveralNumbers() {
|
2016-12-29 13:32:45 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void divideTwoNumbersWithRemainder() {
|
2016-12-29 13:32:45 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void divideSeveralNumbersWithRemainder() {
|
2016-12-29 13:32:45 -05:00
|
|
|
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)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void divideWithNonNumber() {
|
2016-12-29 13:32:45 -05:00
|
|
|
evaluateString("(/ 'x)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void divideWithTooFewArguments() {
|
2016-12-29 13:32:45 -05:00
|
|
|
evaluateString("(/)");
|
|
|
|
}
|
|
|
|
|
2017-11-18 18:01:00 -05:00
|
|
|
@Test(expected = DivideByZeroException.class)
|
|
|
|
public void divideByZero() {
|
|
|
|
evaluateString("(/ 2 0)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void divideByZeroException_HasCorrectAttributes() {
|
|
|
|
assertIsErrorWithMessage(new DivideByZeroException());
|
|
|
|
}
|
|
|
|
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|