You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB

  1. package printer;
  2. import expression.*;
  3. import org.junit.Test;
  4. import static org.junit.Assert.*;
  5. public class ExpressionPrinterTest {
  6. final String identifierCode = "a";
  7. final Identifier identifier = new Identifier(identifierCode);
  8. final String integerCode = "42";
  9. final Int integer = new Int(42);
  10. final String additionCode = "a + 42";
  11. final Addition addition = new Addition(new Identifier("a"), new Int(42));
  12. final String subtractionCode = "1 - a";
  13. final Subtraction subtraction = new Subtraction(new Int(1), new Identifier("a"));
  14. @Test
  15. public void testVisitAddition() {
  16. ExpressionPrinter printer = new ExpressionPrinter();
  17. assertEquals(additionCode, printer.getValue(addition));
  18. }
  19. @Test
  20. public void testVisitIdentifier() {
  21. ExpressionPrinter printer = new ExpressionPrinter();
  22. assertEquals(identifierCode, printer.getValue(identifier));
  23. }
  24. @Test
  25. public void testVisitInt() {
  26. ExpressionPrinter printer = new ExpressionPrinter();
  27. assertEquals(integerCode, printer.getValue(integer));
  28. }
  29. @Test
  30. public void testVisitSubtraction() {
  31. ExpressionPrinter printer = new ExpressionPrinter();
  32. assertEquals(subtractionCode, printer.getValue(subtraction));
  33. }
  34. }