diff --git a/extras/quickcheck/Mmakefile b/extras/quickcheck/Mmakefile new file mode 100644 index 000000000..cf89d827f --- /dev/null +++ b/extras/quickcheck/Mmakefile @@ -0,0 +1,17 @@ +#-----------------------------------------------------------------------------# +# Copyright (C) 2001 The University of Melbourne. +# This file may only be copied under the terms of the GNU Library General +# Public License - see the file COPYING.LIB in the Mercury distribution. +#-----------------------------------------------------------------------------# + +-include ../Mmake.params + +MAIN_TARGET = all + +all: test_qcheck + +depend: test_qcheck.depend + +.PHONY: check +check: + true diff --git a/extras/quickcheck/nrev.m b/extras/quickcheck/nrev.m new file mode 100644 index 000000000..564a0fe84 --- /dev/null +++ b/extras/quickcheck/nrev.m @@ -0,0 +1,19 @@ +%---------------------------------------------------------------------------% +% Copyright (C) 2001 The University of Melbourne. +% This file may only be copied under the terms of the GNU General +% Public License - see the file COPYING in the Mercury distribution. +%---------------------------------------------------------------------------% + +:- module nrev. + +:- interface. +:- import_module list. + +:- func nrev(list(T)) = list(T). +:- mode nrev(in) = out is det. + +:- implementation. + +nrev([]) = []. +nrev([X|Xs]) = Ys :- + list__append(nrev(Xs), [X], Ys). diff --git a/extras/quickcheck/qcheck.m b/extras/quickcheck/qcheck.m index f978e0fc7..0459d59a7 100644 --- a/extras/quickcheck/qcheck.m +++ b/extras/quickcheck/qcheck.m @@ -326,8 +326,8 @@ qcheck(TestFunction, Name, TestCount, SpecificFrequency, :- func generate_seed_from_time(time_t) = int. :- mode generate_seed_from_time(in) = out. generate_seed_from_time(CurrentTime) = Seed :- - tm(Seconds, Minutes, Hours, _Weekday, Yearday, _Month, Year, _DST) - = time__localtime(CurrentTime), + tm(Year, _Month, _MonthDay, Hours, Minutes, Seconds, Yearday, + _Weekday, _DST) = time__localtime(CurrentTime), TotalSecs = ((( integer(Year) * integer(365) + integer(Yearday)) * integer(24) + integer(Hours)) * integer(60) + integer(Minutes)) diff --git a/extras/quickcheck/test_qcheck.m b/extras/quickcheck/test_qcheck.m new file mode 100644 index 000000000..e0166f198 --- /dev/null +++ b/extras/quickcheck/test_qcheck.m @@ -0,0 +1,35 @@ +%---------------------------------------------------------------------------% +% Copyright (C) 2001 The University of Melbourne. +% This file may only be copied under the terms of the GNU General +% Public License - see the file COPYING in the Mercury distribution. +%---------------------------------------------------------------------------% + +:- module test_qcheck. + +:- interface. + +:- use_module io. + +:- pred main(io__state, io__state). +:- mode main(di, uo) is det. + +%---------------------------------------------------------------------------% + +:- implementation. + +:- import_module int, list. +:- import_module qcheck, nrev. + +%---------------------------------------------------------------------------% + +main --> + qcheck(qcheck__f(testing), "sample testing"). + +%------------------------------------------------------------------------------% +% Invariant test functions +%------------------------------------------------------------------------------% + +:- func testing(list(int), list(int)) = property. +testing(Xs, Ys) = + nrev(Xs ++ Ys) `===` (nrev(Ys) ++ nrev(Xs)). +