この非常に単純な変数-節モデルを考えると
class Variable(name: String, negated: Boolean = false) {
def evaluate(b: Boolean): Boolean = negated match {
case false => b
case true => !b
}
def negate = new Variable(this.name, !this.negated)
override def toString = negated match {
case false => name
case true => "~" + name
}
override def hashCode() = name.hashCode()
override def equals(obj: Any) = name.equals(obj)
}
class Clause(vars: List[Variable]) {
def evaluate(values: Map[Variable, Boolean]): Boolean = {
val evaluatedVars = vars.map(v => v.evaluate(values(v)))
(false /: evaluatedVars)(_ || _)
}
}
この単純なアサーションは例外をスローします
val c = new Variable("c")
val d = new Variable("d")
val c3 = new Clause(List(c.negate, d))
assertTrue( c2.evaluate( Map(c -> false, d -> true) ) )
java.util.NoSuchElementException:キーが見つかりません:〜c
私は何が欠けていますか?