public void FunctionAndFullTest() { this.TestFunction( (state, param, result) => FunctionAnd.Create(state, param, result), (state, param, result) => { bool value = true; foreach (int p in param) { value &= (state[p] != State.On0); } return(value ? state[result] == State.On1 : state[result] == State.On0); } ); }
public void CircuitStateEvaluateTest() { CircuitState target = new CircuitState(3); OneBitConst c1 = new OneBitConst(target, State.On0, 0); OneBitConst c2 = new OneBitConst(target, State.On1, 1); FunctionAnd and = FunctionAnd.Create(target, new int[] { 0, 1 }, 2); target.EndDefinition(); bool success = target.Evaluate(true); Assert.IsTrue(success); Assert.AreEqual <State>(State.On0, target[0]); Assert.AreEqual <State>(State.On1, target[1]); Assert.AreEqual <State>(State.On0, target[2]); }
// ExprAndOr: private void MatchExprAndOr(out IExpr result) { TokenTypes t; // remember the type IExpr lhs; MatchExprNot(out lhs); result = lhs; // in case we get no matches while ((t = curToken.Type) == TokenTypes.AND || t == TokenTypes.OR) { curToken = tokens.Extract(); IExpr rhs; MatchExprNot(out rhs); bool bBool = (rhs.GetTypeCode() == TypeCode.Boolean && lhs.GetTypeCode() == TypeCode.Boolean); if (!bBool) throw new ParserException("AND/OR operations require both sides to be boolean expressions." + " At column " + Convert.ToString(curToken.StartCol)); switch(t) { case TokenTypes.AND: result = new FunctionAnd(lhs, rhs); break; case TokenTypes.OR: result = new FunctionOr(lhs, rhs); break; } lhs = result; // in case we have more AND/OR s } }