Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix findMax for arrays with duplicates #1025

Merged
merged 3 commits into from
Nov 21, 2018
Merged

fix findMax for arrays with duplicates #1025

merged 3 commits into from
Nov 21, 2018

Conversation

commy2
Copy link
Contributor

@commy2 commy2 commented Nov 16, 2018

When merged this pull request will:

  • In case of duplicates, findMax should report the rightmost maximum, while findMin should report the leftmost minimum.

Same reasoning as https://stackoverflow.com/questions/26584510/why-does-stdmax-return-the-wrong-value

min of two equivalent elements should return the first parameter, and max should return the [last]. This definition preserves a few properties that you'd expect, most notably

  • the pair (min(x,y), max(x,y)) is either (x,y) or (y,x),
    and
  • if x and y are distinct, then min(x,y) and max(x,y) are distinct

@commy2 commy2 added the Bug Fix label Nov 16, 2018
@commy2 commy2 added this to the 3.9.1 milestone Nov 16, 2018
@commy2
Copy link
Contributor Author

commy2 commented Nov 21, 2018

execVM "\x\cba\addons\arrays\test_findMax.sqf";
RPT log
 1:17:31 [CBA] (arrays) LOG: Testing CBA_fnc_findMax x\cba\addons\arrays\test_findMax.sqf:13
 1:17:31 [CBA] (arrays) Test OK: (CBA_fnc_findMax is defined) x\cba\addons\arrays\test_findMax.sqf:15
 1:17:31 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:20
 1:17:31 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:25
 1:17:31 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:30
 1:17:31 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:35
 1:17:31 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:40
 1:17:31 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:45
 1:17:31 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMax.sqf:49
 1:17:31 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMax.sqf:53
 1:17:31 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMax.sqf:57
 1:17:31 Error in expression <riptName 'cba\arrays\findMax';

[_this] params [["_array", [], [[]]]];

if !(_ar>
 1:17:31   Error position: <params [["_array", [], [[]]]];

if !(_ar>
 1:17:31   Error Params: Type String, expected Array
 1:17:31 File \x\cba\addons\arrays\fnc_findMax.sqf [CBA_fnc_findMax], line 1810
 1:17:31 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMax.sqf:61
 1:17:31 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMax.sqf:65

That one params error is from // Test invalid parameter array with string, so expected. Result is correct.

@commy2 commy2 merged commit d7aceff into master Nov 21, 2018
@commy2 commy2 deleted the fix_findMax branch November 21, 2018 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants