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

118 lines
3.1 KiB
Java
Raw Normal View History

2018-01-12 21:02:29 -05:00
package function.builtin.math;
2018-01-13 08:52:29 -05:00
import static testutil.TestUtilities.assertIsErrorWithMessage;
2018-01-12 21:02:29 -05:00
import static testutil.TestUtilities.assertSExpressionsMatch;
import static testutil.TestUtilities.evaluateString;
import org.junit.Test;
import function.ArgumentValidator.BadArgumentTypeException;
import function.ArgumentValidator.TooFewArgumentsException;
import function.ArgumentValidator.TooManyArgumentsException;
import function.builtin.math.MODULO.ModulusNotPositiveException;
import sexpression.LispNumber;
import testutil.SymbolAndFunctionCleaner;
public class MODULOTest extends SymbolAndFunctionCleaner {
@Test
public void mod() {
String input = "(mod 5 3)";
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
}
@Test
public void modulo() {
String input = "(modulo 11 7)";
assertSExpressionsMatch(new LispNumber("4"), evaluateString(input));
}
@Test
public void moduloSymbol() {
String input = "(% 8 5)";
assertSExpressionsMatch(new LispNumber("3"), evaluateString(input));
}
@Test
public void dividendGreaterThanDivisor() {
String input = "(mod 21 19)";
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
}
@Test
public void dividendLessThanDivisor() {
String input = "(mod 5 239)";
assertSExpressionsMatch(new LispNumber("5"), evaluateString(input));
}
@Test
public void dividendEqualToDivisor() {
String input = "(mod 5 5)";
assertSExpressionsMatch(new LispNumber("0"), evaluateString(input));
}
@Test
public void dividendMultipleOfDivisor() {
String input = "(mod 20 5)";
assertSExpressionsMatch(new LispNumber("0"), evaluateString(input));
}
@Test
public void divisorOfOne() {
String input = "(mod 5 1)";
assertSExpressionsMatch(new LispNumber("0"), evaluateString(input));
}
@Test
public void dividendOfZero() {
String input = "(mod 0 2309)";
assertSExpressionsMatch(new LispNumber("0"), evaluateString(input));
}
@Test
public void negativeDividend() {
String input = "(mod -23 25)";
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
}
@Test(expected = ModulusNotPositiveException.class)
2018-01-13 08:52:29 -05:00
public void negativeDivisor() {
evaluateString("(mod 5 -10)");
2018-01-12 21:02:29 -05:00
}
@Test(expected = ModulusNotPositiveException.class)
2018-01-13 08:52:29 -05:00
public void divisorOfZero() {
evaluateString("(mod 5 0)");
2018-01-12 21:02:29 -05:00
}
@Test(expected = BadArgumentTypeException.class)
public void modWithNonNumber() {
evaluateString("(mod 'a 'b)");
}
@Test(expected = TooFewArgumentsException.class)
public void modWithTooFewArguments() {
evaluateString("(mod 1)");
}
@Test(expected = TooManyArgumentsException.class)
public void modWithTooManyArguments() {
evaluateString("(mod 1 2 3)");
}
2018-01-13 08:52:29 -05:00
@Test
public void moduloNotPositiveException_HasCorrectAttributes() {
assertIsErrorWithMessage(new ModulusNotPositiveException());
}
2018-01-12 21:02:29 -05:00
}