-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into optional-file-for-r…
…epository-settings
- Loading branch information
Showing
13 changed files
with
570 additions
and
87 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
language: python | ||
python: | ||
- '3.4' | ||
script: | ||
- python3 tools/sqf_validator.py | ||
- python3 tools/config_style_checker.py |
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
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,59 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_hashFilter | ||
Description: | ||
Iterate through all keys and values in a Hash. | ||
If function returns false, the key is removed from the hash (just like `[] select {}`) | ||
Data passed to the function on each iteration, | ||
* _key - Key from the Hash. | ||
* _value - The value from the Hash corresponding to _key. | ||
See <CBA_fnc_hashCreate>. | ||
Parameters: | ||
_hash - Hash to iterate [Array which is a Hash structure] | ||
_code - Function to call with each pair which returns a bool (false will remove key from hash) [Code] | ||
Returns: | ||
Number of removed entrys [Number] | ||
Example: | ||
(begin example) | ||
_hash = [[["A1", 1], ["A2", 1], ["B", 2], ["C", 3], ["D1", 4], ["D2", 4], ["E1", 5], ["E2", 5]]] call CBA_fnc_hashCreate; | ||
_removeOddValues = { | ||
diag_log format ["Key: %1, Value: %2", _key, _value]; | ||
((_value % 2) == 0) | ||
}; | ||
_removedCount = [_hash, _removeOddValues] call CBA_fnc_hashFilter; | ||
(end) | ||
Author: | ||
PabstMirror | ||
---------------------------------------------------------------------------- */ | ||
//#define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
#include "script_hashes.hpp" | ||
|
||
SCRIPT(hashFilter); | ||
|
||
// ----------------------------------------------------------------------------- | ||
params [["_hash", [], [[]]], ["_code", {}, [{}]]]; | ||
|
||
_hash params ["", "_keys", "_values"]; | ||
|
||
private _removedKeys = 0; | ||
|
||
{ | ||
private _key = _x; | ||
private _index = _forEachIndex - _removedKeys; | ||
private _value = _values select _index; | ||
if (!(call _code)) then { // If code returns false, delete the key/value from hash | ||
_keys deleteAt _index; | ||
_values deleteAt _index; | ||
_removedKeys = _removedKeys + 1; | ||
}; | ||
nil | ||
} forEach +_keys; // Create copy of _keys as the original can be modified during iteration | ||
|
||
_removedKeys // 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,60 @@ | ||
// ---------------------------------------------------------------------------- | ||
#define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
|
||
SCRIPT(test_hashFilter); | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
private ["_hash", "_expected", "_sumKeys", "_sumValues", "_totalIterations", "_removeOddValues"]; | ||
|
||
_fn = "CBA_fnc_hashFilter"; | ||
LOG("Testing " + _fn); | ||
|
||
TEST_DEFINED("CBA_fnc_hashFilter",""); | ||
|
||
_hash = [[[1, 12], [5, 25]], 88] call CBA_fnc_hashCreate; | ||
|
||
_sumKeys = 0; | ||
_sumValues = 0; | ||
_totalIterations = 0; | ||
|
||
[_hash, | ||
{ | ||
ADD(_sumKeys,_key); | ||
ADD(_sumValues,_value); | ||
INC(_totalIterations); | ||
true | ||
}] call CBA_fnc_hashFilter; | ||
|
||
_expected = 6; | ||
TEST_OP(_sumKeys,==,_expected,""); | ||
_expected = 37; | ||
TEST_OP(_sumValues,==,_expected,""); | ||
_expected = 2; | ||
TEST_OP(_totalIterations,==,_expected,""); | ||
|
||
|
||
_hash = [[["A1", 1], ["A2", 1], ["B", 2], ["C", 3], ["D1", 4], ["D2", 4], ["E1", 5], ["E2", 5]]] call CBA_fnc_hashCreate; | ||
|
||
_sumValues = 0; | ||
_totalIterations = 0; | ||
|
||
_removeOddValues = { | ||
ADD(_sumValues,_value); | ||
INC(_totalIterations); | ||
((_value % 2) == 0) | ||
}; | ||
_ret = [_hash, _removeOddValues] call CBA_fnc_hashFilter; | ||
|
||
_expected = 5; | ||
TEST_OP(_ret,isEqualTo,_expected,""); | ||
_expected = ["B", "D1", "D2"]; | ||
TEST_OP(_hash select 1,isEqualTo,_expected,""); | ||
_expected = [2, 4, 4]; | ||
TEST_OP(_hash select 2,isEqualTo,_expected,""); | ||
_expected = 25; | ||
TEST_OP(_sumValues,==,_expected,""); | ||
_expected = 8; | ||
TEST_OP(_totalIterations,==,_expected,""); | ||
|
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
Oops, something went wrong.