Exemplo n.º 1
0
 @Test
 public void testMultiplication() {
   assertEquals(2, Parser.parse("2*1"), 0.0001);
   assertEquals(0, Parser.parse("2*0"), 0.0001);
   assertEquals(3, Parser.parse("1*3"), 0.0001);
   assertEquals(176.5648, Parser.parse("16.88*10.46"), 0.0001);
 }
Exemplo n.º 2
0
 @Test
 public void testSubstraction() {
   assertEquals(1, Parser.parse("2-1"), 0.0);
   assertEquals(2, Parser.parse("2-0"), 0.0);
   assertEquals(-2, Parser.parse("1-3"), 0.0);
   assertEquals(6.42, Parser.parse("16.88-10.46"), 0.0001);
 }
Exemplo n.º 3
0
 @Test
 public void testAddition() {
   assertEquals(3, Parser.parse("1+2"), 0.0001);
   assertEquals(2, Parser.parse("0+2"), 0.0001);
   assertEquals(0, Parser.parse("0+0"), 0.0001);
   assertEquals(27.34, Parser.parse("16.88+10.46"), 0.00001);
 }
Exemplo n.º 4
0
 @Test
 public void testPower() {
   assertEquals(1, Parser.parse("3^0"), 0.0001);
   assertEquals(3, Parser.parse("3^1"), 0.0001);
   assertEquals(9, Parser.parse("3^2"), 0.0001);
   assertEquals(27, Parser.parse("3^3"), 0.0001);
 }
Exemplo n.º 5
0
 @Test
 public void field() throws Exception {
   System.out.println("field");
   Parser instance = new Parser();
   String test = "1X^1+1X^0";
   Polynomial poly = instance.stringToPoly(test, 2);
   FiniteField field = new FiniteField(poly);
   System.out.println(field);
 }
Exemplo n.º 6
0
 /** Test of getChannelList method, of class Parser. */
 @Test
 public void testGetChannelList() {
   System.out.println("getChannelList");
   Parser instance = new Parser(baseDir);
   Collection<File> result = instance.getChannelList();
   for (File channel : result) {
     System.out.println("Channels encontrados : " + channel.getName());
   }
   assertTrue(result != null && result.size() > 0);
 }
Exemplo n.º 7
0
 /** Test of getNotProcessedPackList method, of class Parser. */
 @Test
 public void testGetNotProcessedPackList() {
   System.out.println("getNotProcessedPackList");
   Parser instance = new Parser(baseDir);
   Collection<File> result = instance.getNotProcessedPackList();
   for (File pack : result) {
     System.out.println("Pack encontrado : " + pack.getName());
   }
   assertTrue(result != null && result.size() > 0);
 }
Exemplo n.º 8
0
 /** Test of evaluate method, of class Parser. */
 @Test
 public void testEvaluate() throws Exception {
   System.out.println("parseExpression");
   String input = "-2^3";
   String expResult = "";
   System.out.println(expResult);
   Parser instance = new Parser();
   String result = instance.evaluate(input);
   System.out.println(result);
   assertEquals(expResult, result);
 }
Exemplo n.º 9
0
  /** Test of getServerList method, of class Parser. */
  @Test
  public void testGetServerList() {
    System.out.println("getServerList");
    Parser instance = new Parser(baseDir);
    Collection<File> result = instance.getServerList();

    for (File server : result) {
      System.out.println("Server encontrado : " + server.getName());
    }

    assertTrue(result != null && result.size() > 0);
  }
 @Test
 public void testAddsElementToDocument() {
   Node songsBefore = beforeParser.getSongsNode();
   int countSongsBefore = songsBefore.getChildNodes().getLength();
   Node songsAfter = writer.getSongsNode();
   int countSongsAfter = songsAfter.getChildNodes().getLength();
   assertEquals(countSongsBefore + 1, countSongsAfter);
 }
Exemplo n.º 11
0
  @Test
  public void testWarnings() throws ParseException, TokeniserException {
    ArrayList<Warning> warnings = new ArrayList<>();
    Policy p1 = Parser.parse("frame-src aaa", "https://origin", warnings);

    assertEquals("frame-src aaa", p1.show());
    assertEquals(1, warnings.size());
    assertEquals(
        "The frame-src directive is deprecated as of CSP version 1.1. Authors who wish to govern nested browsing contexts SHOULD use the child-src directive instead.",
        warnings.iterator().next().message);
  }
