These predicates cause two expressions to be evaluated and their values to be compared.
Each arithmetic comparison predicate corresponds to an operation which depends on the types of the values which are obtained by evaluating the argument(s) of the predicate.
=:=/2
(arithmetic equal), =\=/2
(arithmetic not equal), </2
(arithmetic less than), =<
(arithmetic less than or equal), >/2
(arithmetic greater than), >=/2
(arithmetic greater than or equal)The following requirements are true for all P where P = {=:=
, =\=
, <
, =<
, >
, >=
}.
'P'(E1, E2)
is true iff evaluating E1
and E2
as expressions and performing the corresponding arithmetic operation on their values is true
.
Templates and modes for the predicate are as follows:
'=:='(@evaluable, @evaluable) '=\='(@evaluable, @evaluable) '<'(@evaluable, @evaluable) '=<'(@evaluable, @evaluable) '>'(@evaluable, @evaluable) '>='(@evaluable, @evaluable)
Let's start with some simple tests verifying success of failure of single goals.
alice.tuprolog.SimpleGoalFixture | |
goal | success() |
'=:='(0, 1). | false |
'=\='(0, 1). | true |
'<'(0, 1). | true |
'>'(0, 1). | false |
'>='(0, 1). | false |
'=<'(0, 1). | true |
'=:='(1.0, 1). | true |
'=\='(1.0, 1). | false |
'<'(1.0, 1). | false |
'>'(1.0, 1). | false |
'>='(1.0, 1). | true |
'=<'(1.0, 1). | true |
'=:='(3 * 2, 7 - 1). | true |
'=\='(3 * 2, 7 - 1). | false |
'<'(3 * 2, 7 - 1). | false |
'>'(3 * 2, 7 - 1). | false |
'>='(3 * 2, 7 - 1). | true |
'=<'(3 * 2, 7 - 1). | true |
The remaining tests cover the cases when an error or exception is thrown by the engine while solving a query.
First of all, let's start an appropriate fixture containing an engine.
fit.ActionFixture | |
start | alice.tuprolog.EngineFixture |
Then, ask the engine to solve a query, and check variable bindings.
alice.tuprolog.PrologActionFixture | ||
enter | query | '=:='(X, 5). |
check | hasSolution | false |
check | exception | instantiation_error |
enter | query | '=\\='(X, 5). |
check | hasSolution | false |
check | exception | instantiation_error |
enter | query | '<'(X, 5). |
check | hasSolution | false |
check | exception | instantiation_error |
enter | query | '>'(X, 5). |
check | hasSolution | false |
check | exception | instantiation_error |
enter | query | '>='(X, 5). |
check | hasSolution | false |
check | exception | instantiation_error |
enter | query | '=<'(X, 5). |
check | hasSolution | false |
check | exception | instantiation_error |
Run the tests!
The results of the tests for Arithmetic comparison are as follows:
fit.Summary |