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, !. ...@@ -47,7 +47,7 @@ abs_path(Item, Path) :- theory_bg:item(Item, Dict), Path=Dict.abs_path, !.
%! file_size(+Item, -Size) is semidet. %! file_size(+Item, -Size) is semidet.
% %
% Extract the file size of a file. Fails is Item is a directory. % 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. %! directory(?Item) is semidet.
......
...@@ -27,7 +27,7 @@ test(file_findall, [true(Fs == TrueFs), setup(findall(TF, theory_bg:file(TF),Tru ...@@ -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. % abs_path(+Item,+Path) is semidet.
...@@ -39,22 +39,50 @@ test(abs_path_semibound, forall(theory_bg:abs_path(TrueItemId,TrueAbsPath))) :- ...@@ -39,22 +39,50 @@ test(abs_path_semibound, forall(theory_bg:abs_path(TrueItemId,TrueAbsPath))) :-
% abs_path(+Item, -Path) det if item is known, false else % abs_path(+Item, -Path) det if item is known, false else
test(abs_path_semidet) :- test(abs_path_semidet) :-
semidet_for_item(abs_path/2). semidet_for_item(abs_path/2).
%%
%% file_size/2
%% %%
%% file_size/1
%%
% file_size(+Item,+Size) is semidet.
% file_size(+Item,-Size) is semidet. % file_size(+Item,-Size) is semidet.
test(file_size_semibound, forall(theory_bg:file_size(TrueFileId,TrueSize))) :- test(file_size_unbound_semidet_true, [forall(theory_bg:file(FileId))]) :-
first_bound(file_size/2, [TrueFileId, TrueSize]). file_size(FileId, _Size).
test(file_size_unbound_semidet_false,
% file_size(+File, -Size) det if file is known, false else [forall(theory_bg:item_false(UnknownId)), fail]) :-
test(file_size_semidet) :- file_size(UnknownId, _Size).
semidet_for_file(file_size/2).
% 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(+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).
%% %%
%% directory/1 %% directory/1
%% %%
......
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