public void testHeadConstructor(){
        try{
            try{
                StringReader sr = new StringReader("");
                Lex lex = new Lex(sr);
                ExtendedHead head = new ExtendedHead(lex);
                assertTrue(false);
            }catch(ParserException e){
                assertTrue(true);
            };

            try{
                StringReader sr = new StringReader("==(A,B,C");
                Lex lex = new Lex(sr);
                ExtendedHead head = new ExtendedHead(lex);
                assertTrue(false);
            }catch(ParserException e){
                assertTrue(true);
            };

            try{
                StringReader sr = new StringReader("A");
                Lex lex = new Lex(sr);
                ExtendedHead head = new ExtendedHead(lex);
                assertTrue(false);
            }catch(ParserException e){
                assertTrue(true);
            };

            try{
                StringReader sr = new StringReader("A(");
                Lex lex = new Lex(sr);
                ExtendedHead head = new ExtendedHead(lex);
                assertTrue(false);
            }catch(ParserException e){
                assertTrue(true);
            };

            try{
                StringReader sr = new StringReader("A()");
                Lex lex = new Lex(sr);
                ExtendedHead head =
                    new ExtendedHead(lex);
                assertTrue(false);
            }catch(ParserException e){
                assertTrue(true);
            };

            try{
                StringReader sr = new StringReader("A('a')");
                Lex lex = new Lex(sr);
                ExtendedHead head =
                    new ExtendedHead(lex);
                assertTrue(false);
            }catch(ParserException e){
                assertTrue(true);
            };


            try{
                StringReader sr = new StringReader("A(A B)");
                Lex lex = new Lex(sr);
                ExtendedHead head =
                    new ExtendedHead(lex);
                assertTrue(false);
            }catch(ParserException e){
                assertTrue(true);
            };

            try{
                StringReader sr = new StringReader("A(X,)");
                Lex lex = new Lex(sr);
                ExtendedHead head =
                    new ExtendedHead(lex);
                assertTrue(false);
            }catch(ParserException e){
                assertTrue(true);
            };

            StringReader sr = new StringReader("Apple(Id1)");
            Lex lex = new Lex(sr);
            ExtendedHead head = new ExtendedHead(lex);
            ArrayList<Node> nodes = head.getNodes();
            assertTrue(nodes.get(0) instanceof Identifier);
            assertTrue(((Token)nodes.get(0)).getValue().equals("Id1"));
            assertTrue(head.getName().getValue().equals("Apple"));
            assertTrue(head.toString().equals("Apple(Id1)"));

            sr = new StringReader("M(Id1,\n Id2)");
            lex = new Lex(sr);
            head = new ExtendedHead(lex);
            nodes = head.getNodes();
            assertTrue(nodes.size() == 2);
            assertTrue(nodes.get(0) instanceof Identifier);
            assertTrue(nodes.get(1) instanceof Identifier);
            assertTrue(((Token)nodes.get(0)).getValue().equals("Id1"));
            assertTrue(((Token)nodes.get(1)).getValue().equals("Id2"));
            assertTrue(head.getName().getValue().equals("M"));
            assertTrue(head.toString().equals("M(Id1,Id2)"));

            sr = new StringReader("List(Name1,\n Name2,\n Name3)");
            lex = new Lex(sr);
            head = new ExtendedHead(lex);
            nodes = head.getNodes();
            assertTrue(nodes.size() == 3);
            assertTrue(nodes.get(0) instanceof Identifier);
            assertTrue(nodes.get(1) instanceof Identifier);
            assertTrue(nodes.get(2) instanceof Identifier);
            assertTrue(((Token)nodes.get(0)).getValue().equals("Name1"));
            assertTrue(((Token)nodes.get(1)).getValue().equals("Name2"));
            assertTrue(((Token)nodes.get(2)).getValue().equals("Name3"));
            assertTrue(head.getName().getValue().equals("List"));
            assertTrue(head.toString().equals("List(Name1,Name2,Name3)"));
        }catch(ParserException e){
            System.out.println(
                "ERROR in HeadTest.testHeadConstructor\n" +
                "    should not get here.\n" +
                "    error = " + e.getMessage());
        };
    }