Commit f5342a83 authored by Siebers, Michael's avatar Siebers, Michael
Browse files

test and fix file_size/2

parent 3a9b42e4
......@@ -47,7 +47,7 @@ abs_path(Item, Path) :- theory_bg:item(Item, Dict), Path=Dict.abs_path, !.
%! file_size(+Item, -Size) is semidet.
%
% Extract the file size of a file. Fails is Item is a directory.
file_size(Item, Size) :- theory_bg:item(Item, Dict), !, Size=Dict.file_size.
file_size(Item, Size) :- theory_bg:item(Item, Dict), !, Size=Dict.get(file_size).
%! directory(?Item) is semidet.
......
......@@ -27,7 +27,7 @@ test(file_findall, [true(Fs == TrueFs), setup(findall(TF, theory_bg:file(TF),Tru
%%
%% abs_path/1
%% abs_path/2
%%
% abs_path(+Item,+Path) is semidet.
......@@ -40,19 +40,47 @@ test(abs_path_semibound, forall(theory_bg:abs_path(TrueItemId,TrueAbsPath))) :-
test(abs_path_semidet) :-
semidet_for_item(abs_path/2).
%%
%% file_size/1
%% file_size/2
%%
% file_size(+Item,+Size) is semidet.
% file_size(+Item,-Size) is semidet.
test(file_size_semibound, forall(theory_bg:file_size(TrueFileId,TrueSize))) :-
first_bound(file_size/2, [TrueFileId, TrueSize]).
test(file_size_unbound_semidet_true, [forall(theory_bg:file(FileId))]) :-
file_size(FileId, _Size).
test(file_size_unbound_semidet_false,
[forall(theory_bg:item_false(UnknownId)), fail]) :-
file_size(UnknownId, _Size).
% file_size(+File, -Size) correct
test(file_size_correct,
[forall(theory_bg:file_size(FileId, ExpectedSize)),
true(Size == ExpectedSize)
]) :- file_size(FileId, Size).
% file_size(+File, +Size) is semidet.
test(file_size_bound_semidet_true,
[forall(theory_bg:file_size(FileId, ExpectedSize))]) :-
file_size(FileId, ExpectedSize).
test(file_size_bound_semidet_false,
[forall(theory_bg:file_size(FileId, ExpectedSize)),
setup(WrongSize is ExpectedSize + 10),
fail]) :-
file_size(FileId, WrongSize).
% file_size(+File, -Size) det if file is known, false else
test(file_size_semidet) :-
semidet_for_file(file_size/2).
% file_size(+Directory, -Size) fails
test(file_size_fails_for_directory_unbound,
[forall(theory_bg:file_false(DirId)), fail]) :-
file_size(DirId, _Size).
% file_size(+Directory, +Size) fails
test(file_size_fails_for_directory_bound,
[forall((
theory_bg:file_false(DirId),
member(AnySize, [-123456, 0, 18, 1024, 1700000000])
)),
fail]) :-
file_size(DirId, AnySize).
%%
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment