public void SimpleLambda() { var boundVar = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "foo", Microsoft.Boogie.Type.Bool)); var id = new IdentifierExpr(Token.NoToken, boundVar); // This is basically an Identity Map var lambdaExpr = new LambdaExpr(Token.NoToken, new List <TypeVariable>(), new List <Variable>() { boundVar }, null, id); var id2 = new IdentifierExpr(Token.NoToken, boundVar); var lambdaExpr2 = new LambdaExpr(Token.NoToken, new List <TypeVariable>(), new List <Variable>() { boundVar }, null, id2); Assert.AreNotSame(lambdaExpr, lambdaExpr2); // These are different references Assert.IsTrue(lambdaExpr.Equals(lambdaExpr2)); // These are "structurally equal" Assert.AreEqual(lambdaExpr.GetHashCode(), lambdaExpr2.GetHashCode()); // If the .Equals() is true then hash codes must be the same }
public void CachedHashCodeLambdaExpr() { var x = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "x", BasicType.Int)); var y = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "x", BasicType.Int)); var body = Expr.Gt(new IdentifierExpr(Token.NoToken, x, /*immutable=*/true), new IdentifierExpr(Token.NoToken, y, /*immutable=*/true)); var lambda = new LambdaExpr(Token.NoToken, new List<TypeVariable>(), new List<Variable>() {x, y}, null, body, /*immutable=*/true); Assert.AreEqual(lambda.ComputeHashCode(), lambda.GetHashCode()); }