mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
* lib/std/sort: unify binarysearch and binarysearch_with; add comments to quicksort Signed-off-by: Pierre Curto <pierre.curto@gmail.com> * lib/std/collections: mark List.{len, is_empty, get} with @inline Signed-off-by: Pierre Curto <pierre.curto@gmail.com> * lib/std/collections: add PriorityQueueMax; add tests for PriorityQueue and PriorityQueueMax Signed-off-by: Pierre Curto <pierre.curto@gmail.com> --------- Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
59 lines
1.2 KiB
C
59 lines
1.2 KiB
C
module priorityqueue_test @test;
|
|
import std::collections;
|
|
import std::collections::priorityqueue;
|
|
|
|
def Queue = PriorityQueue(<int>);
|
|
|
|
fn void! priorityqueue()
|
|
{
|
|
Queue q;
|
|
assert(q.is_empty());
|
|
|
|
q.push(1);
|
|
q.push(2);
|
|
assert(q.len() == 2);
|
|
|
|
int x;
|
|
x = q.pop()!;
|
|
assert(x == 1, "got %d; want %d", x, 1);
|
|
x = q.pop()!;
|
|
assert(x == 2, "got %d; want %d", x, 2);
|
|
|
|
q.push(3);
|
|
q.push(2);
|
|
q.push(1);
|
|
x = q.pop()!;
|
|
assert(x == 1, "got %d; want %d", x, 1);
|
|
x = q.pop()!;
|
|
assert(x == 2, "got %d; want %d", x, 2);
|
|
x = q.pop()!;
|
|
assert(x == 3, "got %d; want %d", x, 3);
|
|
}
|
|
|
|
def QueueMax = PriorityQueueMax(<int>);
|
|
|
|
fn void! priorityqueue_max()
|
|
{
|
|
QueueMax q;
|
|
assert(q.is_empty());
|
|
|
|
q.push(1);
|
|
q.push(2);
|
|
assert(q.len() == 2);
|
|
|
|
int x;
|
|
x = q.pop()!;
|
|
assert(x == 2, "got %d; want %d", x, 2);
|
|
x = q.pop()!;
|
|
assert(x == 1, "got %d; want %d", x, 1);
|
|
|
|
q.push(3);
|
|
q.push(2);
|
|
q.push(1);
|
|
x = q.pop()!;
|
|
assert(x == 3, "got %d; want %d", x, 3);
|
|
x = q.pop()!;
|
|
assert(x == 2, "got %d; want %d", x, 2);
|
|
x = q.pop()!;
|
|
assert(x == 1, "got %d; want %d", x, 1);
|
|
} |