Skip to content

Commit

Permalink
Improve tests (apply same tests to all versions)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurahaupo committed Feb 27, 2010
1 parent 3951a4d commit 163662d
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 73 deletions.
22 changes: 13 additions & 9 deletions t/pmc/fixedpmcqueue.t
Expand Up @@ -91,28 +91,32 @@ sub vtable_set_integer_native() {
sub vtable_push_pmc() {
Q:PIR {
$P0 = new ['FixedPMCQueue']
$P0 = 5
$I1 = 5
$P0 = $I1
$P1 = box 1
$I0 = 0
push_eh push_pmc_sanity_error
L1:
push $P0, $P1
dec $I1
gt $I1, 0, L1
$I0 = 1
push_pmc_sanity_error:
pop_eh
ok($I0, "Can push onto (empty) queue")
ok($I0, "Can push up to capacity onto queue")
}
}

sub vtable_push_pmc_overflow() {
Q:PIR {
$P0 = new ['FixedPMCQueue']
$I0 = 5
$P0 = $I0
$I1 = 5
$P0 = $I1
$P1 = box 1
L1:
push $P0, $P1
dec $I0
gt $I0, 0, L1
dec $I1
gt $I1, 0, L1
$I0 = 1
push_eh push_pmc_overflow
push $P0, $P1
Expand Down Expand Up @@ -205,19 +209,19 @@ sub vtable_get_integer() {
sub method_to_array() {
Q:PIR {
todo(0,"test .to_array()")
todo(0, "test .to_array()")
}
}

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

105 changes: 73 additions & 32 deletions t/pmc/fixedpmcqueue2.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,62 +44,86 @@ sub load_linalg_group() {

sub op_new() {
Q:PIR {
$I0 = 0
push_eh new_sanity_failure
$P0 = new ['FixedPMCQueue2']
ok(1)
goto new_sanity_end
$I0 = 1
new_sanity_failure:
ok(0)
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 ['FixedPMCQueue2']
$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 ['FixedPMCQueue2']
$S0 = typeof $P0
is($S0, 'FixedPMCQueue2')
is($S0, 'FixedPMCQueue2', "Isa 'FixedPMCQueue2'")
}
}

sub vtable_set_integer_native() {
Q:PIR {
$P0 = new ['FixedPMCQueue2']
$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)")
}
}

sub vtable_push_pmc() {
Q:PIR {
$P0 = new ['FixedPMCQueue2']
$P0 = 5
$I1 = 5
$P0 = $I1
$P1 = box 1
$I0 = 0
push_eh push_pmc_sanity_error
L1:
push $P0, $P1
ok(1)
goto push_pmc_sanity_end
dec $I1
gt $I1, 0, L1
$I0 = 1
push_pmc_sanity_error:
ok(0)
push_pmc_sanity_end:
pop_eh
ok($I0, "Can push up to capacity onto queue")
}
}

sub vtable_push_pmc_overflow() {
Q:PIR {
$P0 = new ['FixedPMCQueue2']
$I1 = 5
$P0 = $I1
$P1 = box 1
L1:
push $P0, $P1
dec $I1
gt $I1, 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 +134,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 ['FixedPMCQueue2']
$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 ['FixedPMCQueue2']
$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 ['FixedPMCQueue2']
$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 ['FixedPMCQueue2']
$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 163662d

Please sign in to comment.