Skip to content

Commit

Permalink
Improve basic tests; check overflow & underflow behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
kurahaupo committed Feb 27, 2010
1 parent eceb4bf commit 3951a4d
Showing 1 changed file with 68 additions and 31 deletions.
99 changes: 68 additions & 31 deletions t/pmc/fixedpmcqueue.t
Expand Up @@ -4,15 +4,17 @@ MAIN();

sub MAIN () {
load_test_more();
plan(18);
plan(23);
load_linalg_group();

op_new();
op_does();
op_typeof();
vtable_set_integer_native();
vtable_push_pmc();
vtable_push_pmc_overflow();
vtable_shift_pmc();
vtable_shift_pmc_underflow();
vtable_elements();
vtable_get_bool();
vtable_get_integer();
Expand Down Expand Up @@ -42,47 +44,47 @@ sub load_linalg_group() {

sub op_new() {
Q:PIR {
$I0 = 0
push_eh new_sanity_failure
$P0 = new ['FixedPMCQueue']
ok(1, "Could create FPQ")
goto new_sanity_end
$I0 = 1
new_sanity_failure:
ok(0, "Could not create FPQ")
new_sanity_end:
pop_eh
ok($I0, "Can create FPQ")

$I0 = isnull $P0
is($I0, 1)
todo($I0, "... should be Null (or not!?)")
}
}

sub op_does() {
Q:PIR {
$P0 = new ['FixedPMCQueue']
$I0 = does $P0, 'queue'
is($I0, 1)
is($I0, 1, "Does 'queue'")
$I0 = does $P0, "jibbajabba"
is($I0, 0)
is($I0, 0, "Doesn't do 'jibbajabba'")
}
}
sub op_typeof() {
Q:PIR {
$P0 = new ['FixedPMCQueue']
$S0 = typeof $P0
is($S0, 'FixedPMCQueue')
is($S0, 'FixedPMCQueue', "isa 'FixedPMCQueue'")
}
}

sub vtable_set_integer_native() {
Q:PIR {
$P0 = new ['FixedPMCQueue']
$I0 = 0
push_eh set_integer_sanity_error
$P0 = 5
ok(1)
goto set_integer_sanity_end
$I0 = 1
set_integer_sanity_error:
ok(0)
set_integer_sanity_end:
pop_eh
ok($I0, "Can set capacity (to 5)")
}
}

Expand All @@ -91,13 +93,33 @@ sub vtable_push_pmc() {
$P0 = new ['FixedPMCQueue']
$P0 = 5
$P1 = box 1
$I0 = 0
push_eh push_pmc_sanity_error
push $P0, $P1
ok(1)
goto push_pmc_sanity_end
$I0 = 1
push_pmc_sanity_error:
ok(0)
push_pmc_sanity_end:
pop_eh
ok($I0, "Can push onto (empty) queue")
}
}

sub vtable_push_pmc_overflow() {
Q:PIR {
$P0 = new ['FixedPMCQueue']
$I0 = 5
$P0 = $I0
$P1 = box 1
L1:
push $P0, $P1
dec $I0
gt $I0, 0, L1
$I0 = 1
push_eh push_pmc_overflow
push $P0, $P1
$I0 = 0
push_pmc_overflow:
pop_eh
ok($I0, "Can't push onto full queue (throws exception)")
}
}

Expand All @@ -108,79 +130,94 @@ sub vtable_shift_pmc() {
$P1 = box 1
push $P0, $P1
$P2 = shift $P0
is($P1, $P2)
is($P1, $P2, "Push then shift gets original value back")
}
}
sub vtable_shift_pmc_underflow() {
Q:PIR {
$P0 = new ['FixedPMCQueue']
$P0 = 5
$P1 = box 1
$I0 = 1
push_eh shift_pmc_underflow
$P2 = shift $P0
$I0 = 0
shift_pmc_underflow:
pop_eh
ok($I0, "Can't shift from empty queue (throws exception)")
}
}

sub vtable_elements() {
Q:PIR {
$P0 = new ['FixedPMCQueue']
$I0 = elements $P0
is($I0, 0)
is($I0, 0, ".elements() initially 0")
$P0 = 5
$I0 = elements $P0
is($I0, 0)
is($I0, 0, " ... still empty after setting capacity")
$P1 = box 1
push $P0, $P1
$I0 = elements $P0
is($I0, 1)
is($I0, 1, " ... is 1 after pushing 1 item")
$P2 = shift $P0
$I0 = elements $P0
is($I0, 0)
is($I0, 0, " ... is 0 after shifting all items")
}
}
sub vtable_get_bool() {
Q:PIR {
$P0 = new ['FixedPMCQueue']
$I0 = istrue $P0
is($I0, 0)
is($I0, 0, "Boolean initially false")

$P0 = 5
$I0 = istrue $P0
is($I0, 0)
is($I0, 0, " ... still false after setting capacity")

$P1 = box 1
push $P0, $P1
$I0 = istrue $P0
is($I0, 1)
is($I0, 1, " ... is true after pushing 1 item")

$P2 = shift $P0
$I0 = istrue $P0
is($I0, 0)
is($I0, 0, " ... is false after shifting all items")
}
}

sub vtable_get_integer() {
Q:PIR {
$P0 = new ['FixedPMCQueue']
$I0 = $P0
is($I0, 0)
is($I0, 0, "Integer initially 0")
$P0 = 5
$I0 = $P0
is($I0, 5)
is($I0, 5, " ... changes to reflect capacity")
}
}
sub method_to_array() {
Q:PIR {
# TODO: This!
todo(0,"test .to_array()")
}
}

sub method_total_mem_size() {
Q:PIR {
# TODO: This!
todo(0,"test .total_mem_size()")
}
}
sub method_clear() {
Q:PIR {
# TODO: This!
todo(0,"test .clear()")
}
}

0 comments on commit 3951a4d

Please sign in to comment.