Skip to content

Commit

Permalink
Make FixedFloatArray sorting actually work and add a test #925
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Jan 15, 2013
1 parent b52608b commit 3f65128
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/pmc/fixedfloatarray.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ stored FLOATVALs. It uses Float PMCs to do all necessary conversions.
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */

PARROT_PURE_FUNCTION
static int auxcmpfunc(ARGIN(const INTVAL *i), ARGIN(const INTVAL *j))
static int auxcmpfunc(ARGIN(const FLOATVAL *i), ARGIN(const FLOATVAL *j))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

Expand Down Expand Up @@ -581,7 +581,7 @@ Reverse the contents of the array.

=over 4

=item C<static int auxcmpfunc(const INTVAL *i, const INTVAL *j)>
=item C<static int auxcmpfunc(const FLOATVAL *i, const FLOATVAL *j)>

INTVAL compare function for qsort usage.

Expand All @@ -591,10 +591,10 @@ INTVAL compare function for qsort usage.

PARROT_PURE_FUNCTION
static int
auxcmpfunc(ARGIN(const INTVAL *i), ARGIN(const INTVAL *j))
auxcmpfunc(ARGIN(const FLOATVAL *i), ARGIN(const FLOATVAL *j))
{
ASSERT_ARGS(auxcmpfunc)
return (int) *i - *j;
return (int) (*i - *j);
}

/*
Expand Down
20 changes: 19 additions & 1 deletion t/pmc/fixedfloatarray.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ out-of-bounds test. Checks INT and PMC keys.
.sub main :main
.include 'fp_equality.pasm'
.include 'test_more.pir'
plan(32)
plan(36)

array_size_tests()
element_set_tests()
Expand All @@ -32,6 +32,24 @@ out-of-bounds test. Checks INT and PMC keys.
test_new_style_init()
test_invalid_init_tt1509()
test_get_string()
test_sort()
.end

.sub test_sort
$P0 = new ['FixedFloatArray'], 4
set $P0[0],10.0
set $P0[1],5.0
set $P0[2],3.0
set $P0[3],1.0
$P0.'sort'()
$I0 = $P0[0]
is($I0,1,'sort works')
$I1 = $P0[1]
is($I1,3,'sort works')
$I2 = $P0[2]
is($I2,5,'sort works')
$I3 = $P0[3]
is($I3,10,'sort works')
.end

.sub array_size_tests
Expand Down

0 comments on commit 3f65128

Please sign in to comment.