1N/A# Unit tests for heap implementation 1N/A# Test the following methods: 1N/A# Finish these later. 1N/A# They're nonurgent because the important heap stuff is extensively 1N/A# tested by tests 19, 20, 24, 30, 32, 33, and 40, as well as by pretty 1N/A# much everything else. 1N/A# (3) Are all the methods there? 1N/A print $good ? "ok $N\n" : "not ok $N\n"; 1N/A# (4) Straight insert and removal FIFO test 1N/A ? "ok $N\n" : "not ok $N \# expected ($iota), got (@R)\n"; 1N/A# (5) Remove from empty heap 1N/Aprint ! defined $n ? "ok $N\n" : "not ok $N \# expected UNDEF, got $n"; 1N/A# (6) Interleaved insert and removal 1N/Aprint "@R" eq $iota ? "ok $N\n" : "not ok $N \# expected ($iota), got (@R)\n"; 1N/A# (7) It should be empty now 1N/A# (8) Insert and delete 1N/Afor (2, 4, 6, 8, 10) { 1N/Aprint "@R" eq "c1 c3 c5 c7 c9" ? 1N/A "ok $N\n" : "not ok $N \# expected (c1 c3 c5 c7 c9), got (@R)\n"; 1N/A# (9) Interleaved insert and delete 1N/Aprint "@R" eq "d1 d3 d5 d7 d9" ? 1N/A "ok $N\n" : "not ok $N \# expected (d1 d3 d5 d7 d9), got (@R)\n"; 1N/Afor (2, 4, 6, 8, 10) { 1N/Aprint "@R" eq "e1 e3 e5 e7 e9 e2 e4 e6 e8 e10" ? 1N/A "not ok $N \# expected (e1 e3 e5 e7 e9 e2 e4 e6 e8 e10), got (@R)\n"; 1N/Afor (2, 4, 6, 4, 8) { 1N/A print $r eq "f$_" ? "ok $N\n" : "not ok $N \# expected f$_, got $r\n"; 1N/A# (16) It shouldn't be empty 1N/A# (17) Lookup should have promoted the looked-up records 1N/Aprint "@R" eq "f1 f3 f5 f7 f9 f10 f2 f6 f4 f8" ? 1N/A "not ok $N \# expected (f1 f3 f5 f7 f9 f10 f2 f6 f4 f8), got (@R)\n"; 1N/A# (18-19) Typical 'rekey' operation 1N/A print "# looked up $k, got $v, expected $x{$k}\n"; 1N/A print $good ? "ok $N\n" : "not ok $N\n"; 1N/A print "# looked up $k, got $v, should have been undef\n"; 1N/A print $good ? "ok $N\n" : "not ok $N\n"; 1N/Aprint "@R" eq "1 2 3 4 5 8 9 10 11 12" ? 1N/A "not ok $N \# expected (1 2 3 4 5 8 9 10 11 12) got (@R)\n"; 1N/Aprint "@R" eq "h1 h2 h3 h4 h5 h8 h9 h10 h11 h12" ? 1N/A "not ok $N \# expected (h1 h2 h3 h4 h5 h8 h9 h10 h11 h12) got (@R)\n"; 1N/Aprint $B == 23 ? "ok $N\n" : "not ok $N \# expected 23, got $B\n"; 1N/Aprint $B == 29 ? "ok $N\n" : "not ok $N \# expected 29, got $B\n"; 1N/Aprint ! defined $n ? "ok $N\n" : "not ok $N \# expected UNDEF, got $n"; 1N/A# (26) very weak testing of DESTROY 1N/A# are we still alive?