Package net.sourceforge.chaperon.test

Source Code of net.sourceforge.chaperon.test.SymbolListTestCase

/*
*  Copyright (C) Chaperon. All rights reserved.
*  -------------------------------------------------------------------------
*  This software is published under the terms of the Apache Software License
*  version 1.1, a copy of which has been included  with this distribution in
*  the LICENSE file.
*/

package net.sourceforge.chaperon.test;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import net.sourceforge.chaperon.model.symbol.Nonterminal;
import net.sourceforge.chaperon.model.symbol.SymbolList;
import net.sourceforge.chaperon.model.symbol.Terminal;

public class SymbolListTestCase extends TestCase
{
  private Terminal a;
  private Terminal b;
  private Terminal c;
  private Nonterminal A;
  private Nonterminal B;
  private Nonterminal C;

  public SymbolListTestCase()
  {
    super("SymbolListTestCase");
  }

  public void setUp()
  {
    a = new Terminal("a");
    b = new Terminal("b");
    c = new Terminal("c");

    A = new Nonterminal("A");
    B = new Nonterminal("B");
    C = new Nonterminal("C");
  }

  public static void assertNotEquals(String message, Object a, Object b)
  {
    if ((a==null) || (a==null))
      return;

    if (a.equals(b))
    {
      String formatted = "";
      if (message!=null)
        formatted = message+" ";

      fail(formatted+"<"+a+"> equals <"+b+">");
    }
  }

  public void runTest() throws Throwable
  {
    SymbolList list = new SymbolList();

    assertEquals("Test if list is empty", 0, list.getSymbolCount());
    assertEquals("Test if list is empty", true, list.isEmpty());

    list.addSymbol(a);

    assertEquals("Test if list is not empty", 1, list.getSymbolCount());
    assertEquals("Test if list is not empty", false, list.isEmpty());

    assertEquals("Test if symbols are equal", a, list.getSymbol(0));

    list.addSymbol(a);
    list.addSymbol(A);
    list.addSymbol(b);
    list.addSymbol(B);
    list.addSymbol(c);
    list.addSymbol(C);

    assertEquals("Test if list is not empty", 7, list.getSymbolCount());
    assertEquals("Test if list is not empty", false, list.isEmpty());

    assertEquals("Test if symbols are equal", a, list.getSymbol(0));
    assertEquals("Test if symbols are equal", a, list.getSymbol(1));
    assertEquals("Test if symbols are equal", B, list.getSymbol(4));
    assertEquals("Test if symbols are equal", C, list.getSymbol(6));

    assertEquals("Test if indices are equal", 0, list.indexOf(a));
    assertEquals("Test if indices are equal", 5, list.indexOf(c));

    SymbolList list2 = new SymbolList();

    list2.addSymbol(a);
    list2.addSymbol(a);
    list2.addSymbol(A);
    list2.addSymbol(b);

    assertNotEquals("Test if lists are not equal", list, list2);

    list2.addSymbol(B);
    list2.addSymbol(c);
    list2.addSymbol(C);

    assertEquals("Test if lists are equal", list, list2);

    SymbolList list3 = new SymbolList();

    list3.addSymbol(a);
    list3.addSymbol(A);
    list3.addSymbol(b);
    list3.addSymbol(B);
    list3.addSymbol(c);
    list3.addSymbol(C);
    list3.addSymbol(a);

    assertNotEquals("Test if lists are not equal", list, list3);
  }

  public static Test suite()
  {
    TestSuite suite = new TestSuite("Symbol list tests");
    suite.addTest(new SymbolListTestCase());
    return suite;
  }
}
TOP

Related Classes of net.sourceforge.chaperon.test.SymbolListTestCase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.