Merge delete and fixe row tests

This commit is contained in:
Brieuc Dubois 2024-03-14 23:07:48 +01:00
commit 84a3075bc8
2 changed files with 39 additions and 33 deletions

View File

@ -68,7 +68,7 @@ row(Table, Row) :-
length(Cols, L),
length(Row, L),
apply(Table, Row)
); fail.
); throw("Table doesn't exist").
:- dynamic rows/1.
/*
@ -153,11 +153,16 @@ prompt, but which may include selectors. Selectors are terms of the form
delete(Table, Conds) :-
(tabl(Table, _) ->
row(Table, Row),
does_match(Conds, Table, Row)
does_match(Conds, Table, Row),
Term =.. [Table | Row],
retract(Term),
fail
;
throw("Table doesn't exist")
).
delete(_, _).
does_match([], _, _) :- !.
@ -182,6 +187,7 @@ delete(Table, Conds) :-
% Check the next condition
does_match(Rest, Table, Row).
:- dynamic selec/4.
/*
Note that the name of this predicate is selec (without t) for the simple

View File

@ -52,16 +52,16 @@ test(drop_inexistant, throws(_)) :-
drop(foobar).
% Test if row/2 returns the different rows of a given table.
test(rows, cleanup(cdrop(foo))) :-
test(row, cleanup(cdrop(foo))) :-
create_table(foo, [bar, baz]),
insert(foo, [1, 2]),
insert(foo, [3, 4]),
rows(foo, Rows),
row(foo, Rows),
assertion(length(Rows,2)).
% Test if row/2 fails on an unknown table name.
test(row_inexistant, throws(_)) :-
rows(foo, _Row).
row(foo, _Row).
% Test if rows/1 works when called for a given table name.
test(rows, cleanup(cdrop(foo))) :-