Normalize all the line endings

This commit is contained in:
Arkshine
2015-03-10 16:51:45 +01:00
parent afc3cac54d
commit 48d6a3354a
64 changed files with 16240 additions and 16240 deletions

View File

@ -7,126 +7,126 @@
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#include <amxmodx>
new __testnumber;
new errcount;
enum TestType
{
TT_Equal = 0,
TT_LessThan,
TT_GreaterThan,
TT_LessThanEqual,
TT_GreaterThanEqual,
TT_NotEqual
};
new TestWords[6][] = {
"==",
"<",
">",
"<=",
">=",
"!="
};
stock test(A,B=0,TestType:Type=TT_Equal)
{
++__testnumber;
new passed=0;
switch (Type)
{
case TT_Equal: if (A==B) passed=1;
case TT_LessThan: if (A<B) passed=1;
case TT_GreaterThan: if (A>B) passed=1;
case TT_LessThanEqual: if (A<=B) passed=1;
case TT_GreaterThanEqual: if (A>=B) passed=1;
case TT_NotEqual: if (A!=B) passed=1;
}
if (!passed)
{
log_amx("Failed test #%d (%d %s %d)",__testnumber,A,TestWords[_:Type],B);
errcount++;
}
}
public plugin_init()
{
register_srvcmd("testadmins","testadmins");
}
public testadmins()
{
new AuthData[44];
new Password[32];
new Access;
new Flags;
new id;
__testnumber=0;
errcount=0;
test(admins_num(),0);
admins_push("STEAM_0:1:23456","",read_flags("abcdefghijklmnopqrstu"),read_flags("ce"));
test(admins_num(),1);
admins_push("ABCDEFGHIJKLMNOP","abcdefghijklmnop",read_flags("z"),read_flags("a"));
test(admins_num(),2);
admins_push("ZYXWVUTSRQPONMLKJIHGFEDCBA","plop",read_flags("a"),read_flags("b"));
test(admins_num(),3);
id=0;
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
Access=admins_lookup(id,AdminProp_Access);
Flags=admins_lookup(id,AdminProp_Flags);
test(strcmp(AuthData,"STEAM_0:1:23456"),0);
test(strcmp(Password,""),0);
test(Access,read_flags("abcdefghijklmnopqrstu"));
test(Flags,read_flags("ce"));
id++;
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
Access=admins_lookup(id,AdminProp_Access);
Flags=admins_lookup(id,AdminProp_Flags);
test(strcmp(AuthData,"ABCDEFGHIJKLMNOP"),0);
test(strcmp(Password,"abcdefghijklmnop"),0);
test(Access,read_flags("z"));
test(Flags,read_flags("a"));
id++;
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
Access=admins_lookup(id,AdminProp_Access);
Flags=admins_lookup(id,AdminProp_Flags);
test(strcmp(AuthData,"ZYXWVUTSRQPONMLKJIHGFEDCBA"),0);
test(strcmp(Password,"plop"),0);
test(Access,read_flags("a"));
test(Flags,read_flags("b"));
admins_flush();
test(admins_num(),0);
server_print("test complete, %d errors",errcount);
#include <amxmodx>
new __testnumber;
new errcount;
enum TestType
{
TT_Equal = 0,
TT_LessThan,
TT_GreaterThan,
TT_LessThanEqual,
TT_GreaterThanEqual,
TT_NotEqual
};
new TestWords[6][] = {
"==",
"<",
">",
"<=",
">=",
"!="
};
stock test(A,B=0,TestType:Type=TT_Equal)
{
++__testnumber;
new passed=0;
switch (Type)
{
case TT_Equal: if (A==B) passed=1;
case TT_LessThan: if (A<B) passed=1;
case TT_GreaterThan: if (A>B) passed=1;
case TT_LessThanEqual: if (A<=B) passed=1;
case TT_GreaterThanEqual: if (A>=B) passed=1;
case TT_NotEqual: if (A!=B) passed=1;
}
if (!passed)
{
log_amx("Failed test #%d (%d %s %d)",__testnumber,A,TestWords[_:Type],B);
errcount++;
}
}
public plugin_init()
{
register_srvcmd("testadmins","testadmins");
}
public testadmins()
{
new AuthData[44];
new Password[32];
new Access;
new Flags;
new id;
__testnumber=0;
errcount=0;
test(admins_num(),0);
admins_push("STEAM_0:1:23456","",read_flags("abcdefghijklmnopqrstu"),read_flags("ce"));
test(admins_num(),1);
admins_push("ABCDEFGHIJKLMNOP","abcdefghijklmnop",read_flags("z"),read_flags("a"));
test(admins_num(),2);
admins_push("ZYXWVUTSRQPONMLKJIHGFEDCBA","plop",read_flags("a"),read_flags("b"));
test(admins_num(),3);
id=0;
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
Access=admins_lookup(id,AdminProp_Access);
Flags=admins_lookup(id,AdminProp_Flags);
test(strcmp(AuthData,"STEAM_0:1:23456"),0);
test(strcmp(Password,""),0);
test(Access,read_flags("abcdefghijklmnopqrstu"));
test(Flags,read_flags("ce"));
id++;
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
Access=admins_lookup(id,AdminProp_Access);
Flags=admins_lookup(id,AdminProp_Flags);
test(strcmp(AuthData,"ABCDEFGHIJKLMNOP"),0);
test(strcmp(Password,"abcdefghijklmnop"),0);
test(Access,read_flags("z"));
test(Flags,read_flags("a"));
id++;
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
Access=admins_lookup(id,AdminProp_Access);
Flags=admins_lookup(id,AdminProp_Flags);
test(strcmp(AuthData,"ZYXWVUTSRQPONMLKJIHGFEDCBA"),0);
test(strcmp(Password,"plop"),0);
test(Access,read_flags("a"));
test(Flags,read_flags("b"));
admins_flush();
test(admins_num(),0);
server_print("test complete, %d errors",errcount);
}

File diff suppressed because it is too large Load Diff

View File

@ -7,63 +7,63 @@
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#include <amxmodx>
public plugin_init()
{
register_plugin("callfunc test", "1.0", "BAILOPAN")
register_srvcmd("test_callfunc", "Command_Callfunc")
}
public OnCallfuncReceived(num, str[], &val, array[], array2[], size, hello2[1])
{
server_print("num = %d (expected: %d)", num, 5)
server_print("str[] = ^"%s^" (expected: %s)", str, "Gaben")
server_print("val = %d (expected %d, setting to %d)", val, 62, 15)
val = 15
server_print("printing %d elements of array[] (expected: %d)", size, 6)
for (new i=0; i<size; i++)
{
server_print("array[%d] = %d (expected: %d)", i, array[i], i)
}
for (new i=0; i<size; i++)
{
server_print("array2[%d] = %d (expected: %d)", i, array[i], i)
}
array[0] = 5
array2[1] = 6
hello2[0] = 25
}
public Command_Callfunc()
{
new a = 62
new hello[] = {0,1,2,3,4,5}
new hello2[] = {9}
new pm = 6
new err
if ((err=callfunc_begin("OnCallfuncReceived")) < 1)
{
server_print("Failed to call callfunc_begin()! Error: %d", err)
return PLUGIN_HANDLED
}
callfunc_push_int(5)
callfunc_push_str("Gaben")
callfunc_push_intrf(a)
callfunc_push_array(hello, pm)
callfunc_push_array(hello, pm)
callfunc_push_int(pm)
callfunc_push_array(hello2, 1, false)
callfunc_end()
server_print("a = %d (expected: %d)", a, 15)
server_print("hello[0] = %d (expected: %d)", hello[0], 5)
server_print("hello[1] = %d (expected: %d)", hello[1], 6)
server_print("hello2[0] = %d (expected: %d)", hello2[0], 9)
return PLUGIN_HANDLED
}
#include <amxmodx>
public plugin_init()
{
register_plugin("callfunc test", "1.0", "BAILOPAN")
register_srvcmd("test_callfunc", "Command_Callfunc")
}
public OnCallfuncReceived(num, str[], &val, array[], array2[], size, hello2[1])
{
server_print("num = %d (expected: %d)", num, 5)
server_print("str[] = ^"%s^" (expected: %s)", str, "Gaben")
server_print("val = %d (expected %d, setting to %d)", val, 62, 15)
val = 15
server_print("printing %d elements of array[] (expected: %d)", size, 6)
for (new i=0; i<size; i++)
{
server_print("array[%d] = %d (expected: %d)", i, array[i], i)
}
for (new i=0; i<size; i++)
{
server_print("array2[%d] = %d (expected: %d)", i, array[i], i)
}
array[0] = 5
array2[1] = 6
hello2[0] = 25
}
public Command_Callfunc()
{
new a = 62
new hello[] = {0,1,2,3,4,5}
new hello2[] = {9}
new pm = 6
new err
if ((err=callfunc_begin("OnCallfuncReceived")) < 1)
{
server_print("Failed to call callfunc_begin()! Error: %d", err)
return PLUGIN_HANDLED
}
callfunc_push_int(5)
callfunc_push_str("Gaben")
callfunc_push_intrf(a)
callfunc_push_array(hello, pm)
callfunc_push_array(hello, pm)
callfunc_push_int(pm)
callfunc_push_array(hello2, 1, false)
callfunc_end()
server_print("a = %d (expected: %d)", a, 15)
server_print("hello[0] = %d (expected: %d)", hello[0], 5)
server_print("hello[1] = %d (expected: %d)", hello[1], 6)
server_print("hello2[0] = %d (expected: %d)", hello2[0], 9)
return PLUGIN_HANDLED
}

View File

@ -7,21 +7,21 @@
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#include <amxmodx>
#include <fakemeta>
public plugin_init()
{
register_plugin("Fakemeta Tests", "1.0", "BAILOPAN")
register_forward(FM_ServerDeactivate, "Hook_ServerDeactivate")
}
public Hook_ServerDeactivate()
{
server_print("[FAKEMETA TEST] ServerDeactivate() at %f", get_gametime())
}
public plugin_end()
{
server_print("[FAKEMETA TEST] plugin_end() at %f", get_gametime())
}
#include <amxmodx>
#include <fakemeta>
public plugin_init()
{
register_plugin("Fakemeta Tests", "1.0", "BAILOPAN")
register_forward(FM_ServerDeactivate, "Hook_ServerDeactivate")
}
public Hook_ServerDeactivate()
{
server_print("[FAKEMETA TEST] ServerDeactivate() at %f", get_gametime())
}
public plugin_end()
{
server_print("[FAKEMETA TEST] plugin_end() at %f", get_gametime())
}

View File

@ -7,61 +7,61 @@
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#include <amxmodx>
public plugin_init()
{
register_plugin("Format Test", "1.0", "BAILOPAN")
register_srvcmd("test_format", "Command_TestFormat")
register_srvcmd("test_replace", "Command_TestReplace")
}
public gabprint(const fmt[], ...)
{
static buffer[2048]
vformat(buffer, 2047, fmt, 2)
server_print("%s", buffer)
}
public Command_TestFormat()
{
server_print("Printing -1 with d: %d", -1)
server_print("Printing -1 with u: %u", -1)
server_print("Printing (1<<31) with d: %d", (1<<31))
server_print("Printing (1<<31) with u: %u", (1<<31))
server_print("Printing 1 with d: %d", 1)
server_print("Printing 1 with u: %u", 1)
}
public Command_TestReplace()
{
new message[192] = "^"@test^""
replace_all(message, 191, "^"", "")
server_print("Got: %s (expected: %s)", message, "@test")
copy(message, 191, "test")
replace_all(message, 191, "t", "tt")
server_print("Got: %s (expected: %s)", message, "ttestt")
replace_all(message, 191, "tt", "")
server_print("Got: %s (expected: %s)", message, "es")
copy(message, 191, "good boys do fine always")
replace_all(message, 191, " ", "-----")
server_print("Got %s (expected: %s)", message, "good-----boys-----do-----fine-----always")
copy(message, 191, "-----")
replace_all(message, 191, "-", "")
server_print("Got ^"%s%^" (expected: ^"%s%^")", message, "")
copy(message, 191, "-----")
replace_all(message, 191, "--", "")
server_print("Got ^"%s%^" (expected: ^"%s%^")", message, "-")
copy(message, 191, "aaaa")
replace_all(message, 191, "a", "Aaa")
server_print("Got %s (expected: %s)", message, "AaaAaaAaaAaa")
}
#include <amxmodx>
public plugin_init()
{
register_plugin("Format Test", "1.0", "BAILOPAN")
register_srvcmd("test_format", "Command_TestFormat")
register_srvcmd("test_replace", "Command_TestReplace")
}
public gabprint(const fmt[], ...)
{
static buffer[2048]
vformat(buffer, 2047, fmt, 2)
server_print("%s", buffer)
}
public Command_TestFormat()
{
server_print("Printing -1 with d: %d", -1)
server_print("Printing -1 with u: %u", -1)
server_print("Printing (1<<31) with d: %d", (1<<31))
server_print("Printing (1<<31) with u: %u", (1<<31))
server_print("Printing 1 with d: %d", 1)
server_print("Printing 1 with u: %u", 1)
}
public Command_TestReplace()
{
new message[192] = "^"@test^""
replace_all(message, 191, "^"", "")
server_print("Got: %s (expected: %s)", message, "@test")
copy(message, 191, "test")
replace_all(message, 191, "t", "tt")
server_print("Got: %s (expected: %s)", message, "ttestt")
replace_all(message, 191, "tt", "")
server_print("Got: %s (expected: %s)", message, "es")
copy(message, 191, "good boys do fine always")
replace_all(message, 191, " ", "-----")
server_print("Got %s (expected: %s)", message, "good-----boys-----do-----fine-----always")
copy(message, 191, "-----")
replace_all(message, 191, "-", "")
server_print("Got ^"%s%^" (expected: ^"%s%^")", message, "")
copy(message, 191, "-----")
replace_all(message, 191, "--", "")
server_print("Got ^"%s%^" (expected: ^"%s%^")", message, "-")
copy(message, 191, "aaaa")
replace_all(message, 191, "a", "Aaa")
server_print("Got %s (expected: %s)", message, "AaaAaaAaaAaa")
}

View File

@ -7,48 +7,48 @@
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#include <amxmodx>
new g_BlockLog
public plugin_init()
{
register_plugin("Log Tester", "1.0", "BAILOPAN")
register_srvcmd("log_addlogevent", "Command_AddLogEvent")
register_srvcmd("log_setblock", "Command_LogSetBlock")
}
public event_round_start()
{
}
public Command_LogSetBlock()
{
if (read_argc() < 2)
{
server_print("Specify 1 or 0.")
return PLUGIN_HANDLED
}
new temp[12]
read_argv(1, temp, 11)
g_BlockLog = str_to_num(temp) ? true : false
return PLUGIN_HANDLED
}
public plugin_log()
{
server_print("Got log event! Blocking: %d", g_BlockLog)
return g_BlockLog ? PLUGIN_HANDLED : PLUGIN_CONTINUE
}
public Command_AddLogEvent(id)
{
register_logevent("event_round_start", 2, "0=World triggered", "1=Round_Start")
return PLUGIN_HANDLED
}
#include <amxmodx>
new g_BlockLog
public plugin_init()
{
register_plugin("Log Tester", "1.0", "BAILOPAN")
register_srvcmd("log_addlogevent", "Command_AddLogEvent")
register_srvcmd("log_setblock", "Command_LogSetBlock")
}
public event_round_start()
{
}
public Command_LogSetBlock()
{
if (read_argc() < 2)
{
server_print("Specify 1 or 0.")
return PLUGIN_HANDLED
}
new temp[12]
read_argv(1, temp, 11)
g_BlockLog = str_to_num(temp) ? true : false
return PLUGIN_HANDLED
}
public plugin_log()
{
server_print("Got log event! Blocking: %d", g_BlockLog)
return g_BlockLog ? PLUGIN_HANDLED : PLUGIN_CONTINUE
}
public Command_AddLogEvent(id)
{
register_logevent("event_round_start", 2, "0=World triggered", "1=Round_Start")
return PLUGIN_HANDLED
}

View File

@ -7,34 +7,34 @@
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#include <amxmodx>
native Factorial(num)
public __Factorial(id, num)
{
new num = get_param(1)
if (num == 0)
{
return 1
}
return num * Factorial(num - 1)
}
public plugin_natives()
{
register_native("Factorial", "__Factorial")
}
public plugin_init()
{
register_plugin("Native Test", "1.0", "BAILOPAN")
register_srvcmd("test_native1", "Command_TestNative1")
}
public Command_TestNative1()
{
new num = Factorial(6)
server_print("Factorial of 6 is: %d", num)
}
#include <amxmodx>
native Factorial(num)
public __Factorial(id, num)
{
new num = get_param(1)
if (num == 0)
{
return 1
}
return num * Factorial(num - 1)
}
public plugin_natives()
{
register_native("Factorial", "__Factorial")
}
public plugin_init()
{
register_plugin("Native Test", "1.0", "BAILOPAN")
register_srvcmd("test_native1", "Command_TestNative1")
}
public Command_TestNative1()
{
new num = Factorial(6)
server_print("Factorial of 6 is: %d", num)
}

View File

@ -7,23 +7,23 @@
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#include <amxmodx>
#include <nvault>
public plugin_init()
{
register_plugin("nVault Test", "1.0", "BAILOPAN")
register_srvcmd("test_nvault", "Command_TestNvault")
}
public Command_TestNvault()
{
new v = nvault_open("://:/1/R!?#@41345$%:$")
server_print("Vault value: %d (expected: %d)", v, -1)
if (v != -1)
{
nvault_close(v)
}
}
#include <amxmodx>
#include <nvault>
public plugin_init()
{
register_plugin("nVault Test", "1.0", "BAILOPAN")
register_srvcmd("test_nvault", "Command_TestNvault")
}
public Command_TestNvault()
{
new v = nvault_open("://:/1/R!?#@41345$%:$")
server_print("Vault value: %d (expected: %d)", v, -1)
if (v != -1)
{
nvault_close(v)
}
}

View File

@ -7,294 +7,294 @@
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#include <amxmodx>
public plugin_init()
{
register_plugin("Sort Test", "1.0", "BAILOPAN")
register_srvcmd("test_sort_ints", "Command_TestSortInts")
register_srvcmd("test_sort_floats", "Command_TestSortFloats")
register_srvcmd("test_sort_strings", "Command_TestSortStrings")
register_srvcmd("test_sort_1d", "Command_TestSort1D")
register_srvcmd("test_sort_2d", "Command_TestSort2D")
register_srvcmd("test_adtsort_ints", "Command_TestSortADTInts")
register_srvcmd("test_adtsort_floats", "Command_TestSortADTFloats")
register_srvcmd("test_adtsort_strings", "Command_TestSortADTStrings")
}
/*****************
* INTEGER TESTS *
*****************/
// Note that integer comparison is just int1-int2 (or a variation therein)
PrintIntegers(const array[], size)
{
for (new i=0; i<size; i++)
{
server_print("array[%d] = %d", i, array[i])
}
}
public Command_TestSortInts()
{
new array[10] = {6, 7, 3, 2, 8, 5, 0, 1, 4, 9}
server_print("Testing ascending sort:")
SortIntegers(array, 10, Sort_Ascending)
PrintIntegers(array, 10)
server_print("Testing descending sort:")
SortIntegers(array, 10, Sort_Descending)
PrintIntegers(array, 10)
server_print("Testing random sort:")
SortIntegers(array, 10, Sort_Random)
PrintIntegers(array, 10)
}
/**************************
* Float comparison tests *
**************************/
PrintFloats(const Float:array[], size)
{
for (new i=0; i<size; i++)
{
server_print("array[%d] = %f", i, array[i])
}
}
public Command_TestSortFloats()
{
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
server_print("Testing ascending sort:")
SortFloats(array, 10, Sort_Ascending)
PrintFloats(array, 10)
server_print("Testing descending sort:")
SortFloats(array, 10, Sort_Descending)
PrintFloats(array, 10)
server_print("Testing random sort:")
SortFloats(array, 10, Sort_Random)
PrintFloats(array, 10)
return PLUGIN_HANDLED
}
public Custom1DSort(Float:elem1, Float:elem2)
{
if (elem1 > elem2)
{
return -1;
} else if (elem1 < elem2) {
return 1;
}
return 0;
}
public Command_TestSort1D()
{
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
SortCustom1D(_:array, 10, "Custom1DSort")
PrintFloats(array, 10)
return PLUGIN_HANDLED
}
/***************************
* String comparison tests *
***************************/
PrintStrings(const array[][], size)
{
for (new i=0; i<size; i++)
{
server_print("array[%d] = %s", i, array[i])
}
}
public Command_TestSortStrings()
{
new array[][] =
{
"faluco",
"bailopan",
"pm onoto",
"damaged soul",
"sniperbeamer",
"sidluke",
"johnny got his gun",
"gabe newell",
"hello",
"WHAT?!"
}
server_print("Testing ascending sort:")
SortStrings(array, 10, Sort_Ascending)
PrintStrings(array, 10)
server_print("Testing descending sort:")
SortStrings(array, 10, Sort_Descending)
PrintStrings(array, 10)
server_print("Testing random sort:")
SortStrings(array, 10, Sort_Random)
PrintStrings(array, 10)
return PLUGIN_HANDLED
}
public Custom2DSort(const elem1[], const elem2[])
{
return strcmp(elem1, elem2)
}
public Command_TestSort2D()
{
new array[][] =
{
"faluco",
"bailopan",
"pm onoto",
"damaged soul",
"sniperbeamer",
"sidluke",
"johnny got his gun",
"gabe newell",
"hello",
"WHAT?!"
}
SortCustom2D(array, 10, "Custom2DSort")
PrintStrings(array, 10)
return PLUGIN_HANDLED
}
/*******************
* ADT ARRAY TESTS *
*******************/
// Int and floats work the same as normal comparisions. Strings are direct
// comparisions with no hacky memory stuff like Pawn arrays.
PrintADTArrayIntegers(Array:array)
{
new size = ArraySize(array);
for (new i=0; i<size;i++)
{
server_print("array[%d] = %d", i, ArrayGetCell(array, i));
}
}
public Command_TestSortADTInts()
{
new Array:array = ArrayCreate();
ArrayPushCell(array, 6);
ArrayPushCell(array, 7);
ArrayPushCell(array, 3);
ArrayPushCell(array, 2);
ArrayPushCell(array, 8);
ArrayPushCell(array, 5);
ArrayPushCell(array, 0);
ArrayPushCell(array, 1);
ArrayPushCell(array, 4);
ArrayPushCell(array, 9);
server_print("Testing ascending sort:")
SortADTArray(array, Sort_Ascending, Sort_Integer)
PrintADTArrayIntegers(array)
server_print("Testing descending sort:")
SortADTArray(array, Sort_Descending, Sort_Integer)
PrintADTArrayIntegers(array)
server_print("Testing random sort:")
SortADTArray(array, Sort_Random, Sort_Integer)
PrintADTArrayIntegers(array)
return PLUGIN_HANDLED
}
PrintADTArrayFloats(Array:array)
{
new size = ArraySize(array);
for (new i=0; i<size;i++)
{
server_print("array[%d] = %f", i, Float:ArrayGetCell(array, i));
}
}
public Command_TestSortADTFloats()
{
new Array:array = ArrayCreate();
ArrayPushCell(array, 6.0);
ArrayPushCell(array, 7.0);
ArrayPushCell(array, 3.0);
ArrayPushCell(array, 2.0);
ArrayPushCell(array, 8.0);
ArrayPushCell(array, 5.0);
ArrayPushCell(array, 0.0);
ArrayPushCell(array, 1.0);
ArrayPushCell(array, 4.0);
ArrayPushCell(array, 9.0);
server_print("Testing ascending sort:")
SortADTArray(array, Sort_Ascending, Sort_Float)
PrintADTArrayFloats(array)
server_print("Testing descending sort:")
SortADTArray(array, Sort_Descending, Sort_Float)
PrintADTArrayFloats(array)
server_print("Testing random sort:")
SortADTArray(array, Sort_Random, Sort_Float)
PrintADTArrayFloats(array)
return PLUGIN_HANDLED
}
PrintADTArrayStrings(Array:array)
{
new size = ArraySize(array);
new buffer[64];
for (new i=0; i<size;i++)
{
ArrayGetString(array, i, buffer, sizeof(buffer));
server_print("array[%d] = %s", i, buffer);
}
}
public Command_TestSortADTStrings()
{
new Array:array = ArrayCreate(64);
ArrayPushString(array, "faluco");
ArrayPushString(array, "bailopan");
ArrayPushString(array, "pm onoto");
ArrayPushString(array, "damaged soul");
ArrayPushString(array, "sniperbeamer");
ArrayPushString(array, "sidluke");
ArrayPushString(array, "johnny got his gun");
ArrayPushString(array, "gabe newell");
ArrayPushString(array, "Hello pRED*");
ArrayPushString(array, "WHAT?!");
server_print("Testing ascending sort:")
SortADTArray(array, Sort_Ascending, Sort_String)
PrintADTArrayStrings(array)
server_print("Testing descending sort:")
SortADTArray(array, Sort_Descending, Sort_String)
PrintADTArrayStrings(array)
server_print("Testing random sort:")
SortADTArray(array, Sort_Random, Sort_String)
PrintADTArrayStrings(array)
return PLUGIN_HANDLED
}
#include <amxmodx>
public plugin_init()
{
register_plugin("Sort Test", "1.0", "BAILOPAN")
register_srvcmd("test_sort_ints", "Command_TestSortInts")
register_srvcmd("test_sort_floats", "Command_TestSortFloats")
register_srvcmd("test_sort_strings", "Command_TestSortStrings")
register_srvcmd("test_sort_1d", "Command_TestSort1D")
register_srvcmd("test_sort_2d", "Command_TestSort2D")
register_srvcmd("test_adtsort_ints", "Command_TestSortADTInts")
register_srvcmd("test_adtsort_floats", "Command_TestSortADTFloats")
register_srvcmd("test_adtsort_strings", "Command_TestSortADTStrings")
}
/*****************
* INTEGER TESTS *
*****************/
// Note that integer comparison is just int1-int2 (or a variation therein)
PrintIntegers(const array[], size)
{
for (new i=0; i<size; i++)
{
server_print("array[%d] = %d", i, array[i])
}
}
public Command_TestSortInts()
{
new array[10] = {6, 7, 3, 2, 8, 5, 0, 1, 4, 9}
server_print("Testing ascending sort:")
SortIntegers(array, 10, Sort_Ascending)
PrintIntegers(array, 10)
server_print("Testing descending sort:")
SortIntegers(array, 10, Sort_Descending)
PrintIntegers(array, 10)
server_print("Testing random sort:")
SortIntegers(array, 10, Sort_Random)
PrintIntegers(array, 10)
}
/**************************
* Float comparison tests *
**************************/
PrintFloats(const Float:array[], size)
{
for (new i=0; i<size; i++)
{
server_print("array[%d] = %f", i, array[i])
}
}
public Command_TestSortFloats()
{
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
server_print("Testing ascending sort:")
SortFloats(array, 10, Sort_Ascending)
PrintFloats(array, 10)
server_print("Testing descending sort:")
SortFloats(array, 10, Sort_Descending)
PrintFloats(array, 10)
server_print("Testing random sort:")
SortFloats(array, 10, Sort_Random)
PrintFloats(array, 10)
return PLUGIN_HANDLED
}
public Custom1DSort(Float:elem1, Float:elem2)
{
if (elem1 > elem2)
{
return -1;
} else if (elem1 < elem2) {
return 1;
}
return 0;
}
public Command_TestSort1D()
{
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
SortCustom1D(_:array, 10, "Custom1DSort")
PrintFloats(array, 10)
return PLUGIN_HANDLED
}
/***************************
* String comparison tests *
***************************/
PrintStrings(const array[][], size)
{
for (new i=0; i<size; i++)
{
server_print("array[%d] = %s", i, array[i])
}
}
public Command_TestSortStrings()
{
new array[][] =
{
"faluco",
"bailopan",
"pm onoto",
"damaged soul",
"sniperbeamer",
"sidluke",
"johnny got his gun",
"gabe newell",
"hello",
"WHAT?!"
}
server_print("Testing ascending sort:")
SortStrings(array, 10, Sort_Ascending)
PrintStrings(array, 10)
server_print("Testing descending sort:")
SortStrings(array, 10, Sort_Descending)
PrintStrings(array, 10)
server_print("Testing random sort:")
SortStrings(array, 10, Sort_Random)
PrintStrings(array, 10)
return PLUGIN_HANDLED
}
public Custom2DSort(const elem1[], const elem2[])
{
return strcmp(elem1, elem2)
}
public Command_TestSort2D()
{
new array[][] =
{
"faluco",
"bailopan",
"pm onoto",
"damaged soul",
"sniperbeamer",
"sidluke",
"johnny got his gun",
"gabe newell",
"hello",
"WHAT?!"
}
SortCustom2D(array, 10, "Custom2DSort")
PrintStrings(array, 10)
return PLUGIN_HANDLED
}
/*******************
* ADT ARRAY TESTS *
*******************/
// Int and floats work the same as normal comparisions. Strings are direct
// comparisions with no hacky memory stuff like Pawn arrays.
PrintADTArrayIntegers(Array:array)
{
new size = ArraySize(array);
for (new i=0; i<size;i++)
{
server_print("array[%d] = %d", i, ArrayGetCell(array, i));
}
}
public Command_TestSortADTInts()
{
new Array:array = ArrayCreate();
ArrayPushCell(array, 6);
ArrayPushCell(array, 7);
ArrayPushCell(array, 3);
ArrayPushCell(array, 2);
ArrayPushCell(array, 8);
ArrayPushCell(array, 5);
ArrayPushCell(array, 0);
ArrayPushCell(array, 1);
ArrayPushCell(array, 4);
ArrayPushCell(array, 9);
server_print("Testing ascending sort:")
SortADTArray(array, Sort_Ascending, Sort_Integer)
PrintADTArrayIntegers(array)
server_print("Testing descending sort:")
SortADTArray(array, Sort_Descending, Sort_Integer)
PrintADTArrayIntegers(array)
server_print("Testing random sort:")
SortADTArray(array, Sort_Random, Sort_Integer)
PrintADTArrayIntegers(array)
return PLUGIN_HANDLED
}
PrintADTArrayFloats(Array:array)
{
new size = ArraySize(array);
for (new i=0; i<size;i++)
{
server_print("array[%d] = %f", i, Float:ArrayGetCell(array, i));
}
}
public Command_TestSortADTFloats()
{
new Array:array = ArrayCreate();
ArrayPushCell(array, 6.0);
ArrayPushCell(array, 7.0);
ArrayPushCell(array, 3.0);
ArrayPushCell(array, 2.0);
ArrayPushCell(array, 8.0);
ArrayPushCell(array, 5.0);
ArrayPushCell(array, 0.0);
ArrayPushCell(array, 1.0);
ArrayPushCell(array, 4.0);
ArrayPushCell(array, 9.0);
server_print("Testing ascending sort:")
SortADTArray(array, Sort_Ascending, Sort_Float)
PrintADTArrayFloats(array)
server_print("Testing descending sort:")
SortADTArray(array, Sort_Descending, Sort_Float)
PrintADTArrayFloats(array)
server_print("Testing random sort:")
SortADTArray(array, Sort_Random, Sort_Float)
PrintADTArrayFloats(array)
return PLUGIN_HANDLED
}
PrintADTArrayStrings(Array:array)
{
new size = ArraySize(array);
new buffer[64];
for (new i=0; i<size;i++)
{
ArrayGetString(array, i, buffer, sizeof(buffer));
server_print("array[%d] = %s", i, buffer);
}
}
public Command_TestSortADTStrings()
{
new Array:array = ArrayCreate(64);
ArrayPushString(array, "faluco");
ArrayPushString(array, "bailopan");
ArrayPushString(array, "pm onoto");
ArrayPushString(array, "damaged soul");
ArrayPushString(array, "sniperbeamer");
ArrayPushString(array, "sidluke");
ArrayPushString(array, "johnny got his gun");
ArrayPushString(array, "gabe newell");
ArrayPushString(array, "Hello pRED*");
ArrayPushString(array, "WHAT?!");
server_print("Testing ascending sort:")
SortADTArray(array, Sort_Ascending, Sort_String)
PrintADTArrayStrings(array)
server_print("Testing descending sort:")
SortADTArray(array, Sort_Descending, Sort_String)
PrintADTArrayStrings(array)
server_print("Testing random sort:")
SortADTArray(array, Sort_Random, Sort_String)
PrintADTArrayStrings(array)
return PLUGIN_HANDLED
}