Skip to content

Commit

Permalink
Merge branch 'release/0.21.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
garex committed Sep 26, 2018
2 parents 89a188b + 281832e commit 3ae4cdd
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
## Changelog ##


### 0.21.12 ###

Fix bug with scale sorting.

Negative values was sorted after zero value, but with reverse order: 10, 9, 8, 7, 1, 0, -10, -9, -8, -1. Now it fixed and order is correct: 10, 9, 8, 7, 1, 0, -1, -8, -9, -10.

Bug was hiding from us for almost 3 and half years and was reported by @justtoask2.


### 0.21.11 ###

Allow to use socket and IPv6 in database connection
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

**Tested up to:** 4.9

**Stable tag:** 0.21.11
**Stable tag:** 0.21.12

**License:** GPLv3

Expand Down
2 changes: 1 addition & 1 deletion src/Model/Passing.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function buildScalesWithRange()

$records = fRecordSet::buildFromArray('WpTesting_Model_Scale', array_values($result));
if ($this->createTest()->isSortScalesByScore()) {
$records = $records->sort('getValue', 'desc');
$records = $records->sortByCallback(array('WpTesting_Model_Scale', 'compareDescending'));
}
return $records;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Model/Scale.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public function getValue()
return $this->value;
}

public static function compareDescending(WpTesting_Model_Scale $a, WpTesting_Model_Scale $b)
{
if ($a->getValue() == $b->getValue()) {
return 0;
}

return ($a->getValue() > $b->getValue()) ? -1 : 1;
}

/**
* @return number
*/
Expand Down
34 changes: 34 additions & 0 deletions tests/phpunit/Model/ScaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,38 @@ public function testScaleValueAndMaximumAlwaysAvailable()
$this->assertEquals( 23, $this->scale->getValue());
$this->assertEquals(100, $this->scale->getMaximum());
}

public function testScalesSortedByValueFromMaxToMinIncludingNegative()
{
$records = fRecordSet::buildFromArray('WpTesting_Model_Scale', array(
$this->createScale(0),
$this->createScale(-10),
$this->createScale(50),
$this->createScale(100),
$this->createScale(-1000),
));

$sorted = $records->sortByCallback(array('WpTesting_Model_Scale', 'compareDescending'));

$values = array();
foreach ($sorted as $scale) {
$values[] = $scale->getValue();
}

$this->assertEquals(array(100.0, 50.0, 0.0, -10.0, -1000.0), $values);
}

/**
* @param int $value
*
* @return WpTesting_Model_Scale
*/
private function createScale($value)
{
$scale = new WpTesting_Model_Scale();
$scale->setRange(-1000, 1000);
$scale->setValue($value);

return $scale;
}
}
2 changes: 1 addition & 1 deletion wp-testing.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Wp-testing
* Plugin URI: http://wordpress.org/extend/plugins/wp-testing/
* Description: Helps to create psychological tests.
* Version: 0.21.11
* Version: 0.21.12
* Author: Alexander Ustimenko
* Author URI: http://ustimen.co
* License: GPL3
Expand Down

0 comments on commit 3ae4cdd

Please sign in to comment.