From 3f65128bb28e5b76c48d064b9bbc782fd3b4f4a7 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 14 Jan 2013 23:57:29 -0800 Subject: [PATCH] Make FixedFloatArray sorting actually work and add a test #925 --- src/pmc/fixedfloatarray.pmc | 8 ++++---- t/pmc/fixedfloatarray.t | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/pmc/fixedfloatarray.pmc b/src/pmc/fixedfloatarray.pmc index 576f440646..a26cdee201 100644 --- a/src/pmc/fixedfloatarray.pmc +++ b/src/pmc/fixedfloatarray.pmc @@ -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); @@ -581,7 +581,7 @@ Reverse the contents of the array. =over 4 -=item C +=item C INTVAL compare function for qsort usage. @@ -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); } /* diff --git a/t/pmc/fixedfloatarray.t b/t/pmc/fixedfloatarray.t index 529c82382e..8d221a3994 100644 --- a/t/pmc/fixedfloatarray.t +++ b/t/pmc/fixedfloatarray.t @@ -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() @@ -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