Skip to content

Commit

Permalink
Merge pull request #123 from CBATeam/UnitTestLogging
Browse files Browse the repository at this point in the history
Added unit test macros that log success/failure. Fixes #29
  • Loading branch information
Killswitch00 committed Aug 17, 2015
2 parents 6a6dcec + 130234e commit 8eff8ea
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 158 deletions.
26 changes: 13 additions & 13 deletions addons/arrays/test_filter.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,45 @@ SCRIPT(test_filter);
private ["_original", "_expected", "_result", "_fn"];

_fn = "CBA_fnc_filter";
ASSERT_DEFINED("CBA_fnc_filter","");

LOG("Testing " + _fn);

TEST_DEFINED("CBA_fnc_filter","");

// Filter to new array.
_original = [];
_result = [[], { _x * 10 }] call CBA_fnc_filter;
_expected = [];
ASSERT_OP(str _result,==,str _expected,_fn);
ASSERT_OP(str _original,==,str _expected,_fn);
TEST_OP(str _result,==,str _expected,_fn);
TEST_OP(str _original,==,str _expected,_fn);

_original = [1, 2, 3];
_result = [_original, { _x + 1 }] call CBA_fnc_filter;
_expected = [2, 3, 4];
ASSERT_OP(str _result,==,str _expected,_fn);
ASSERT_OP(str _original,!=,str _expected,_fn);
TEST_OP(str _result,==,str _expected,_fn);
TEST_OP(str _original,!=,str _expected,_fn);

_original = [1, 2, 3];
_result = [_original, { _x }, false] call CBA_fnc_filter;
_expected = [1, 2, 3];
ASSERT_OP(str _result,==,str _expected,_fn);
TEST_OP(str _result,==,str _expected,_fn);

// Filter in place.
_original = [];
_result = [_original, { _x * 10 }, true] call CBA_fnc_filter;
_expected = [];
ASSERT_OP(str _original,==,str _expected,_fn);
ASSERT_OP(str _result,==,str _expected,_fn);
TEST_OP(str _original,==,str _expected,_fn);
TEST_OP(str _result,==,str _expected,_fn);

_original = [1, 2, 3];
_result = [_original, { _x + 1 }, true] call CBA_fnc_filter;
_expected = [2, 3, 4];
ASSERT_OP(str _original,==,str _expected,_fn);
ASSERT_OP(str _result,==,str _expected,_fn);
TEST_OP(str _original,==,str _expected,_fn);
TEST_OP(str _result,==,str _expected,_fn);

_original = [1, 2, 3];
_result = [_original, { _x }, true] call CBA_fnc_filter;
_expected = [1, 2, 3];
ASSERT_OP(str _original,==,str _expected,_fn);
ASSERT_OP(str _result,==,str _expected,_fn);
TEST_OP(str _original,==,str _expected,_fn);
TEST_OP(str _result,==,str _expected,_fn);

nil;
12 changes: 6 additions & 6 deletions addons/arrays/test_inject.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ SCRIPT(test_inject);
private ["_expected", "_result", "_fn"];

_fn = "CBA_fnc_inject";
ASSERT_DEFINED("CBA_fnc_inject","");

LOG("Testing " + _fn);

TEST_DEFINED("CBA_fnc_inject","");

_result = [[], "", { _accumulator + (str _x) }] call CBA_fnc_inject;
_expected = "";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

_result = [[1, 2, 3], "", { _accumulator + (str _x) }] call CBA_fnc_inject;
_expected = "123";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

_result = [[1, 2, 3], " frogs", { (str _x) + _accumulator }] call CBA_fnc_inject;
_expected = "321 frogs";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

_result = [[1, 2, 3], 0, { _accumulator + _x }] call CBA_fnc_inject;
_expected = 6;
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

nil;
16 changes: 8 additions & 8 deletions addons/arrays/test_join.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@ SCRIPT(test_join);
private ["_expected", "_result", "_fn"];

_fn = "CBA_fnc_join";
ASSERT_DEFINED("CBA_fnc_join","");

LOG("Testing " + _fn);

TEST_DEFINED("CBA_fnc_join","");

_result = [[], "x"] call CBA_fnc_join;
_expected = "";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

