-
Notifications
You must be signed in to change notification settings - Fork 149
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
Added 4 New Array Functions #131
Changes from 5 commits
3adfb0e
058409d
e1f58c3
1a9ae13
232a7e6
52d47a0
9129ce8
0dfc4a2
50c75f6
43e8ec4
f4d2a80
6816ee4
aa136b5
1f22847
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_findNil | ||
|
||
Description: | ||
A function that returns the index of the first empty (nil) entry in an array. | ||
|
||
Parameters: | ||
The array to search in. | ||
|
||
Example: | ||
(begin example) | ||
_index = ["", Player, "test", nil, VARIABLE, nil] call CBA_fnc_findNil | ||
(end) | ||
|
||
Returns: | ||
Index of the first nil entry in the array. If there is no nil entry, the function returns -1 | ||
|
||
Author: | ||
joko // Jonas | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
scopeName "main"; | ||
|
||
{ | ||
private "_current"; | ||
_current = _x; | ||
if (isNil "_current") then { | ||
_forEachIndex breakOut "main"; | ||
}; | ||
} forEach _this; | ||
|
||
-1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_findNull | ||
|
||
Description: | ||
A function that returns the index of the first null entry in an array. | ||
|
||
Parameters: | ||
The array to search in. | ||
|
||
Example: | ||
(begin example) | ||
_index = ["", Player, "test", objNull, VARIABLE, ] call CBA_fnc_findNull | ||
(end) | ||
|
||
Returns: | ||
Index of the first null entry in the array. If there is no null entry, the function returns -1 | ||
|
||
Author: | ||
joko // Jonas | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
scopeName "main"; | ||
|
||
{ | ||
if (isNull _x) then { | ||
_forEachIndex breakOut "main"; | ||
}; | ||
} forEach _this; | ||
|
||
-1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_findTypeName | ||
|
||
Description: | ||
A function that returns the index of the first entry of the given type in an array. | ||
|
||
Parameters: | ||
0: Entry type to search for. Was not a string with a known type name it take the typeName from the input. | ||
1: A Array with Any type of Variable | ||
|
||
Example: | ||
(begin example) | ||
_index = ["OBJECT",["", Player, "test", nil, VARIABLE, nil]] call CBA_fnc_findTypeName | ||
(end) | ||
|
||
Returns: | ||
Index of the first entry of the indicated type in the array or -1 if no entry of the type could be found. | ||
|
||
Author: | ||
joko // Jonas | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
scopeName "main"; | ||
|
||
params ["_typeName", "_array"]; | ||
_typeName = toUpper _typeName; | ||
if !(_typeName in ["ARRAY", "BOOL", "CODE", "CONFIG", "CONTROL", "DISPLAY", "LOCALTION", "OBJECT", "SCALAR", "SCRIPT", "SIDE", "STRING", "TEXT", "TEAM_MEMBER", "NAMESPACE"]) then { | ||
_typeName = typeName _typeName; | ||
}; | ||
|
||
{ | ||
if (typeName _x == _typeName) then { | ||
_forEachIndex breakOut "main"; | ||
}; | ||
} forEach _array; | ||
|
||
-1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_findTypeOf | ||
|
||
Description: | ||
A function that returns the index of the first entry of the given type in an array. | ||
|
||
Parameters: | ||
0: Entry type to search for. Object or class name (as returned by the typeOf command). | ||
1: A Array with Any type of Variable | ||
|
||
Example: | ||
(begin example) | ||
_index = [Player, ["", Player, "test", nil, VARIABLE, nil]] call CBA_fnc_findTypeOf | ||
(end) | ||
|
||
Returns: | ||
Index of the first entry of the indicated type in the array or -1 if no entry of the type could be found. | ||
|
||
Author: | ||
joko // Jonas | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
scopeName "main"; | ||
|
||
params ["_typeOf", "_array"]; | ||
if (typeName _typeOf == "OBJECT") then { | ||
_typeOf = typeOf _typeOf; | ||
}; | ||
|
||
{ | ||
if (_x typeName == "OBJECT" && {typeOf _x == _typeOf}) then { | ||
_forEachIndex breakOut "main"; | ||
}; | ||
if (_x typeName == "STRING" && {_x == _typeOf}) then { | ||
_forEachIndex breakOut "main"; | ||
}; | ||
} forEach _array; | ||
|
||
-1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
// ---------------------------------------------------------------------------- | ||
#define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
|
||
SCRIPT(test_find); | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
private ["_original", "_expected", "_result", "_fn"]; | ||
|
||
_fn = "CBA_fnc_findNil"; | ||
LOG("Testing " + _fn); | ||
|
||
TEST_DEFINED("CBA_fnc_findNil",""); | ||
|
||
// Find First Nil Entry | ||
_original = ["", player, "", player, nil, "", player, nil]; | ||
_result = ["", player, "", player, nil, "", player, nil] call CBA_fnc_findNil; | ||
_expected = 4; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["", nil, "", player, nil, "", player, nil]; | ||
_result = ["", nil, "", player, nil, "", player, nil] call CBA_fnc_findNil; | ||
_expected = 1; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["", player, "", nil, nil, "", player, nil]; | ||
_result = ["", player, "", nil, nil, "", player, nil] call CBA_fnc_findNil; | ||
_expected = 3; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["", player, "", player, "", "", player, nil]; | ||
_result = ["", player, "", player, "", "", player, nil] call CBA_fnc_findNil; | ||
_expected = 7; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["", player, "", player, "", "", player, ""]; | ||
_result = ["", player, "", player, "", "", player, ""] call CBA_fnc_findNil; | ||
_expected = -1; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
|
||
|
||
_fn = "CBA_fnc_findNull"; | ||
LOG("Testing " + _fn); | ||
|
||
TEST_DEFINED("CBA_fnc_findNull",""); | ||
|
||
|
||
// Find First Null Entry | ||
_original = ["", player, "", player, objNull, "", player, displayNull]; | ||
_result = ["", player, "", player, objNull, "", player, displayNull] call CBA_fnc_findNull; | ||
_expected = 4; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["", grpNull, "", player, objNull, "", player, displayNull]; | ||
_result = ["", grpNull, "", player, objNull, "", player, displayNull] call CBA_fnc_findNull; | ||
_expected = 1; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["", player, "", scriptNull, objNull, "", player, displayNull]; | ||
_result = ["", player, "", scriptNull, objNull, "", player, displayNull] call CBA_fnc_findNull; | ||
_expected = 3; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["", player, "", player, "", "", player, displayNull]; | ||
_result = ["", player, "", player, "", "", player, displayNull] call CBA_fnc_findNull; | ||
_expected = 7; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
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. Good - these four tests above test for different kinds of null values (but a test for controlNull is missing). It also needs tests for
|
||
|
||
_original = ["", player, "", player, "", "", player, ""]; | ||
_result = ["", player, "", player, "", "", player, ""] call CBA_fnc_findNil; | ||
_expected = -1; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
|
||
|
||
|
||
|
||
_fn = "CBA_fnc_findTypeName"; | ||
LOG("Testing " + _fn); | ||
|
||
TEST_DEFINED("CBA_fnc_findTypeName",""); | ||
|
||
|
||
// Find First Type of Entry | ||
_original = ["OBJECT" ,["", player, "", player, objNull, "", player, displayNull]]; | ||
_result = ["OBJECT" ,["", player, "", player, objNull, "", player, displayNull]] call CBA_fnc_findTypeName; | ||
_expected = 4; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["OBJECT" ,["", "", "", player, objNull, "", player, displayNull]]; | ||
_result = ["OBJECT" ,["", "", "", player, objNull, "", player, displayNull]] call CBA_fnc_findTypeName; | ||
_expected = 3; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["CODE" ,["", player, {}, {}, objNull, "", player, displayNull]]; | ||
_result = ["CODE" ,["", player, {}, {}, objNull, "", player, displayNull]] call CBA_fnc_findTypeName; | ||
_expected = 2; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["STRING" ,[objNull, player, {}, player, objNull, "", player, displayNull]]; | ||
_result = ["STRING" ,[objNull, player, {}, player, objNull, "", player, displayNull]] call CBA_fnc_findTypeName; | ||
_expected = 5; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["OBJECT" ,["", "", "", "", "", "", "", displayNull]]; | ||
_result = ["OBJECT" ,["", "", "", "", "", "", "", displayNull]] call CBA_fnc_findTypeName; | ||
_expected = -1; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
|
||
|
||
_fn = "CBA_fnc_findTypOf"; | ||
LOG("Testing " + _fn); | ||
|
||
TEST_DEFINED("CBA_fnc_findTypOf",""); | ||
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. I can see that this unit test file hasn't been tested at all. Run it using
|
||
|
||
|
||
// Find First Type of Entry | ||
_original = [typeOf player ,["", player, "", player, objNull, "", player, displayNull]]; | ||
_result = [typeOf player ,["", player, "", player, objNull, "", player, displayNull]] call CBA_fnc_findTypOf; | ||
_expected = 4; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = [player ,["", "", "", player, objNull, "", player, displayNull]]; | ||
_result = [player ,["", "", "", player, objNull, "", player, displayNull]] call CBA_fnc_findTypOf; | ||
_expected = 3; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = [player ,["", player, {}, {}, objNull, "", player, displayNull]]; | ||
_result = [player ,["", player, {}, {}, objNull, "", player, displayNull]] call CBA_fnc_findTypOf; | ||
_expected = 2; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = [player ,[objNull, player, {}, player, objNull, "", player, displayNull]]; | ||
_result = [player ,[objNull, player, {}, player, objNull, "", player, displayNull]] call CBA_fnc_findTypOf; | ||
_expected = 5; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
|
||
_original = ["OBJECT" ,["", "", "", "", "", "", "", displayNull]]; | ||
_result = ["OBJECT" ,["", "", "", "", "", "", "", displayNull]] call CBA_fnc_findTypOf; | ||
_expected = -1; | ||
TEST_OP(str _original,==,str _expected,_fn); | ||
TEST_OP(str _result,==,str _expected,_fn); | ||
|
||
nil; |
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.
The three tests below all do the same thing as the first test above - look for the first literal
nil
element in the test arrays. Keep the first one, and change the three redundant tests to use