This predicate causes an expression to be evaluated and a value to be unified with a term.
is/2
'is'(Result, Expression)
is true iff the value of evaluating Expression
as an expression is Result
.
Templates and modes for the predicate are as follows:
is(?term, @evaluable)
Note that is
is a predefined operator.
Let's start with some simple tests verifying success or failure of single goals.
jTrolog.engine.SimpleGoalFixture | ||
goal | success() | exception() |
'is'(3, 3). | true | no exception |
'is'(3, 3.0). | false | no exception |
'is'(foo, 77). | false | no exception |
'is'(77, N). | false | instantiation_error |
Now we run some tests also verifying the unification for some of the variables in goals.
First of all, let's start an appropriate fixture containing an engine.
fit.ActionFixture | |
start | jTrolog.engine.EngineFixture |
Then, ask the engine to solve a query, and check variable bindings.
fit.ActionFixture | ||
enter | query | 'is'(Result, 3 + 11.0). |
check | hasSolution | true |
enter | variable | Result |
check | binding | 14.0 |
enter | query | X = 1 + 2, Y is X * 3. |
check | hasSolution | true |
enter | variable | X |
check | binding | 1 + 2 |
enter | variable | Y |
check | binding | 9 |
The remaining tests cover the cases when an error or exception is thrown by the engine while solving a query.
jTrolog.engine.PrologActionFixture | ||
enter | query | 'is'(77, N). |
check | hasSolution | false |
check | exception | instantiation_error |
The results of the tests for Arithmetic evaluation are as follows:
fit.Summary | |
counts | 15 right, 0 wrong, 0 ignored, 0 exceptions |
run date | Tue Jan 15 12:14:13 CET 2008 |
run elapsed time | 0:00.14 |