- Completed sort_compare routine to mimic 1.9.2, but using std::sort.
- Added blank task to the unit tests to prove the sorting is working
  (it wasn't), then fixed all.
This commit is contained in:
Paul Beckingham
2010-08-07 19:58:56 -04:00
parent c95a55128a
commit f83cc3f39a
3 changed files with 132 additions and 108 deletions

View File

@@ -614,21 +614,41 @@ bool sort_compare (int left, int right)
// nothing < something. // nothing < something.
if (cell_left == NULL && cell_right != NULL) if (cell_left == NULL && cell_right != NULL)
return (sort_type == Table::ascendingNumeric || {
sort_type == Table::ascendingCharacter || if (sort_type == Table::ascendingDueDate)
sort_type == Table::ascendingPriority || return true;
sort_type == Table::ascendingDate ||
sort_type == Table::ascendingDueDate || else if (sort_type == Table::descendingDueDate)
sort_type == Table::ascendingPeriod) ? true : false; return false;
else if (sort_type == Table::ascendingNumeric ||
sort_type == Table::ascendingCharacter ||
sort_type == Table::ascendingPriority ||
sort_type == Table::ascendingDate ||
sort_type == Table::ascendingPeriod)
return true;
return false;
}
// something > nothing. // something > nothing.
if (cell_left != NULL && cell_right == NULL) if (cell_left != NULL && cell_right == NULL)
return (sort_type == Table::ascendingNumeric || {
sort_type == Table::ascendingCharacter || if (sort_type == Table::ascendingDueDate)
sort_type == Table::ascendingPriority || return false;
sort_type == Table::ascendingDate ||
sort_type == Table::ascendingDueDate || else if (sort_type == Table::descendingDueDate)
sort_type == Table::ascendingPeriod) ? false : true; return true;
else if (sort_type == Table::ascendingNumeric ||
sort_type == Table::ascendingCharacter ||
sort_type == Table::ascendingPriority ||
sort_type == Table::ascendingDate ||
sort_type == Table::ascendingPeriod)
return false;
return true;
}
// Differing data - do a proper comparison. // Differing data - do a proper comparison.
if (cell_left && cell_right) if (cell_left && cell_right)
@@ -693,11 +713,11 @@ bool sort_compare (int left, int right)
{ {
// something > nothing. // something > nothing.
if ((std::string)*cell_left != "" && (std::string)*cell_right == "") if ((std::string)*cell_left != "" && (std::string)*cell_right == "")
return false; return true;
// nothing < something. // nothing < something.
else if ((std::string)*cell_left == "" && (std::string)*cell_right != "") else if ((std::string)*cell_left == "" && (std::string)*cell_right != "")
return true; return false;
else else
{ {

View File

@@ -126,6 +126,8 @@ private:
std::map <int, just> mJustification; std::map <int, just> mJustification;
std::map <int, bool> mCommify; std::map <int, bool> mCommify;
Grid mData; Grid mData;
// Sorting...
std::vector <int> mSortColumns; std::vector <int> mSortColumns;
std::map <int, order> mSortOrder; std::map <int, order> mSortOrder;

View File

@@ -40,137 +40,139 @@ if (open my $fh, '>', 'sorting.rc')
# Test assorted sort orders. # Test assorted sort orders.
qx{../task rc:sorting.rc add zero};
qx{../task rc:sorting.rc add priority:H project:A due:yesterday one}; qx{../task rc:sorting.rc add priority:H project:A due:yesterday one};
qx{../task rc:sorting.rc add priority:M project:B due:today two}; qx{../task rc:sorting.rc add priority:M project:B due:today two};
qx{../task rc:sorting.rc add priority:L project:C due:tomorrow three}; qx{../task rc:sorting.rc add priority:L project:C due:tomorrow three};
qx{../task rc:sorting.rc add priority:H project:C due:today four}; qx{../task rc:sorting.rc add priority:H project:C due:today four};
qx{../task rc:sorting.rc start 1}; qx{../task rc:sorting.rc start 2};
qx{../task rc:sorting.rc start 3}; qx{../task rc:sorting.rc start 4};
# pri:H pro:C due:today four # pri:H pro:C due:today four
# pri:H pro:A * due:yesterday one # pri:H pro:A * due:yesterday one
# pri:M pro:B due:today two # pri:M pro:B due:today two
# pri:L pro:C * due:tomorrow three # pri:L pro:C * due:tomorrow three
# zero
my %tests = my %tests =
( (
# Single sort column. # Single sort column.
'priority-' => '(?:one.+four|four.+one).+two.+three', 'priority-' => '(?:one.+four|four.+one).+two.+three.+zero',
'priority+' => 'three.+two.+(?:one.+four|four.+one)', 'priority+' => 'zero.+three.+two.+(?:one.+four|four.+one)',
'project-' => '(?:three.+four|four.+three).+two.+one', 'project-' => '(?:three.+four|four.+three).+two.+one.+zero',
'project+' => 'one.+two.+(?:three.+four|four.+three)', 'project+' => 'zero.+one.+two.+(?:three.+four|four.+three)',
'active-' => '(?:one.+three|three.+one).+(?:two.+four|four.+two)', 'active-' => '(?:one.+three|three.+one).+(?:zero.+two.+four|zero.+four.+two|two.+zero.+four|two.+four.+zero|four.+zero.+two|four.+two.+zero)',
'active+' => '(?:two.+four|four.+two).+(?:one.+three|three.+one)', 'active+' => '(?:zero.+two.+four|zero.+four.+two|two.+zero.+four|two.+four.+zero|four.+zero.+two|four.+two.+zero).+(?:one.+three|three.+one)',
'due-' => 'three.+(?:two.+four|four.+two).+one', 'due-' => 'three.+(?:two.+four|four.+two).+one.+zero',
'due+' => 'one.+(?:two.+four|four.+two).+three', 'due+' => 'one.+(?:two.+four|four.+two).+three.+zero',
'description-' => 'two.+three.+one.+four', 'description-' => 'zero.+two.+three.+one.+four',
'description+' => 'four.+one.+three.+two', 'description+' => 'four.+one.+three.+two.+zero',
# Two sort columns. # Two sort columns.
'priority-,project-' => 'four.+one.+two.+three', 'priority-,project-' => 'four.+one.+two.+three.+zero',
'priority-,project+' => 'one.+four.+two.+three', 'priority-,project+' => 'one.+four.+two.+three.+zero',
'priority+,project-' => 'three.+two.+four.+one', 'priority+,project-' => 'zero.+three.+two.+four.+one',
'priority+,project+' => 'three.+two.+one.+four', 'priority+,project+' => 'zero.+three.+two.+one.+four',
'priority-,active-' => 'one.+four.+two.+three', 'priority-,active-' => 'one.+four.+two.+three.+zero',
'priority-,active+' => 'four.+one.+two.+three', 'priority-,active+' => 'four.+one.+two.+three.+zero',
'priority+,active-' => 'three.+two.+one.+four', 'priority+,active-' => 'zero.+three.+two.+one.+four',
'priority+,active+' => 'three.+two.+four.+one', 'priority+,active+' => 'zero.+three.+two.+four.+one',
'priority-,due-' => 'four.+one.+two.+three', 'priority-,due-' => 'four.+one.+two.+three.+zero',
'priority-,due+' => 'one.+four.+two.+three', 'priority-,due+' => 'one.+four.+two.+three.+zero',
'priority+,due-' => 'three.+two.+four.+one', 'priority+,due-' => 'zero.+three.+two.+four.+one',
'priority+,due+' => 'three.+two.+one.+four', 'priority+,due+' => 'zero.+three.+two.+one.+four',
'priority-,description-' => 'one.+four.+two.+three', 'priority-,description-' => 'one.+four.+two.+three.+zero',
'priority-,description+' => 'four.+one.+two.+three', 'priority-,description+' => 'four.+one.+two.+three.+zero',
'priority+,description-' => 'three.+two.+one.+four', 'priority+,description-' => 'zero.+three.+two.+one.+four',
'priority+,description+' => 'three.+two.+four.+one', 'priority+,description+' => 'zero.+three.+two.+four.+one',
'project-,priority-' => 'four.+three.+two.+one', 'project-,priority-' => 'four.+three.+two.+one.+zero',
'project-,priority+' => 'three.+four.+two.+one', 'project-,priority+' => 'three.+four.+two.+one.+zero',
'project+,priority-' => 'one.+two.+four.+three', 'project+,priority-' => 'zero.+one.+two.+four.+three',
'project+,priority+' => 'one.+two.+three.+four', 'project+,priority+' => 'zero.+one.+two.+three.+four',
'project-,active-' => 'three.+four.+two.+one', 'project-,active-' => 'three.+four.+two.+one.+zero',
'project-,active+' => 'four.+three.+two.+one', 'project-,active+' => 'four.+three.+two.+one.+zero',
'project+,active-' => 'one.+two.+three.+four', 'project+,active-' => 'zero.+one.+two.+three.+four',
'project+,active+' => 'one.+two.+four.+three', 'project+,active+' => 'zero.+one.+two.+four.+three',
'project-,due-' => 'three.+four.+two.+one', 'project-,due-' => 'three.+four.+two.+one.+zero',
'project-,due+' => 'four.+three.+two.+one', 'project-,due+' => 'four.+three.+two.+one.+zero',
'project+,due-' => 'one.+two.+three.+four', 'project+,due-' => 'zero.+one.+two.+three.+four',
'project+,due+' => 'one.+two.+four.+three', 'project+,due+' => 'zero.+one.+two.+four.+three',
'project-,description-' => 'three.+four.+two.+one', 'project-,description-' => 'three.+four.+two.+one.+zero',
'project-,description+' => 'four.+three.+two.+one', 'project-,description+' => 'four.+three.+two.+one.+zero',
'project+,description-' => 'one.+two.+three.+four', 'project+,description-' => 'zero.+one.+two.+three.+four',
'project+,description+' => 'one.+two.+four.+three', 'project+,description+' => 'zero.+one.+two.+four.+three',
'active-,priority-' => 'one.+three.+four.+two', 'active-,priority-' => 'one.+three.+four.+two.+zero',
'active-,priority+' => 'three.+one.+two.+four', 'active-,priority+' => 'three.+one.+zero.+two.+four',
'active+,priority-' => 'four.+two.+one.+three', 'active+,priority-' => 'four.+two.+zero.+one.+three',
'active+,priority+' => 'two.+four.+three.+one', 'active+,priority+' => 'zero.+two.+four.+three.+one',
'active-,project-' => 'three.+one.+four.+two', 'active-,project-' => 'three.+one.+four.+two.+zero',
'active-,project+' => 'one.+three.+two.+four', 'active-,project+' => 'one.+three.+zero.+two.+four',
'active+,project-' => 'four.+two.+three.+one', 'active+,project-' => 'four.+two.+zero.+three.+one',
'active+,project+' => 'two.+four.+one.+three', 'active+,project+' => 'zero.+two.+four.+one.+three',
'active-,due-' => 'three.+one.+(?:four.+two|two.+four)', 'active-,due-' => 'three.+one.+(?:four.+two|two.+four).+zero',
'active-,due+' => 'one.+three.+(?:four.+two|two.+four)', 'active-,due+' => 'one.+three.+(?:four.+two|two.+four).+zero',
'active+,due-' => '(?:four.+two|two.+four).+three.+one', 'active+,due-' => '(?:four.+two|two.+four).+zero.+three.+one',
'active+,due+' => '(?:four.+two|two.+four).+one.+three', 'active+,due+' => '(?:four.+two|two.+four).+zero.+one.+three',
'active-,description-' => 'three.+one.+two.+four', 'active-,description-' => 'three.+one.+zero.+two.+four',
'active-,description+' => 'one.+three.+four.+two', 'active-,description+' => 'one.+three.+four.+two.+zero',
'active+,description-' => 'two.+four.+three.+one', 'active+,description-' => 'zero.+two.+four.+three.+one',
'active+,description+' => 'four.+two.+one.+three', 'active+,description+' => 'four.+two.+zero.+one.+three',
'due-,priority-' => 'three.+four.+two.+one', 'due-,priority-' => 'three.+four.+two.+one.+zero',
'due-,priority+' => 'three.+two.+four.+one', 'due-,priority+' => 'three.+two.+four.+one.+zero',
'due+,priority-' => 'one.+four.+two.+three', 'due+,priority-' => 'one.+four.+two.+three.+zero',
'due+,priority+' => 'one.+two.+four.+three', 'due+,priority+' => 'one.+two.+four.+three.+zero',
'due-,project-' => 'three.+four.+two.+one', 'due-,project-' => 'three.+four.+two.+one.+zero',
'due-,project+' => 'three.+two.+four.+one', 'due-,project+' => 'three.+two.+four.+one.+zero',
'due+,project-' => 'one.+four.+two.+three', 'due+,project-' => 'one.+four.+two.+three.+zero',
'due+,project+' => 'one.+two.+four.+three', 'due+,project+' => 'one.+two.+four.+three.+zero',
'due-,active-' => 'three.+(?:four.+two|two.+four).+one', 'due-,active-' => 'three.+(?:four.+two|two.+four).+one.+zero',
'due-,active+' => 'three.+(?:four.+two|two.+four).+one', 'due-,active+' => 'three.+(?:four.+two|two.+four).+one.+zero',
'due+,active-' => 'one.+(?:four.+two|two.+four).+three', 'due+,active-' => 'one.+(?:four.+two|two.+four).+three.+zero',
'due+,active+' => 'one.+(?:four.+two|two.+four).+three', 'due+,active+' => 'one.+(?:four.+two|two.+four).+three.+zero',
'due-,description-' => 'three.+two.+four.+one', 'due-,description-' => 'three.+two.+four.+one.+zero',
'due-,description+' => 'three.+four.+two.+one', 'due-,description+' => 'three.+four.+two.+one.+zero',
'due+,description-' => 'one.+two.+four.+three', 'due+,description-' => 'one.+two.+four.+three.+zero',
'due+,description+' => 'one.+four.+two.+three', 'due+,description+' => 'one.+four.+two.+three.+zero',
'description-,priority-' => 'two.+three.+one.+four', 'description-,priority-' => 'zero.+two.+three.+one.+four',
'description-,priority+' => 'two.+three.+one.+four', 'description-,priority+' => 'zero.+two.+three.+one.+four',
'description+,priority-' => 'four.+one.+three.+two', 'description+,priority-' => 'four.+one.+three.+two.+zero',
'description+,priority+' => 'four.+one.+three.+two', 'description+,priority+' => 'four.+one.+three.+two.+zero',
'description-,project-' => 'two.+three.+one.+four', 'description-,project-' => 'zero.+two.+three.+one.+four',
'description-,project+' => 'two.+three.+one.+four', 'description-,project+' => 'zero.+two.+three.+one.+four',
'description+,project-' => 'four.+one.+three.+two', 'description+,project-' => 'four.+one.+three.+two.+zero',
'description+,project+' => 'four.+one.+three.+two', 'description+,project+' => 'four.+one.+three.+two.+zero',
'description-,active-' => 'two.+three.+one.+four', 'description-,active-' => 'zero.+two.+three.+one.+four',
'description-,active+' => 'two.+three.+one.+four', 'description-,active+' => 'zero.+two.+three.+one.+four',
'description+,active-' => 'four.+one.+three.+two', 'description+,active-' => 'four.+one.+three.+two.+zero',
'description+,active+' => 'four.+one.+three.+two', 'description+,active+' => 'four.+one.+three.+two.+zero',
'description-,due-' => 'two.+three.+one.+four', 'description-,due-' => 'zero.+two.+three.+one.+four',
'description-,due+' => 'two.+three.+one.+four', 'description-,due+' => 'zero.+two.+three.+one.+four',
'description+,due-' => 'four.+one.+three.+two', 'description+,due-' => 'four.+one.+three.+two.+zero',
'description+,due+' => 'four.+one.+three.+two', 'description+,due+' => 'four.+one.+three.+two.+zero',
# Four sort columns. # Four sort columns.
'active+,project+,due+,priority+' => 'two.+four.+one.+three', 'active+,project+,due+,priority+' => 'zero.+two.+four.+one.+three',
'project+,due+,priority+,active+' => 'one.+two.+four.+three', 'project+,due+,priority+,active+' => 'zero.+one.+two.+four.+three',
); );
for my $sort (sort keys %tests) for my $sort (sort keys %tests)