Skip to content

Instantly share code, notes, and snippets.

@hsk
Created December 4, 2017 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsk/ff712ab7e4ba400211557a3e59ed381f to your computer and use it in GitHub Desktop.
Save hsk/ff712ab7e4ba400211557a3e59ed381f to your computer and use it in GitHub Desktop.
prolog test sample
:- module(fun1, [add/3,mul/3]).
% fun.pl
add(A,B,C) :- C is A+B.
mul(A,B,C) :- C is A*B.
:- module(fun2, [add/3,mul/3]).
% fun2.pl
add(A,B,C) :- C is A+B.
mul(A,B,C) :- C is A*B.
% funtest.pl
:- current_prolog_flag(argv, [M]),!,format('use ~w\n',[M]),use_module(M) ;
use_module(fun1).
:- begin_tests(add).
test(add1_2) :- add(1,2,3).
test(add0_1) :- add(0,1,1).
:- end_tests(add).
:- begin_tests(mul).
test(mul1_2) :- mul(1,2,2).
test(mul0_1) :- mul(0,1,0).
test(mul10_20) :- mul(10,20,200).
:- end_tests(mul).
:- run_tests.
:- halt.
test: test1 test2
test1:
swipl funtest.pl
test2:
swipl funtest.pl fun2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment