Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make FixedFloatArray sorting actually work and add a test #925

  • Loading branch information...
commit 3f65128bb28e5b76c48d064b9bbc782fd3b4f4a7 1 parent b52608b
@leto leto authored
Showing with 23 additions and 5 deletions.
  1. +4 −4 src/pmc/fixedfloatarray.pmc
  2. +19 −1 t/pmc/fixedfloatarray.t
View
8 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<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.
@@ -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);
}
/*
View
20 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
Please sign in to comment.
Something went wrong with that request. Please try again.