Exemplo n.º 12
0
  @Test
  public void testParseTag() {
    Element elemento = new Element("p");
    Attr atributo = new Attr("name", "parrafo");
    Text texto = new Text("texto");

    elemento.setAttributeNode(atributo);
    elemento.appendChild(texto);
    Element elementoAComparar = parser.parse("<p name:\"parrafo\">texto</p>");
    assertEquals(elemento, elementoAComparar);
  }
public class XMLWriterTest {
  Parser beforeParser = createParser();
  int lengthOfListBefore = beforeParser.getSongsNode().getChildNodes().getLength();

  Composition testComposition =
      new Builder().byComposer("Francois Couperin").withTitle("Les Baricades Mysterieuses");

  XMLWriter writer = new XMLWriter(testComposition);

  @Test
  public void testReturnsDocument() {
    Document document = writer.getDocument();
    assertNotNull(document.getDocumentElement());
  }

  @Test
  public void testGetSongsNode() {
    Node songs = writer.getSongsNode();
    assertTrue(songs.getNodeName().equals("songs"));
  }

  @Test
  public void testAddsElementToDocument() {
    Node songsBefore = beforeParser.getSongsNode();
    int countSongsBefore = songsBefore.getChildNodes().getLength();
    Node songsAfter = writer.getSongsNode();
    int countSongsAfter = songsAfter.getChildNodes().getLength();
    assertEquals(countSongsBefore + 1, countSongsAfter);
  }

  private Parser createParser() {
    XMLToDocumentConverter converter = new XMLToDocumentConverter("RepertoireList.xml");
    Document document = converter.getDocument();
    Parser parser = new Parser(document);
    return parser;
  }
}
Exemplo n.º 14
0
 @Test(expected = IllegalArgumentException.class)
 public void testInvalidOpeningBracket() {
   Parser.parse("((2+1))");
 }
Exemplo n.º 15
0
  @Test
  public void testParseMulti() throws ParseException, TokeniserException {
    List<Policy> pl;
    ArrayList<Warning> warnings;

    pl =
        Parser.parseMulti(
            "script-src a; script-src b, , script-src c; script-src d", "https://origin.com");
    assertEquals(2, pl.size());
    assertEquals("script-src a", pl.get(0).show());
    assertEquals("script-src c", pl.get(1).show());

    pl = Parser.parseMulti("script-src a,", URI.parse("https://origin.com"));
    assertEquals(2, pl.size());
    assertEquals("script-src a", pl.get(0).show());
    assertEquals("", pl.get(1).show());

    warnings = new ArrayList<>();
    pl = Parser.parseMulti("script-src a,", URI.parse("https://origin.com"), warnings);
    assertEquals(2, pl.size());
    assertEquals("script-src a", pl.get(0).show());
    assertEquals("", pl.get(1).show());
    assertEquals(0, warnings.size());

    warnings = new ArrayList<>();
    pl = Parser.parseMulti("script-src a, sandbox", "https://origin.com", warnings);
    assertEquals(2, pl.size());
    assertEquals("script-src a", pl.get(0).show());
    assertEquals("sandbox", pl.get(1).show());
    assertEquals(0, warnings.size());

    warnings = new ArrayList<>();
    pl =
        ParserWithLocation.parseMulti(
            "   plugin-types  a/b  , script-src 'unsafe-redirect'", "https://origin.com", warnings);
    assertEquals(2, pl.size());
    assertEquals("plugin-types a/b", pl.get(0).show());
    assertEquals("script-src 'unsafe-redirect'", pl.get(1).show());
    assertEquals(1, warnings.size());
    assertEquals(
        "1:36: 'unsafe-redirect' has been removed from CSP as of version 2.0",
        warnings.get(0).show());

    warnings = new ArrayList<>();
    pl =
        ParserWithLocation.parseMulti(
            "script-src a, frame-src b", URI.parse("https://origin.com"), warnings);
    assertEquals(2, pl.size());
    assertEquals("script-src a", pl.get(0).show());
    assertEquals("frame-src b", pl.get(1).show());
    assertEquals(1, warnings.size());
    assertEquals(
        "1:15: The frame-src directive is deprecated as of CSP version 1.1. Authors who wish to govern nested browsing contexts SHOULD use the child-src directive instead.",
        warnings.get(0).show());

    try {
      pl.clear();
      pl = Parser.parseMulti("script-src a,b", "https://origin.com");
      fail();
    } catch (IllegalArgumentException e1) {
      assertEquals(0, pl.size());
      assertEquals("Unrecognised directive name: b", e1.getMessage());
    }

    try {
      ParserWithLocation.parse(
          "script-src a, script-src b", "https://origin.com", new ArrayList<>());
      fail();
    } catch (ParseException e1) {
      assertEquals(0, pl.size());
      assertEquals("1:13: expecting end of policy but found ,", e1.getMessage());
    }

    try {
      Parser.parse("script-src a, script-src b", "https://origin.com");
      fail();
    } catch (ParseException e1) {
      assertEquals(0, pl.size());
      assertEquals("expecting end of policy but found ,", e1.getMessage());
    }

    try {
      pl.clear();
      pl = ParserWithLocation.parseMulti("allow 'none', options", "https://origin.com");
      fail();
    } catch (ParseException e1) {
      assertEquals(0, pl.size());
      assertEquals(
          "1:1: The allow directive has been replaced with default-src and is not in the CSP specification.",
          e1.getMessage());
    }

    try {
      pl.clear();
      pl = ParserWithLocation.parseMulti("allow 'none', referrer", URI.parse("https://origin.com"));
      fail();
    } catch (ParseException e1) {
      assertEquals(0, pl.size());
      assertEquals(
          "1:1: The allow directive has been replaced with default-src and is not in the CSP specification.",
          e1.getMessage());
    }

    failsToParse("script-src *, ");
  }
