/* $Id$ */

package aspectjhw.lambda;

import junit.framework.TestCase;
import java.util.*;

/** Tests for variables
 * @author Gary T. Leavens
 */
public class VariableTest extends TestCase {

    /** Constructor for VariableTest.
     */
    public VariableTest(String name) {
        super(name);
    }

    /** Run this test */
    public static void main(String[] args) {
        junit.textui.TestRunner.run(VariableTest.class);
    }
    
    /** Test the equals method. */
    public void testEquals() {
        assertEquals(new Variable("x"), new Variable("x"));
        assertFalse(new Variable("x").equals(new Variable("y")));
        assertFalse(new Variable("z").equals(null));
        assertFalse(new Variable("z").equals(new Lambda("x", new Variable("z"))));
    }
    
    /** Test the hashCode method. */
    public void testHashCode() {
        assertEquals(new Variable("x").hashCode(), new Variable("x").hashCode());
    }

    /** Test the evaluate method. */
    public void testEvaluate() {
        Term t = new Variable("x");
        assertSame(t, t.reduce1Step());
    }
    
    /** Test the freeVars method. */
    public void testFreeVars() {
        Term t = new Variable("z");
        Set s = new HashSet();
        s.add("z");
        assertEquals(s, t.freeVars());
    }
    
    /** Test the substituteFor method. */
    public void testSubstituteFor() {
        Term t = new Variable("z");
        assertSame(t, t.substituteFor("x", new Variable("y")));
        assertEquals(new Variable("y"), t.substituteFor("z", new Variable("y")));
    }
}