_result = [[""], "x"] call CBA_fnc_join;
_expected = "";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

_result = [["frog"], "x"] call CBA_fnc_join;
_expected = "frog";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

_result = [["", ""], "x"] call CBA_fnc_join;
_expected = "x";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

_result = [["a","b","c"], "x"] call CBA_fnc_join;
_expected = "axbxc";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

_result = [["a",1,[objNull]], "x^x"] call CBA_fnc_join;
_expected = "ax^x1x^x[<Null-Object>]";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

nil;
14 changes: 7 additions & 7 deletions addons/arrays/test_shuffle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ SCRIPT(test_shuffle);
private ["_expected", "_result", "_fn"];

_fn = "CBA_fnc_shuffle";
ASSERT_DEFINED("CBA_fnc_shuffle","");

LOG("Testing " + _fn);

TEST_DEFINED("CBA_fnc_shuffle","");

_original = [1, 2, 3];
_result = [_original] call CBA_fnc_shuffle;
ASSERT_OP(count _result,==,count _original,_fn);
TEST_OP(count _result,==,count _original,_fn);

{
ASSERT_OP(_x,in,_original,_fn);
TEST_OP(_x,in,_original,_fn);
} forEach _result;

// Test depecated version.
_original = [1, 2, 3];
_result = _original call CBA_fnc_shuffle;
ASSERT_OP(count _result,==,count _original,_fn);
TEST_OP(count _result,==,count _original,_fn);

{
ASSERT_OP(_x,in,_original,_fn);
TEST_OP(_x,in,_original,_fn);
} forEach _result;

// Test depecated version.
_original = [];
_result = _original call CBA_fnc_shuffle;
ASSERT_OP(count _result,==,count _original,_fn);
TEST_OP(count _result,==,count _original,_fn);

nil;
2 changes: 1 addition & 1 deletion addons/common/test.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Automatically generated by 'functions_config.rb'
// DO NOT MANUALLY EDIT THIS FILE!
// -----------------------------------------------------------------------------

#define DEBUG_MODE_FULL
#include "script_component.hpp"

#define TESTS ["inheritsFrom", "parseYaml"]
Expand Down
14 changes: 7 additions & 7 deletions addons/common/test_inheritsFrom.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ SCRIPT(test_inheritsFrom);
private ["_class", "_base", "_expected", "_result", "_fn", "_game", "_clssname"];

_fn = "CBA_fnc_inheritsFrom";
ASSERT_DEFINED("CBA_fnc_inheritsFrom","");

LOG("Testing " + _fn);

TEST_DEFINED("CBA_fnc_inheritsFrom","");

/*
Game as integer from SLX_XEH_MACHINE
0 = Arma2
Expand All @@ -23,8 +23,8 @@ Game as integer from SLX_XEH_MACHINE
_game = SLX_XEH_MACHINE select 14;

if (_game > 3) then {
LOG ("FIXME! - Unknown game " + (SLX_XEH_MACHINE select 15) + ". All assert tests will fail! " + _fn); //Sanity check and reminder
Diag_log ("FIXME! - Unknown game " + (SLX_XEH_MACHINE select 15) + ". All assert tests will fail! " + _fn);
LOG ("FIXME! - Unknown game " + (SLX_XEH_MACHINE select 15) + ". All TEST tests will fail! " + _fn); //Sanity check and reminder
Diag_log ("FIXME! - Unknown game " + (SLX_XEH_MACHINE select 15) + ". All TEST tests will fail! " + _fn);
};

if (_game < 2) then {
Expand All @@ -40,16 +40,16 @@ if (_game < 2) then {
_class = configFile >> "CfgWeapons" >> _clssname;
_base = configFile >> "CfgWeapons" >> "RifleCore";
_result = [_class, _base] call CBA_fnc_inheritsFrom;
ASSERT_TRUE(_result,_fn);
TEST_TRUE(_result,_fn);

_class = configFile >> "CfgWeapons" >> "RifleCore";
_base = configFile >> "CfgWeapons" >> _clssname;
_result = [_class, _base] call CBA_fnc_inheritsFrom;
ASSERT_FALSE(_result,_fn);
TEST_FALSE(_result,_fn);

_class = configFile >> "CfgWeapons" >> _clssname;
_base = configFile >> "CfgWeapons" >> "PistolCore";
_result = [_class, _base] call CBA_fnc_inheritsFrom;
ASSERT_FALSE(_result,_fn);
TEST_FALSE(_result,_fn);

nil;
12 changes: 6 additions & 6 deletions addons/common/test_parseYaml.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ SCRIPT(test_parseYaml);
private ["_expected", "_result", "_fn", "_data"];

_fn = "CBA_fnc_parseYaml";
ASSERT_DEFINED("CBA_fnc_parseYaml",_fn);

LOG("Testing " + _fn);

TEST_DEFINED("CBA_fnc_parseYaml",_fn);

_data = ["\x\cba\addons\common\test_parseYaml_config.yml"] call CBA_fnc_parseYaml;

ASSERT_TRUE([_data] call CBA_fnc_isHash,_fn);
TEST_TRUE([_data] call CBA_fnc_isHash,_fn);

_result = [_data, "anotherNumber"] call CBA_fnc_hashGet;
_expected = "42";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

_result = ([_data, "nestedArray"] call CBA_fnc_hashGet) select 0;
_expected = "first";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

_result = (([_data, "nestedArray"] call CBA_fnc_hashGet) select 2) select 1;
_expected = "3.2";
ASSERT_OP(_result,==,_expected,_fn);
TEST_OP(_result,==,_expected,_fn);

nil;
2 changes: 1 addition & 1 deletion addons/diagnostic/test.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Automatically generated by 'functions_config.rb'
// DO NOT MANUALLY EDIT THIS FILE!
// -----------------------------------------------------------------------------

#define DEBUG_MODE_FULL
#include "script_component.hpp"

#define TESTS ["assertions", "parameters"]
Expand Down
10 changes: 5 additions & 5 deletions addons/diagnostic/test_parameters.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ SCRIPT(test_parameters);

LOG("Testing parameters");

private ["_expected"];
private ["_expected","_result","_this"];

// Test default params.
_this = [5];
DEFAULT_PARAM(0,_result,12);
_expected = 5;
ASSERT_OP(_result,==,_expected,"DEFAULT_PARAM");
TEST_OP(_result,==,_expected,"DEFAULT_PARAM");

_result = nil;

_this = [];
DEFAULT_PARAM(0,_result,12);
_expected = 12;
ASSERT_OP(_result,==,_expected,"DEFAULT_PARAM");
TEST_OP(_result,==,_expected,"DEFAULT_PARAM");

_result = nil;

_this = [nil];
DEFAULT_PARAM(0,_result,12);
_expected = 12;
ASSERT_OP(_result,==,_expected,"DEFAULT_PARAM");
TEST_OP(_result,==,_expected,"DEFAULT_PARAM");

_result = nil;

_this = nil;
DEFAULT_PARAM(0,_result,12);
_expected = 12;
ASSERT_OP(_result,==,_expected,"DEFAULT_PARAM");
TEST_OP(_result,==,_expected,"DEFAULT_PARAM");

nil;
10 changes: 4 additions & 6 deletions addons/hashes/test_hashEachPair.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ private ["_hash", "_expected", "_sumKeys", "_sumValues", "_totalIterations"];
_fn = "CBA_fnc_hashEachPair";
LOG("Testing " + _fn);

ASSERT_DEFINED("CBA_fnc_hashEachPair","");

Diag_log [diag_frameNo, diag_tickTime, time, ("Testing " + _fn)];
TEST_DEFINED("CBA_fnc_hashEachPair","");

_hash = [[[1, 12], [5, 25]], 88] call CBA_fnc_hashCreate;

Expand All @@ -29,10 +27,10 @@ _totalIterations = 0;
}] call CBA_fnc_hashEachPair;

_expected = 6;
ASSERT_OP(_sumKeys,==,_expected,"");
TEST_OP(_sumKeys,==,_expected,"");

_expected = 37;
ASSERT_OP(_sumValues,==,_expected,"");
TEST_OP(_sumValues,==,_expected,"");

_expected = 2;
ASSERT_OP(_totalIterations,==,_expected,"");
TEST_OP(_totalIterations,==,_expected,"");
Loading

0 comments on commit 8eff8ea

Please sign in to comment.