transcendental-lisp/test/function/builtin/math/DIVIDETest.java

80 lines
2.1 KiB
Java
Raw Normal View History

package function.builtin.math;
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;
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;
import testutil.SymbolAndFunctionCleaner;
public class DIVIDETest extends SymbolAndFunctionCleaner {
@Test
public void divideWithOne() {
String input = "(/ 1)";
assertSExpressionsMatch(parseString("1"), evaluateString(input));
}
@Test
public void divideWithTwo() {
String input = "(/ 2)";
assertSExpressionsMatch(parseString("0"), evaluateString(input));
}
@Test
public void divideTwoNumbers() {
String input = "(/ 24 3)";
assertSExpressionsMatch(parseString("8"), evaluateString(input));
}
@Test
public void divideSeveralNumbers() {
String input = "(/ 256 2 2 8)";
assertSExpressionsMatch(parseString("8"), evaluateString(input));
}
@Test
public void divideTwoNumbersWithRemainder() {
String input = "(/ 9 2)";
assertSExpressionsMatch(parseString("4"), evaluateString(input));
}
@Test
public void divideSeveralNumbersWithRemainder() {
String input = "(/ 19 2 5)";
assertSExpressionsMatch(parseString("1"), evaluateString(input));
}
@Test(expected = BadArgumentTypeException.class)
public void divideWithNonNumber() {
evaluateString("(/ 'x)");
}
@Test(expected = TooFewArgumentsException.class)
public void divideWithTooFewArguments() {
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());
}
}