Exemplo n.º 16
0
 @Test
 public void testNegatives() {
   assertEquals(-3, Parser.parse("-3"), 0.0001);
   assertEquals(12, Parser.parse("-3*-4"), 0.0001);
   assertEquals(-13, Parser.parse("-5+-8"), 0.0001);
 }
Exemplo n.º 17
0
 @Test
 public void testOperatorPriority() {
   assertEquals(22, Parser.parse("4+3*6"), 0.0001);
   assertEquals(9, Parser.parse("4+10/2"), 0.0001);
 }
Exemplo n.º 18
0
 @Test
 public void testBracketParsing() {
   assertEquals(13, Parser.parse("((2+1)*3)+4"), 0.0001);
   assertEquals(-1, Parser.parse("(2-5)/3"), 0.0001);
 }
Exemplo n.º 19
0
 @Test
 public void testSpaceStripping() {
   assertEquals(3, Parser.parse(" ( 3 ) "), 0.0001);
   assertEquals(3, Parser.parse(" ( 2 + 1 ) "), 0.0001);
   assertEquals(-3, Parser.parse(" ( 2 - 5 ) "), 0.0001);
 }
Exemplo n.º 20
0
 @Test
 public void testBracketStripping() {
   assertEquals(3, Parser.parse("(2+1)"), 0.0001);
   assertEquals(-3, Parser.parse("(2-5)"), 0.0001);
   assertEquals(4, Parser.parse("(2*5) - (3*2)"), 0.0001);
 }
Exemplo n.º 21
0
 @Test(expected = IllegalArgumentException.class)
 public void testDivisionByZeroAfterManyOperation() {
   String zeroFormula = "((((3*4)/2)/2)/3)*(17/3)/(3/17))-1";
   assertEquals(0, Parser.parse(zeroFormula), 0.000000001);
   Parser.parse("2/" + zeroFormula);
 }
Exemplo n.º 22
0
 @Test(expected = IllegalArgumentException.class)
 public void testDivisionByZero() {
   Parser.parse("2/0");
 }
Exemplo n.º 23
0
 @Test
 public void testDivision() {
   assertEquals(2, Parser.parse("2/1"), 0.0001);
   assertEquals(0.333333, Parser.parse("1/3"), 0.0001);
   assertEquals(1.6137, Parser.parse("16.88/10.46"), 0.0001);
 }