From 7c0d17ef7cd6a2fc34857c6890c1a4f13d1fd6ad Mon Sep 17 00:00:00 2001 From: Paul Cochrane Date: Sun, 24 Mar 2013 11:57:00 +0100 Subject: [PATCH 1/3] [GH #927] Added tests for sort() method of ResizableFloatArray PMC --- t/pmc/resizablefloatarray.t | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/t/pmc/resizablefloatarray.t b/t/pmc/resizablefloatarray.t index 0c17c82bf8..a0bfc73060 100644 --- a/t/pmc/resizablefloatarray.t +++ b/t/pmc/resizablefloatarray.t @@ -16,7 +16,7 @@ out-of-bounds test. Checks INT and PMC keys. =cut -.const int TESTS = 63 +.const int TESTS = 72 .const num PRECISION = 1e-6 .sub 'test' :main @@ -49,6 +49,7 @@ out-of-bounds test. Checks INT and PMC keys. check_interface() get_iter() 'clone'() + test_sort() method_reverse() .end @@ -459,6 +460,36 @@ out-of-bounds test. Checks INT and PMC keys. nok(0, 'clone made an evil clone') .end +.sub test_sort + .local pmc array + array = new ['ResizableFloatArray'], 4 + set array[0], 10.2 + set array[1], 3.0 + set array[2], 5.85 + set array[3], -1.7 + array.'sort'() + $N0 = array[0] + is($N0, -1.7, 'sort works - 1st element correct') + $N1 = array[1] + is($N1, 3.0, 'sort works - 2nd element correct') + $N2 = array[2] + is($N2, 5.85, 'sort works - 3rd element correct') + $N3 = array[3] + is($N3, 10.2, 'sort works - 4th element correct') + push array, 3.5 + array.'sort'() + $N0 = array[0] + is($N0, -1.7, 'sort works - 1st element correct after resize') + $N1 = array[1] + is($N1, 3.0, 'sort works - 2nd element correct after resize') + $N2 = array[2] + is($N2, 3.5, 'sort works - 3rd element correct after resize') + $N3 = array[3] + is($N3, 5.85, 'sort works - 4th element correct after resize') + $N4 = array[4] + is($N4, 10.2, 'sort works - 5th element correct after resize') +.end + .sub method_reverse .local pmc array array = new ['ResizableFloatArray'] From 76e83f7ed0da121bc84d80fd5b0b8d61bef30bdf Mon Sep 17 00:00:00 2001 From: Paul Cochrane Date: Sun, 24 Mar 2013 14:12:16 +0100 Subject: [PATCH 2/3] [GH# 927] Test output more specific wrt how float array was resized --- t/pmc/resizablefloatarray.t | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/t/pmc/resizablefloatarray.t b/t/pmc/resizablefloatarray.t index a0bfc73060..a277a2ae56 100644 --- a/t/pmc/resizablefloatarray.t +++ b/t/pmc/resizablefloatarray.t @@ -479,15 +479,15 @@ out-of-bounds test. Checks INT and PMC keys. push array, 3.5 array.'sort'() $N0 = array[0] - is($N0, -1.7, 'sort works - 1st element correct after resize') + is($N0, -1.7, 'sort works - 1st element correct after push') $N1 = array[1] - is($N1, 3.0, 'sort works - 2nd element correct after resize') + is($N1, 3.0, 'sort works - 2nd element correct after push') $N2 = array[2] - is($N2, 3.5, 'sort works - 3rd element correct after resize') + is($N2, 3.5, 'sort works - 3rd element correct after push') $N3 = array[3] - is($N3, 5.85, 'sort works - 4th element correct after resize') + is($N3, 5.85, 'sort works - 4th element correct after push') $N4 = array[4] - is($N4, 10.2, 'sort works - 5th element correct after resize') + is($N4, 10.2, 'sort works - 5th element correct after push') .end .sub method_reverse From fee04de31acf0ce35b0c146c6d94aa492537d33a Mon Sep 17 00:00:00 2001 From: Paul Cochrane Date: Sun, 24 Mar 2013 15:25:26 +0100 Subject: [PATCH 3/3] [GH #927] Test sort() after unshift in ResizableFloatArray It's probably a good idea to check if sorting after an unshift works as well as the currently available tests for simply sorting and for sorting after a push. This way we test the interaction between resizing and sorting. --- t/pmc/resizablefloatarray.t | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/t/pmc/resizablefloatarray.t b/t/pmc/resizablefloatarray.t index a277a2ae56..89d1125787 100644 --- a/t/pmc/resizablefloatarray.t +++ b/t/pmc/resizablefloatarray.t @@ -16,7 +16,7 @@ out-of-bounds test. Checks INT and PMC keys. =cut -.const int TESTS = 72 +.const int TESTS = 78 .const num PRECISION = 1e-6 .sub 'test' :main @@ -488,6 +488,20 @@ out-of-bounds test. Checks INT and PMC keys. is($N3, 5.85, 'sort works - 4th element correct after push') $N4 = array[4] is($N4, 10.2, 'sort works - 5th element correct after push') + unshift array, 7.2 + array.'sort'() + $N0 = array[0] + is($N0, -1.7, 'sort works - 1st element correct after unshift') + $N1 = array[1] + is($N1, 3.0, 'sort works - 2nd element correct after unshift') + $N2 = array[2] + is($N2, 3.5, 'sort works - 3rd element correct after unshift') + $N3 = array[3] + is($N3, 5.85, 'sort works - 4th element correct after unshift') + $N4 = array[4] + is($N4, 7.2, 'sort works - 5th element correct after unshift') + $N5 = array[5] + is($N5, 10.2, 'sort works - 6th element correct after unshift') .end .sub method_reverse