2017-01-14 18:01:14 -05:00
|
|
|
package function.builtin.predicate;
|
2016-12-29 13:32:45 -05:00
|
|
|
|
2017-01-27 11:37:11 -05:00
|
|
|
import static testutil.TestUtilities.evaluateString;
|
|
|
|
import static testutil.TypeAssertions.*;
|
2016-12-29 13:32:45 -05:00
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import function.ArgumentValidator.*;
|
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 EQTest extends SymbolAndFunctionCleaner {
|
2016-12-29 13:32:45 -05:00
|
|
|
|
|
|
|
@Test
|
2017-02-28 11:54:19 -05:00
|
|
|
public void eqWithEqualAtoms() {
|
2016-12-29 13:32:45 -05:00
|
|
|
String input = "(eq 1 1)";
|
|
|
|
|
2017-01-27 11:37:11 -05:00
|
|
|
assertT(evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
2017-03-07 13:15:40 -05:00
|
|
|
@Test
|
|
|
|
public void eqWithEqualAtomsAndAlias() {
|
|
|
|
String input = "(eq? 1 1)";
|
|
|
|
|
|
|
|
assertT(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
2016-12-29 13:32:45 -05:00
|
|
|
@Test
|
2017-02-28 11:54:19 -05:00
|
|
|
public void eqWithUnequalAtoms() {
|
2016-12-29 13:32:45 -05:00
|
|
|
String input = "(eq 1 2)";
|
|
|
|
|
2017-01-27 11:37:11 -05:00
|
|
|
assertNil(evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
2017-01-27 11:37:11 -05:00
|
|
|
|
2016-12-29 13:32:45 -05:00
|
|
|
@Test
|
2017-02-28 11:54:19 -05:00
|
|
|
public void eqWithTwoEqualNumbers() {
|
|
|
|
String input = "(eq -4 -4)";
|
|
|
|
|
|
|
|
assertT(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void eqWithTwoUnequalNumbers() {
|
|
|
|
String input = "(eq +5 +7)";
|
|
|
|
|
|
|
|
assertNil(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void eqWithTwoEqualStrings() {
|
|
|
|
String input = "(eq \"potato\" \"potato\")";
|
|
|
|
|
|
|
|
assertT(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void eqWithTwoUnequalStrings() {
|
|
|
|
String input = "(eq \"tomato\" \"potato\")";
|
|
|
|
|
|
|
|
assertNil(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void eqWithTwoDifferentCasedStrings() {
|
|
|
|
String input = "(eq \"Potato\" \"potato\")";
|
|
|
|
|
|
|
|
assertNil(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void eqWithAtomAndList() {
|
2016-12-29 13:32:45 -05:00
|
|
|
String input = "(eq 1 '(2))";
|
|
|
|
|
2017-01-27 11:37:11 -05:00
|
|
|
assertNil(evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-02-28 11:54:19 -05:00
|
|
|
public void eqWithSameList() {
|
2017-03-07 16:41:26 -05:00
|
|
|
String initializeL1 = "(setq l1 '(1 2 3))";
|
|
|
|
String initializeL2 = "(setq l2 l1)";
|
2016-12-29 13:32:45 -05:00
|
|
|
String input = "(eq l1 l2)";
|
|
|
|
|
|
|
|
evaluateString(initializeL1);
|
|
|
|
evaluateString(initializeL2);
|
|
|
|
|
2017-01-27 11:37:11 -05:00
|
|
|
assertT(evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-02-28 11:54:19 -05:00
|
|
|
public void eqWithEqualLists() {
|
2016-12-29 13:32:45 -05:00
|
|
|
String input = "(eq '(1 2) '(1 2))";
|
|
|
|
|
2017-01-27 11:37:11 -05:00
|
|
|
assertNil(evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-02-28 11:54:19 -05:00
|
|
|
public void eqWithUnequalLists() {
|
2016-12-29 13:32:45 -05:00
|
|
|
String input = "(eq '(1 2) '(3 4))";
|
|
|
|
|
2017-01-27 11:37:11 -05:00
|
|
|
assertNil(evaluateString(input));
|
2016-12-29 13:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
2017-02-28 11:54:19 -05:00
|
|
|
public void eqWithTooManyArguments() {
|
2016-12-29 13:32:45 -05:00
|
|
|
evaluateString("(eq 'one 'two 'three)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
2017-02-28 11:54:19 -05:00
|
|
|
public void eqWithTooFewArguments() {
|
2016-12-29 13:32:45 -05:00
|
|
|
evaluateString("(eq 'one)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|