Skip to content

Commit

Permalink
fixed hw6 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Whitomtit committed Aug 15, 2024
1 parent be3ef3b commit f30816e
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 21 deletions.
4 changes: 4 additions & 0 deletions Spr24/HW/Homework6/q1_1.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ true.

true.

true.

false.


false.

Expand Down
4 changes: 3 additions & 1 deletion Spr24/HW/Homework6/q1_1.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ set_prolog_flag(answer_write_options, [quoted(true), portray(true), max_depth(0)
print("===TEST START===").

once(bt(5, [bt(7, [])])).
once(bt(7, [bt(5, [])])).
once(bt(5, [bt(6, [bt(7, [])]), bt(8, [])])).
once(bt(7, [bt(5, [])])).
once(bt(5, [bt(8, []), bt(6, [bt(7, [])])])).
6 changes: 3 additions & 3 deletions Spr24/HW/Homework6/q1_3.expected
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
true.

L = [[[empty, bt(4, [bt(5, [])])]]].
L = [[[4, 5]]].

L = [[[empty, empty, bt(3, [bt(4, [bt(5, [])]), bt(2, [])])]]].
L = [[[2, 3, 4, 5]]].


L = [[[bt(1, []), empty, bt(3, [bt(4, [bt(5, [])]), bt(2, [])])]]].
L = [[[1, 2, 3, 4, 5]]].


47 changes: 41 additions & 6 deletions Spr24/HW/Homework6/q1_3.in
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
use_module(library(yall)).
set_prolog_flag(answer_write_options, [quoted(true), portray(true), max_depth(0), spacing(next_argument)]).

assert(is_heap([]) :- !).
assert((is_heap(X) :- is_heap_aux(X, 0), length(X, L), \+ nth1(L, X, empty))).
assert(is_heap_aux([], _) :- !).
assert((is_heap_aux([empty | Xs], I) :-
!, NI is I + 1,
is_heap_aux(Xs, NI))).
assert((is_heap_aux([bt(V, L) | Xs], I) :-
bt(V, L),
length(L, I),
NI is I + 1,
is_heap_aux(Xs, NI))).

assert(values([], [])).
assert(values([empty | Xs], Ys) :-
values(Xs, Ys)).
assert((values([bt(V, L) | Xs], Ys) :-
values(L, LV),
values(Xs, XsV),
append([V | LV], XsV, Ys))).
print("===TEST START===").

{L}/(
findall(
[X],
add_bt(bt(5, []), [bt(4, [])], X),
[Z],
(
add_bt(bt(5, []), [bt(4, [])], X),
is_heap(X),
values(X, Y),
msort(Y, Z)
),
L1
),
msort(L1, L)
).

{L}/(
findall(
[X],
add_bt(bt(3, [bt(2, [])]), [empty, bt(4, [bt(5, [])])], X),
[Z],
(
add_bt(bt(2, [bt(3, [])]), [empty, bt(4, [bt(5, [])])], X),
is_heap(X),
values(X, Y),
msort(Y, Z)
),
L1
),
msort(L1, L)
).

{L}/(
findall(
[X],
add_bt(bt(1, []), [empty, empty, bt(3,[bt(4,[bt(5,[])]), bt(2,[])])], X),
[Z],
(
add_bt(bt(1, []), [empty, empty, bt(2,[bt(4,[bt(5,[])]), bt(3,[])])], X),
is_heap(X),
values(X, Y),
msort(Y, Z)
),
L1
),
msort(L1, L)
Expand Down
4 changes: 2 additions & 2 deletions Spr24/HW/Homework6/q1_4.expected
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
true.

L = [[[empty, bt(3, [bt(4, [])])]]].
L = [[[3, 4]]].


L = [[[bt(10, []), bt(3, [bt(4, [])])]]].
L = [[[3, 4, 10]]].


38 changes: 34 additions & 4 deletions Spr24/HW/Homework6/q1_4.in
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
use_module(library(yall)).
set_prolog_flag(answer_write_options, [quoted(true), portray(true), max_depth(0), spacing(next_argument)]).

assert(is_heap([]) :- !).
assert((is_heap(X) :- is_heap_aux(X, 0), length(X, L), \+ nth1(L, X, empty))).
assert(is_heap_aux([], _) :- !).
assert((is_heap_aux([empty | Xs], I) :-
!, NI is I + 1,
is_heap_aux(Xs, NI))).
assert((is_heap_aux([bt(V, L) | Xs], I) :-
bt(V, L),
length(L, I),
NI is I + 1,
is_heap_aux(Xs, NI))).

assert(values([], [])).
assert(values([empty | Xs], Ys) :-
values(Xs, Ys)).
assert((values([bt(V, L) | Xs], Ys) :-
values(L, LV),
values(Xs, XsV),
append([V | LV], XsV, Ys))).
print("===TEST START===").

{L}/(
findall(
[X],
add(3, [bt(4, [])], X),
[Z],
(
add(3, [bt(4, [])], X),
is_heap(X),
values(X, Y),
msort(Y, Z)
),
L1
),
msort(L1, L)
).

{L}/(
findall(
[X],
add(10, [empty, bt(3, [bt(4, [])])], X),
[Z],
(
add(10, [empty, bt(3, [bt(4, [])])], X),
is_heap(X),
values(X, Y),
msort(Y, Z)
),
L1
),
msort(L1, L)
Expand Down
2 changes: 1 addition & 1 deletion Spr24/HW/Homework6/q1_5.expected
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
true.

L = [[3, [bt(4, [])]]].
L = [[3, [4]]].


L = [[4, []]].
Expand Down
38 changes: 34 additions & 4 deletions Spr24/HW/Homework6/q1_5.in
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
use_module(library(yall)).
set_prolog_flag(answer_write_options, [quoted(true), portray(true), max_depth(0), spacing(next_argument)]).

assert(is_heap([]) :- !).
assert((is_heap(X) :- is_heap_aux(X, 0), length(X, L), \+ nth1(L, X, empty))).
assert(is_heap_aux([], _) :- !).
assert((is_heap_aux([empty | Xs], I) :-
!, NI is I + 1,
is_heap_aux(Xs, NI))).
assert((is_heap_aux([bt(V, L) | Xs], I) :-
bt(V, L),
length(L, I),
NI is I + 1,
is_heap_aux(Xs, NI))).

assert(values([], [])).
assert(values([empty | Xs], Ys) :-
values(Xs, Ys)).
assert((values([bt(V, L) | Xs], Ys) :-
values(L, LV),
values(Xs, XsV),
append([V | LV], XsV, Ys))).
print("===TEST START===").

{L}/(
findall(
[X, Y],
fetch_min(X, [empty, bt(3, [bt(4, [])])], Y),
[X, Z],
(
fetch_min(X, [empty, bt(3, [bt(4, [])])], Y),
is_heap(Y),
values(Y, YY),
msort(YY, Z)
),
L1
),
msort(L1, L)
).

{L}/(
findall(
[X, Y],
fetch_min(X, [bt(4, [])], Y),
[X, Z],
(
fetch_min(X, [bt(4, [])], Y),
is_heap(Y),
values(Y, YY),
msort(YY, Z)
),
L1
),
msort(L1, L)
Expand Down

0 comments on commit f30816e

Please sign in to comment.