-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
Community Toolbox/scripts/suite_CommunityToolboxSuite/suite_CommunityToolboxSuite.gml
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,4 @@ | ||
function CommunityToolboxSuite() : VerrificSuiteGroup("Community toolbox tests") constructor { | ||
add_suite(new MiscUtilsSuite()); | ||
add_suite(new MathUtilsSuite()); | ||
} |
3 changes: 3 additions & 0 deletions
3
Community Toolbox/scripts/suite_MathUtilsSuite/suite_MathUtilsSuite.gml
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,3 @@ | ||
function MathUtilsSuite() : VerrificSuiteGroup("Math utilities tests") constructor { | ||
add_methods_from(EucmoddivTests); | ||
} |
11 changes: 11 additions & 0 deletions
11
Community Toolbox/scripts/suite_MathUtilsSuite/suite_MathUtilsSuite.yy
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
Community Toolbox/scripts/tests_EucmoddivTests/tests_EucmoddivTests.gml
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 EucmoddivTests(_run, _method) : VerrificMethodTest(_run, _method) constructor { | ||
static test_subject = "eucmod/eucdiv"; | ||
static should_be_positive_eucmod_pos_pos = function() { | ||
_a = 7; | ||
_b = 3; | ||
_r = eucmod(_a,_b); | ||
assert_is_true( _r >= 0 && _r < abs(_b)); | ||
} | ||
|
||
static should_be_positive_eucmod_pos_neg = function() { | ||
_a = 7; | ||
_b = -3; | ||
_r = eucmod(_a,_b); | ||
assert_is_true( _r >= 0 && _r < abs(_b)); | ||
} | ||
|
||
static should_be_positive_eucmod_neg_pos = function() { | ||
_a = -7; | ||
_b = 3; | ||
_r = eucmod(_a,_b); | ||
assert_is_true( _r >= 0 && _r < abs(_b)); | ||
} | ||
|
||
static should_be_positive_eucmod_neg_neg = function() { | ||
_a = -7; | ||
_b = -3; | ||
_r = eucmod(_a,_b); | ||
assert_is_true( _r >= 0 && _r < abs(_b)); | ||
} | ||
|
||
static should_equal_dividend_pos_pos = function() { | ||
_a = 7; | ||
_b = 3; | ||
_result = eucdiv(_a, _b) * _b + eucmod(_a, _b); | ||
assert_is_true(_a == _result); | ||
} | ||
|
||
static should_equal_dividend_pos_neg = function() { | ||
_a = 7; | ||
_b = -3; | ||
_result = eucdiv(_a, _b) * _b + eucmod(_a, _b); | ||
assert_is_true(_a == _result); | ||
} | ||
|
||
static should_equal_dividend_neg_pos = function() { | ||
_a = -7; | ||
_b = 3; | ||
_result = eucdiv(_a, _b) * _b + eucmod(_a, _b); | ||
assert_is_true(_a == _result); | ||
} | ||
|
||
static should_equal_dividend_neg_neg = function() { | ||
_a = -7; | ||
_b = -3; | ||
_result = eucdiv(_a, _b) * _b + eucmod(_a, _b); | ||
assert_is_true(_a == _result); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
Community Toolbox/scripts/tests_EucmoddivTests/tests_EucmoddivTests.yy
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,30 @@ | ||
/// @func eucmod(dvnd,dvsr) | ||
/// @desc Calculates a remainder from the Euclidian division (the remainder will always be non-negative). | ||
/// @arg {Real} dvnd The value to divide, or dividend. | ||
/// @arg {Real} dvsr The value to divide by, or divisor. | ||
/// @returns {Real} | ||
function eucmod(_dvnd,_dvsr){ | ||
_r = _dvnd%_dvsr; | ||
if (_r > 0) | ||
return _r; | ||
else if (_dvsr > 0) | ||
return _r + _dvsr; | ||
else | ||
return _r - _dvsr; | ||
} | ||
|
||
/// @func eucdiv(dvnd,dvsr) | ||
/// @desc Calculates an integer quotient of the Euclidian division (i.e. with non-negative remainder). | ||
/// @arg {Real} dvnd The value to divide, or dividend. | ||
/// @arg {Real} dvsr The value to divide by, or divisor. | ||
/// @returns {Real} | ||
function eucdiv(_dvnd,_dvsr){ | ||
_q = _dvnd div _dvsr; | ||
|
||
if (_dvnd > 0) | ||
return _q; | ||
else if (_dvsr > 0) | ||
return _q - 1; | ||
else | ||
return _q + 1; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.