Did you know ... | Search Documentation: |
Pack logtalk -- logtalk-3.86.0/examples/quick_check/SCRIPT.txt |
This file is part of Logtalk https://logtalk.org/ SPDX-FileCopyrightText: 1998-2023 Paulo Moura <pmoura@logtalk.org> SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
% start by loading the sample properties used to use QuickCheck interactively % at the top-level interpreter:
| ?- logtalk_load(quick_check(loader))
.
...
% check that reversing a list twice gives back the same list:
| ?- lgtunit::quick_check(reverse_2_twice_prop(+list))
.
% 100 random tests passed
yes
% check the same_length_2_prop/1 property by running the default number of % random tests:
| ?- lgtunit::quick_check(same_length_2_prop(+list))
.
% 100 random tests passed
yes
% check the same_length_3_prop/1 property by running 25 random tests:
| ?- lgtunit::quick_check(same_length_3_prop(+list), [n(25)])
.
% 25 random tests passed
yes
% try a broken property, broken_nth1_3_prop/1, to check returning of a % counter-example that falsifies the property:
| ?- lgtunit::quick_check(broken_nth1_3_prop(+list), [n(25)])
.
broken_nth1_3_prop([])
no
% the alternative lgtunit::quick_check/3 predicate returns results in % reified form:
| ?- lgtunit::quick_check(same_length_2_prop(+list), Result, [])
.
Result = passed.
yes
| ?- lgtunit::quick_check(broken_nth1_3_prop(+list), Result, [n(250)])
.
Result = failed(broken_nth1_3_prop([]))
.
yes
% defining a predicate specifying a property of the predicate that we want % to test is not always necessary; for example assuming that the predicate % length/2 is defined in "user":
| ?- lgtunit::quick_check(length(+list, -integer))
.
% 100 random tests passed
yes
% the template of the quick_check/1-3 predicates can also use the % ::/2 and <</2 control constructs:
| ?- lgtunit::quick_check(list::length(+list, -integer)
).
% 100 random tests passed
yes
| ?- lgtunit::quick_check(list<<length(+list, -integer))
.
% 100 random tests passed
yes
% when using a backend Prolog system supporting modules, the template % argument of the quick_check/1-3 predicates can be an explicitly % module-qualified template; for example, assuming a system providing % a "lists" module defining the de facto standard length/2 predicate:
| ?- use_module(library(lists))
.
yes
| ?- lgtunit::quick_check(lists:length(+list, -integer))
.
% 100 random tests passed
yes