-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add 2 New Array Functions #143
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a2f6dfa
add getHightestVaule
jokoho48 f94e787
Updated names of findMax and findMin, improved documentation, improve…
MikeMatrix 7dd0d45
Merge pull request #1 from MikeMatrix/addNewArrayFunctions
jokoho48 fa98055
Fix Spelling Issue in Command
jokoho48 5e42e56
Documentation fixes
MikeMatrix 8931070
Merge pull request #5 from MikeMatrix/addNewArrayFunctions
jokoho48 c76a338
Merge branch 'master' into addNewArrayFunctions
jokoho48 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_findMax | ||
|
||
Description: | ||
Find smallest numeric value with index in an array. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. findMax looks for the largest ("biggest") value |
||
|
||
Parameters: | ||
_array: Array with Numbers | ||
|
||
Example: | ||
(begin example) | ||
_result = [_array] call CBA_fnc_findMax | ||
(end) | ||
|
||
Returns: | ||
_max: biggest value in array | ||
_index: index of the biggest value in array | ||
nil on failure | ||
|
||
Author: | ||
joko // Jonas | ||
|
||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
SCRIPT(findMax); | ||
|
||
private ["_index"]; | ||
|
||
if (!IS_ARRAY(_this)) exitWith {nil}; | ||
if (_this isEqualTo []) exitWith {nil}; | ||
|
||
params ["_max"]; | ||
_index = 0; | ||
|
||
{ | ||
if (isNil "_x" || {(typeName _x) != (typeName 0)}) exitWith {_max = nil; _index = nil;}; | ||
if (_max < _x) then {_max = _x; _index = _forEachIndex}; | ||
} forEach _this; | ||
|
||
if (isNil "_max") exitWith {nil}; | ||
[_max, _index] // Return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_findMin | ||
|
||
Description: | ||
Find biggest numeric value with index in an array. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. findMin looks for the smallest value |
||
|
||
Parameters: | ||
_array: Array with Numbers | ||
|
||
Example: | ||
(begin example) | ||
_result = [_array] call CBA_fnc_findMin | ||
(end) | ||
|
||
Returns: | ||
_min: smallest value in array | ||
_index: index of the smallest value in array | ||
nil on failure | ||
|
||
Author: | ||
joko // Jonas | ||
|
||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
SCRIPT(findMin); | ||
|
||
private ["_index"]; | ||
|
||
if (!IS_ARRAY(_this)) exitWith {nil}; | ||
if (_this isEqualTo []) exitWith {nil}; | ||
|
||
params ["_min"]; | ||
_index = 0; | ||
|
||
{ | ||
if (isNil "_x" || {(typeName _x) != (typeName 0)}) exitWith {_max = nil; _index = nil;}; | ||
if (_min > _x) then {_min = _x; _index = _forEachIndex}; | ||
} forEach _this; | ||
|
||
if (isNil "_max") exitWith {nil}; | ||
[_min, _index] // Return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// ---------------------------------------------------------------------------- | ||
#define DEBUG_MODE_FULL | ||
#define DEBUG_SYNCHRONOUS | ||
#include "script_component.hpp" | ||
|
||
SCRIPT(test_findMax); | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
private ["_original", "_expected", "_result", "_fn"]; | ||
|
||
_fn = "CBA_fnc_findMax"; | ||
LOG("Testing " + _fn); | ||
|
||
TEST_DEFINED("CBA_fnc_findMax",""); | ||
|
||
// Test descending array | ||
_result = [5, 4, 3, 2, 1] call CBA_fnc_findMax; | ||
_expected = [5, 0]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test ascending array | ||
_result = [1, 2, 3, 4, 5] call CBA_fnc_findMax; | ||
_expected = [5, 4]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test unordered array | ||
_result = [2, 15, 0, 4, 1] call CBA_fnc_findMax; | ||
_expected = [15, 1]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test descending negative values array | ||
_result = [-1, -2, -3, -4, -5] call CBA_fnc_findMax; | ||
_expected = [-1, 0]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test unordered array with negative values | ||
_result = [2, 15, 3, -3, 0] call CBA_fnc_findMax; | ||
_expected = [15, 1]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test unordered array with duplicate max values | ||
_result = [2, 15, 15, -3, -3] call CBA_fnc_findMax; | ||
_expected = [15, 1]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test invalid parameter array with bool | ||
_result = [1, true, 3, 4, 5] call CBA_fnc_findMax; | ||
TEST_TRUE(isNil "_result",_fn); | ||
|
||
// Test invalid parameter array with nil | ||
_result = [1, nil, 3, 4, 5] call CBA_fnc_findMax; | ||
TEST_TRUE(isNil "_result",_fn); | ||
|
||
// Test invalid parameter array with string | ||
_result = [1, "not a number", 3, 4, 5] call CBA_fnc_findMax; | ||
TEST_TRUE(isNil "_result",_fn); | ||
|
||
// Test invalid array given | ||
_result = "not an array" call CBA_fnc_findMax; | ||
TEST_TRUE(isNil "_result",_fn); | ||
|
||
// Test empty array given | ||
_result = [] call CBA_fnc_findMax; | ||
TEST_TRUE(isNil "_result",_fn); | ||
|
||
nil; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// ---------------------------------------------------------------------------- | ||
#define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
|
||
SCRIPT(test_findMax); | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
private ["_original", "_expected", "_result", "_fn"]; | ||
|
||
_fn = "CBA_fnc_findMin"; | ||
LOG("Testing " + _fn); | ||
|
||
TEST_DEFINED("CBA_fnc_findMin",""); | ||
|
||
// Test descending array | ||
_result = [5, 4, 3, 2, 1] call CBA_fnc_findMin; | ||
_expected = [1, 4]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test ascending array | ||
_result = [1, 2, 3, 4, 5] call CBA_fnc_findMin; | ||
_expected = [1, 0]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test unordered array | ||
_result = [2, 15, 0, 4, 1] call CBA_fnc_findMin; | ||
_expected = [0, 2]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test descending negative values array | ||
_result = [-1, -2, -3, -4, -5] call CBA_fnc_findMin; | ||
_expected = [-5, 4]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test unordered array with negative values | ||
_result = [2, 15, 3, -3, 0] call CBA_fnc_findMin; | ||
_expected = [-3, 3]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test unordered array with duplicate max values | ||
_result = [2, 15, 15, -3, -3] call CBA_fnc_findMin; | ||
_expected = [-3, 3]; | ||
TEST_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
// Test invalid parameter array with bool | ||
_result = [1, true, 3, 4, 5] call CBA_fnc_findMin; | ||
TEST_TRUE(isNil "_result",_fn); | ||
|
||
// Test invalid parameter array with nil | ||
_result = [1, nil, 3, 4, 5] call CBA_fnc_findMin; | ||
TEST_TRUE(isNil "_result",_fn); | ||
|
||
// Test invalid parameter array with string | ||
_result = [1, "not a number", 3, 4, 5] call CBA_fnc_findMin; | ||
TEST_TRUE(isNil "_result",_fn); | ||
|
||
// Test invalid array given | ||
_result = "not an array" call CBA_fnc_findMin; | ||
TEST_TRUE(isNil "_result",_fn); | ||
|
||
// Test empty array given | ||
_result = [] call CBA_fnc_findMin; | ||
TEST_TRUE(isNil "_result",_fn); | ||
|
||
nil; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the description for findMin below.