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 CBA_fnc_findMin, improve CBA_fnc_findMax #207

Merged
merged 3 commits into from
Dec 2, 2015

Conversation

commy2
Copy link
Contributor

@commy2 commy2 commented Dec 2, 2015

[0,4,3,-2,1,5,2] call CBA_fnc_findMax

old method: 0.121507 ms for (8238/10000) loops
new method: 0.0360001 ms for (10000/10000) loops

CBA_fnc_findMin was broken.

@commy2 commy2 mentioned this pull request Dec 2, 2015
@MikeMatrix
Copy link
Contributor

👍

@Killswitch00
Copy link
Contributor

The array unit tests fail. To reproduce, run
h=[] spawn CBA_fnc_testArrays

18:52:33 Error in expression <riptName 'cba\arrays\findMax';[_this] params [["_array", [], [[]]]];if !(_ar>
18:52:33   Error position: <params [["_array", [], [[]]]];if !(_ar>
18:52:33   Error Params: Type Array, expected String
18:52:33 File x\cba\addons\arrays\fnc_findMax.sqf, line 5

@commy2
Copy link
Contributor Author

commy2 commented Dec 2, 2015

There are some errors from other functions as well, which is strange, because this PR only changes
findMin and findMax.

Errors from findMin and findMax are:

19:08:33 Error in expression <riptName 'cba\arrays\findMax';

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

if !(_ar>
19:08:33   Error position: <params [["_array", [], [[]]]];

if !(_ar>
19:08:33   Error Params: Type Array, expected String
19:08:33 File x\cba\addons\arrays\fnc_findMax.sqf, line 5
19:08:33 [7563,174.311,12.844,"x\cba\addons\arrays\test_findMax.sqf:13","Testing CBA_fnc_findMax"]
19:08:33 [7563,174.311,12.844,"x\cba\addons\arrays\test_findMax.sqf:15","Test OK: (CBA_fnc_findMax is defined)"]
19:08:33 [7563,174.311,12.844,"x\cba\addons\arrays\test_findMax.sqf:20","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7563,174.311,12.844,"x\cba\addons\arrays\test_findMax.sqf:25","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7563,174.311,12.844,"x\cba\addons\arrays\test_findMax.sqf:30","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7563,174.311,12.844,"x\cba\addons\arrays\test_findMax.sqf:35","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7563,174.312,12.844,"x\cba\addons\arrays\test_findMax.sqf:40","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7563,174.312,12.844,"x\cba\addons\arrays\test_findMax.sqf:45","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7563,174.312,12.844,"x\cba\addons\arrays\test_findMax.sqf:49","Test OK: (isNil "_result")"]
19:08:33 [7563,174.312,12.844,"x\cba\addons\arrays\test_findMax.sqf:53","Test OK: (isNil "_result")"]
19:08:33 [7563,174.312,12.844,"x\cba\addons\arrays\test_findMax.sqf:57","Test OK: (isNil "_result")"]
19:08:33 [7563,174.312,12.844,"x\cba\addons\arrays\test_findMax.sqf:61","Test OK: (isNil "_result")"]
19:08:33 [7563,174.312,12.844,"x\cba\addons\arrays\test_findMax.sqf:65","Test OK: (isNil "_result")"]
19:08:33 Error in expression <riptName 'cba\arrays\findMin';

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

if !(_ar>
19:08:33   Error position: <params [["_array", [], [[]]]];

if !(_ar>
19:08:33   Error Params: Type Array, expected String
19:08:33 File x\cba\addons\arrays\fnc_findMin.sqf, line 5
19:08:33 [7564,174.323,12.844,"x\cba\addons\arrays\test_findMin.sqf:12","Testing CBA_fnc_findMin"]
19:08:33 [7564,174.323,12.844,"x\cba\addons\arrays\test_findMin.sqf:14","Test OK: (CBA_fnc_findMin is defined)"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:19","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:24","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:29","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:34","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:39","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:44","Test OK: (_result isEqualTo _expected)"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:48","Test OK: (isNil "_result")"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:52","Test OK: (isNil "_result")"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:56","Test OK: (isNil "_result")"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:60","Test OK: (isNil "_result")"]
19:08:33 [7564,174.324,12.844,"x\cba\addons\arrays\test_findMin.sqf:64","Test OK: (isNil "_result")"]

@commy2
Copy link
Contributor Author

commy2 commented Dec 2, 2015

Seems like the results are all as expected and the error is the on screen warning from params alternate syntax when using wrong types as function arguments (intentional).

Note that it says Error Params: Type Array, expected String which should be the other way around. (Bug from BI)

@commy2
Copy link
Contributor Author

commy2 commented Dec 2, 2015

Commenting out these two tests removes the on screen / rpt warnings for findMin and findMax.

// Test invalid array given
_result = "not an array" call CBA_fnc_findMax;
TEST_TRUE(isNil "_result",_fn);
// Test invalid array given
_result = "not an array" call CBA_fnc_findMin;
TEST_TRUE(isNil "_result",_fn);

https://community.bistudio.com/wiki/params

In addition to simple parsing directly into variables, input can be tested in case it is undefined, of the wrong type or of the wrong size (if array) and substituted if necessary with default values. Since Arma 3 v1.53.132691, onscreen errors are displayed for when the input is of the wrong type or size.

@Killswitch00
Copy link
Contributor

That explains it. Thanks for the sciencing!

Killswitch00 added a commit that referenced this pull request Dec 2, 2015
fix CBA_fnc_findMin, improve CBA_fnc_findMax
@Killswitch00 Killswitch00 merged commit e23bea7 into master Dec 2, 2015
@Killswitch00 Killswitch00 added this to the 2.2.1 milestone Dec 3, 2015
@Killswitch00 Killswitch00 deleted the findMinMaxImprovements branch January 9, 2016 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants