Improve CellArray.
This commit is contained in:
@ -4,10 +4,6 @@
|
||||
|
||||
#define _cellarray_included
|
||||
|
||||
enum Array
|
||||
{
|
||||
Invalid_Array = 0
|
||||
};
|
||||
/**
|
||||
* These arrays are intended to be used for a form of global storage without
|
||||
* requiring a #define that needs to be increased each time a person needs more
|
||||
@ -15,40 +11,72 @@ enum Array
|
||||
* These are not designed to be used as a replacement for normal arrays, as
|
||||
* normal arrays are faster and should be used whenever possible.
|
||||
*/
|
||||
|
||||
enum Array
|
||||
{
|
||||
Invalid_Array = 0
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a maximum string size (including the null terminator),
|
||||
* returns the number of cells required to fit that string.
|
||||
*
|
||||
* @param size Number of bytes.
|
||||
* @return Minimum number of cells required to fit the byte count.
|
||||
*/
|
||||
stock ByteCountToCells(size)
|
||||
{
|
||||
if (!size)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return (size + 3) / 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a handle to a dynamically sized array.
|
||||
* It is very important that the cellsize you provide matches up with the buffer sizes
|
||||
* that you pass with subsequent Array{Get,Set,Push} calls.
|
||||
*
|
||||
* @param cellsize How many cells each entry in the array is.
|
||||
* @param reserved How many blank entries are created immediately when the array is created. These entries are not valid to read from until called with ArraySet.
|
||||
* @return Handle to the array.
|
||||
* @note As per AMX Mod X 1.8.3, reserved parameter has no effect.
|
||||
*
|
||||
* @param cellsize How many cells each entry in the array is.
|
||||
* @param reserved How many blank entries are created immediately when the array is created.
|
||||
* These entries are not valid to read from until called with ArraySet.
|
||||
*
|
||||
* @return Handle to the array.
|
||||
*/
|
||||
native Array:ArrayCreate(cellsize=1, reserved=32);
|
||||
native Array:ArrayCreate(cellsize = 1, reserved = 32);
|
||||
|
||||
/**
|
||||
* Clones an array, returning a new handle with the same size and data.
|
||||
* You must close it.
|
||||
*
|
||||
* @param which Array handle to be cloned.
|
||||
* @return New handle to the cloned array object on success, 0 on failure.
|
||||
* @param which Array handle to be cloned.
|
||||
*
|
||||
* @return New handle to the cloned array object on success, 0 on failure.
|
||||
* @error Invalid handle.
|
||||
*/
|
||||
native Array:ArrayClone(Array:which);
|
||||
|
||||
/**
|
||||
* Clears all entries from the array.
|
||||
*
|
||||
* @param which The array to clear.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @param which The array to clear.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle.
|
||||
*/
|
||||
native ArrayClear(Array:which);
|
||||
|
||||
/**
|
||||
* Returns the number of elements in the array.
|
||||
*
|
||||
* @param which The array to check.
|
||||
* @return How many elements are in the array.
|
||||
* @param which The array to check.
|
||||
*
|
||||
* @return How many elements are in the array.
|
||||
* @error Invalid handle.
|
||||
*/
|
||||
native ArraySize(Array:which);
|
||||
|
||||
@ -56,9 +84,11 @@ native ArraySize(Array:which);
|
||||
* Resizes an array. If the size is smaller than the current size,
|
||||
* the array is truncated.
|
||||
*
|
||||
* @param which Array Handle.
|
||||
* @param newsize New size.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @param which Array handle.
|
||||
* @param newsize New size.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle or out of memory.
|
||||
*/
|
||||
native bool:ArrayResize(Array:which, newsize);
|
||||
|
||||
@ -66,29 +96,42 @@ native bool:ArrayResize(Array:which, newsize);
|
||||
* Returns data within an array.
|
||||
* Make sure the output buffer matches the size the array was created with!
|
||||
*
|
||||
* @param which The array to retrieve the item from.
|
||||
* @param item The item to retrieve (zero-based).
|
||||
* @param output The output buffer to write.
|
||||
* @param which The array to retrieve the item from.
|
||||
* @param item The item to retrieve (zero-based).
|
||||
* @param size If not set, assumes the buffer size is equal to the
|
||||
* cellsize. Otherwise, the size passed is used.
|
||||
* @param output The output buffer to write.
|
||||
*
|
||||
* @return Number of cells copied.
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArrayGetArray(Array:which, item, any:output[]);
|
||||
native ArrayGetArray(Array:which, item, any:output[], size = -1);
|
||||
|
||||
/**
|
||||
* Returns a single cell of data from an array.
|
||||
* Use this only with arrays that were created with a cellsize of 1!
|
||||
*
|
||||
* @param which The array to retrieve the item from.
|
||||
* @param item The item to retrieve (zero-based).
|
||||
* @return The value of the cell.
|
||||
* @param which The array to retrieve the item from.
|
||||
* @param item The item to retrieve (zero-based).
|
||||
* @param block Optionally specify which block to read from
|
||||
* (useful if the blocksize > 0).
|
||||
* @param asChar Optionally read as a byte instead of a cell.
|
||||
*
|
||||
* @return Value read.
|
||||
* @error Invalid handle, invalid index, or invalid block.
|
||||
*/
|
||||
native any:ArrayGetCell(Array:which, item);
|
||||
native any:ArrayGetCell(Array:which, item, block = 0, bool:asChar = false);
|
||||
|
||||
/**
|
||||
* Returns a string value from an array.
|
||||
*
|
||||
* @param which The array to retrieve the item from.
|
||||
* @param item The item to retrieve (zero-based).
|
||||
* @param output The variable to store the value in.
|
||||
* @param size Character size of the output buffer.
|
||||
* @param which The array to retrieve the item from.
|
||||
* @param item The item to retrieve (zero-based).
|
||||
* @param output The variable to store the value in.
|
||||
* @param size Character size of the output buffer.
|
||||
*
|
||||
* @return Number of characters copied.
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArrayGetString(Array:which, item, output[], size);
|
||||
|
||||
@ -97,30 +140,44 @@ native ArrayGetString(Array:which, item, output[], size);
|
||||
* The buffer size must match what the cellsize that the array was created with!
|
||||
* The item must already exist, use ArrayPushArray to create a new item within the array.
|
||||
*
|
||||
* @param which The array to set the item from within.
|
||||
* @param item The item to set (zero-based).
|
||||
* @param input The input buffer to store.
|
||||
* @param which The array to set the item from within.
|
||||
* @param item The item to set (zero-based).
|
||||
* @param input The input buffer to store.
|
||||
* @param size If not set, assumes the buffer size is equal to the
|
||||
* blocksize. Otherwise, the size passed is used.
|
||||
*
|
||||
* @return Number of cells copied.
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArraySetArray(Array:which, item, const any:input[]);
|
||||
native ArraySetArray(Array:which, item, const any:input[], size =-1);
|
||||
|
||||
/**
|
||||
* Sets an array's single cell value. Use this only on array that were created with a cellsize of 1!
|
||||
* The item must already exist, use ArrayPushCell to create a new item within the array.
|
||||
*
|
||||
* @param which The array to set the item from within.
|
||||
* @param item The item to set (zero-based).
|
||||
* @param input The value to set.
|
||||
* @param which The array to set the item from within.
|
||||
* @param item The item to set (zero-based).
|
||||
* @param input The value to set.
|
||||
* @param block Optionally specify which block to write to
|
||||
* (useful if the blocksize > 0).
|
||||
* @param asChar Optionally set as a byte instead of a cell.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle, invalid index, or invalid block.
|
||||
*/
|
||||
native ArraySetCell(Array:which, item, any:input);
|
||||
native ArraySetCell(Array:which, item, any:input, block = 0, bool:asChar = false);
|
||||
|
||||
/**
|
||||
* Sets a string value from an array.
|
||||
* The stored string will be truncated if it is longer than the cellsize the array was created with!
|
||||
* The item must already exist, use ArrayPushString to create a new item within the array.
|
||||
*
|
||||
* @param which The array to set the item from within.
|
||||
* @param item The item to set (zero-based).
|
||||
* @param input The string to set the item as.
|
||||
* @param which The array to set the item from within.
|
||||
* @param item The item to set (zero-based).
|
||||
* @param input The string to set the item as.
|
||||
*
|
||||
* @return Number of characters copied.
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArraySetString(Array:which, item, const input[]);
|
||||
|
||||
@ -128,17 +185,26 @@ native ArraySetString(Array:which, item, const input[]);
|
||||
* Creates a new item at the end of the array and sets its data with that of a local buffer.
|
||||
* The buffer size must match what the cellsize that the array was created with!
|
||||
*
|
||||
* @param which The array to add the item to.
|
||||
* @param input The input buffer to store.
|
||||
* @param which The array to add the item to.
|
||||
* @param input The input buffer to store.
|
||||
* @param size If not set, the number of elements copied from the array
|
||||
* will be equal to the blocksize. If set higher than the
|
||||
* blocksize, the operation will be truncated.
|
||||
*
|
||||
* @return Index of the new entry.
|
||||
* @error Invalid handle or out of memory.
|
||||
*/
|
||||
native ArrayPushArray(Array:which, const any:input[]);
|
||||
native ArrayPushArray(Array:which, const any:input[], size = -1);
|
||||
|
||||
/**
|
||||
* Creates a new item and sets the array's single cell value.
|
||||
* Use this only on array that were created with a cellsize of 1!
|
||||
*
|
||||
* @param which The array to add the item to.
|
||||
* @param input The value to set.
|
||||
* @param which The array to add the item to.
|
||||
* @param input The value to set.
|
||||
*
|
||||
* @return Index of the new entry.
|
||||
* @error Invalid handle or out of memory.
|
||||
*/
|
||||
native ArrayPushCell(Array:which, any:input);
|
||||
|
||||
@ -146,8 +212,11 @@ native ArrayPushCell(Array:which, any:input);
|
||||
* Creates a new element in the array and sets its value to the input buffer.
|
||||
* The stored string will be truncated if it is longer than the cellsize the array was created with!
|
||||
*
|
||||
* @param which The array to add the item to.
|
||||
* @param input The string to set the item as.
|
||||
* @param which The array to add the item to.
|
||||
* @param input The string to set the item as.
|
||||
*
|
||||
* @return Index of the new entry.
|
||||
* @error Invalid handle or out of memory.
|
||||
*/
|
||||
native ArrayPushString(Array:which, const input[]);
|
||||
|
||||
@ -155,9 +224,12 @@ native ArrayPushString(Array:which, const input[]);
|
||||
* Inserts an item after the selected item. All items beyond it get shifted up 1 space.
|
||||
* The buffer size must match what the cellsize that the array was created with!
|
||||
*
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert after.
|
||||
* @param input The input buffer to store.
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert after.
|
||||
* @param input The input buffer to store.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArrayInsertArrayAfter(Array:which, item, const any:input[]);
|
||||
|
||||
@ -165,9 +237,12 @@ native ArrayInsertArrayAfter(Array:which, item, const any:input[]);
|
||||
* Inserts an item after the selected item. All items beyond it get shifted up 1 space.
|
||||
* Use this only on an array that was created with a cellsize of 1!
|
||||
*
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert after.
|
||||
* @param input The value to set.
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert after.
|
||||
* @param input The value to set.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArrayInsertCellAfter(Array:which, item, any:input);
|
||||
|
||||
@ -175,9 +250,12 @@ native ArrayInsertCellAfter(Array:which, item, any:input);
|
||||
* Inserts an item after the selected item. All items beyond it get shifted up 1 space.
|
||||
* The stored string will be truncated if it is longer than the cellsize the array was created with!
|
||||
*
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert after.
|
||||
* @param input The value to set.
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert after.
|
||||
* @param input The value to set.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArrayInsertStringAfter(Array:which, item, const input[]);
|
||||
|
||||
@ -185,9 +263,12 @@ native ArrayInsertStringAfter(Array:which, item, const input[]);
|
||||
* Inserts an item before the selected item. All items beyond it, and the selected item get shifted up 1 space.
|
||||
* The buffer size must match what the cellsize that the array was created with!
|
||||
*
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert before.
|
||||
* @param input The input buffer to store.
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert before.
|
||||
* @param input The input buffer to store.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArrayInsertArrayBefore(Array:which, item, const any:input[]);
|
||||
|
||||
@ -195,9 +276,12 @@ native ArrayInsertArrayBefore(Array:which, item, const any:input[]);
|
||||
* Inserts an item before the selected item. All items beyond it, and the selected item get shifted up 1 space.
|
||||
* Use this only on an array that was created with a cellsize of 1!
|
||||
*
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert after.
|
||||
* @param input The value to set.
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert after.
|
||||
* @param input The value to set.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArrayInsertCellBefore(Array:which, item, const any:input);
|
||||
|
||||
@ -205,26 +289,35 @@ native ArrayInsertCellBefore(Array:which, item, const any:input);
|
||||
* Inserts an item before the selected item. All items beyond it, and the selected item get shifted up 1 space.
|
||||
* The stored string will be truncated if it is longer than the cellsize the array was created with!
|
||||
*
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert before.
|
||||
* @param input The value to set.
|
||||
* @param which The array to add the item to.
|
||||
* @param item The item to insert before.
|
||||
* @param input The value to set.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArrayInsertStringBefore(Array:which, item, const input[]);
|
||||
|
||||
/**
|
||||
* Swaps the position of two items.
|
||||
*
|
||||
* @param which The array that contains the items.
|
||||
* @param item1 The first item to swap.
|
||||
* @param item2 The second item to swap.
|
||||
* @param which The array that contains the items.
|
||||
* @param item1 The first item to swap.
|
||||
* @param item2 The second item to swap.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArraySwap(Array:which, item1, item2);
|
||||
|
||||
/**
|
||||
* Deletes an item from the array. All items beyond it get shifted down 1 space.
|
||||
*
|
||||
* @param which The array that contains the item to delete.
|
||||
* @param item The item to delete.
|
||||
* @param which The array that contains the item to delete.
|
||||
* @param item The item to delete.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native ArrayDeleteItem(Array:which, item);
|
||||
|
||||
@ -232,9 +325,11 @@ native ArrayDeleteItem(Array:which, item);
|
||||
* Returns the index for the first occurance of the provided string. If the string
|
||||
* cannot be located, -1 will be returned.
|
||||
*
|
||||
* @param which Array Handle.
|
||||
* @param item String to search for.
|
||||
* @return Array index, or -1 on failure.
|
||||
* @param which Array handle.
|
||||
* @param item String to search for.
|
||||
*
|
||||
* @return Array index, or -1 on failure.
|
||||
* @error Invalid handle.
|
||||
*/
|
||||
native ArrayFindString(Array:which, const item[]);
|
||||
|
||||
@ -242,9 +337,11 @@ native ArrayFindString(Array:which, const item[]);
|
||||
* Returns the index for the first occurance of the provided value. If the value
|
||||
* cannot be located, -1 will be returned.
|
||||
*
|
||||
* @param which Array Handle.
|
||||
* @param item Value to search for.
|
||||
* @return Array index, or -1 on failure.
|
||||
* @param which Array handle.
|
||||
* @param item Value to search for.
|
||||
*
|
||||
* @return Array index, or -1 on failure.
|
||||
* @error Invalid handle.
|
||||
*/
|
||||
native ArrayFindValue(Array:which, any:item);
|
||||
|
||||
@ -255,21 +352,25 @@ native ArrayFindValue(Array:which, any:item);
|
||||
*
|
||||
* An example usage: client_print(id, print_chat, "%a", ArrayGetStringHandle(MessageArray, i));
|
||||
*
|
||||
* @param which The array the string is stored in.
|
||||
* @param item Which item to print the string value of.
|
||||
* @return Handle to the item directly. Do not use or save stale handles.
|
||||
* @param which The array the string is stored in.
|
||||
* @param item Which item to print the string value of.
|
||||
*
|
||||
* @return Handle to the item directly. Do not use or save stale handles.
|
||||
* @error Invalid handle or invalid index.
|
||||
*/
|
||||
native DoNotUse:ArrayGetStringHandle(Array:which, item);
|
||||
|
||||
/**
|
||||
* Destroys the array, and resets the handle to 0 to prevent accidental usage after it is destroyed.
|
||||
*
|
||||
* @param which The array to destroy.
|
||||
* @param which The array to destroy.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle.
|
||||
*/
|
||||
native ArrayDestroy(&Array:which);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Similar to sorting.inc's CustomSort.
|
||||
* The sorting algorithm then uses your comparison function to sort the data.
|
||||
@ -277,18 +378,26 @@ native ArrayDestroy(&Array:which);
|
||||
*
|
||||
* public MySortFunc(Array:array, item1, item2, const data[], data_size)
|
||||
*
|
||||
* array - Array handle in its current un-sorted state.
|
||||
* item1, item2 - Current item pair being compared
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
* array - Array handle in its current un-sorted state.
|
||||
* item1, item2 - Current item pair being compared
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
*
|
||||
* Your function should return:
|
||||
* -1 if item1 should go before item2
|
||||
* 0 if item1 and item2 are equal
|
||||
* 1 if item1 should go after item2
|
||||
* Note that the parameters after item2 are all optional and you do not need to specify them.
|
||||
*
|
||||
* Note that the parameters after item2 are all optional and you do not need to specify them.
|
||||
* Note that unlike the sorting.inc versions, the array passed to the callback is not in mid-sorted state.
|
||||
*
|
||||
* @param array Array handle.
|
||||
* @param comparefunc A callback function used for comparison.
|
||||
* @param data Extra data array you passed to the sort func.
|
||||
* @param data_size Size of extra data you passed to the sort func.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle or invalid callback.
|
||||
*/
|
||||
native ArraySort(Array:array, const comparefunc[], data[]="", data_size=0);
|
||||
|
||||
@ -306,20 +415,20 @@ native ArraySort(Array:array, const comparefunc[], data[]="", data_size=0);
|
||||
*
|
||||
* public MySortFunc(Array:array, elem1, elem2, const data[], data_size)
|
||||
*
|
||||
* array - Array handle in its current un-sorted state.
|
||||
* elem1, elem2 - Current element pair being compared
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
* array - Array handle in its current un-sorted state.
|
||||
* elem1, elem2 - Current element pair being compared
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
*
|
||||
* For Arrays with a cellsize larger than 1 (used for storing arrays and strings),
|
||||
* the function is called in the following manner:
|
||||
*
|
||||
* public MySortFunc(Array:array, elem1[], elem2[], const data[], data_size)
|
||||
*
|
||||
* array - Array handle in its current un-sorted state.
|
||||
* elem1[], elem2[] - Current element pair being compared
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
* array - Array handle in its current un-sorted state.
|
||||
* elem1[], elem2[] - Current element pair being compared
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
*
|
||||
*
|
||||
* In both cases your function should return:
|
||||
@ -328,7 +437,14 @@ native ArraySort(Array:array, const comparefunc[], data[]="", data_size=0);
|
||||
* 1 if elem1 should go after elem2
|
||||
*
|
||||
* Note that the parameters after elem2 are all optional and you do not need to specify them.
|
||||
*
|
||||
* Note that unlike the sorting.inc versions, the array passed to the callback is not in mid-sorted state.
|
||||
*
|
||||
* @param array Array handle.
|
||||
* @param comparefunc A callback function used for comparison.
|
||||
* @param data Extra data array you passed to the sort func.
|
||||
* @param data_size Size of extra data you passed to the sort func.
|
||||
*
|
||||
* @noreturn
|
||||
* @error Invalid handle, invalid callback or out of memory.
|
||||
*/
|
||||
native ArraySortEx(Array:array, const comparefunc[], data[]="", data_size=0);
|
||||
|
@ -24,39 +24,39 @@ new TestWords[6][] = {
|
||||
"!="
|
||||
};
|
||||
|
||||
stock test(any:A,any:B=0,TestType:Type=TT_Equal)
|
||||
stock test(any:A, any: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;
|
||||
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);
|
||||
log_amx("Failed test #%d (%d %s %d)", __testnumber, A, TestWords[_:Type], B);
|
||||
errcount++;
|
||||
}
|
||||
}
|
||||
stock starttests(const startfunc[])
|
||||
{
|
||||
__testnumber=0;
|
||||
errcount=0;
|
||||
__testfuncnum=1;
|
||||
__testnumber = 0;
|
||||
errcount = 0;
|
||||
__testfuncnum = 1;
|
||||
server_print("Starting tests...");
|
||||
formatex(__testfunc,sizeof(__testfunc)-1,"%s",startfunc);
|
||||
formatex(__testfunc, charsmax(__testfunc), "%s", startfunc);
|
||||
|
||||
new func[32];
|
||||
formatex(func,sizeof(func)-1,"%s%d",__testfunc,__testfuncnum++);
|
||||
set_task(0.1,func);
|
||||
formatex(func, charsmax(func), "%s%d", __testfunc, __testfuncnum++);
|
||||
set_task(0.1, func);
|
||||
}
|
||||
|
||||
stock showres()
|
||||
@ -64,16 +64,16 @@ stock showres()
|
||||
if (errcount==0)
|
||||
{
|
||||
new func[32];
|
||||
formatex(func,sizeof(func)-1,"%s%d",__testfunc,__testfuncnum++);
|
||||
if (get_func_id(func)==-1)
|
||||
formatex(func, charsmax(func), "%s%d", __testfunc, __testfuncnum++);
|
||||
if (get_func_id(func) == -1)
|
||||
{
|
||||
server_print("All tests ok!");
|
||||
}
|
||||
else
|
||||
{
|
||||
server_print("Test ok, moving on...");
|
||||
|
||||
set_task(0.1,func);
|
||||
|
||||
set_task(0.1, func);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -96,134 +96,128 @@ public arraytest()
|
||||
public arraytest1()
|
||||
{
|
||||
server_print("Testing 1000 iterations of 1-cell arrays...");
|
||||
|
||||
|
||||
new Float:f;
|
||||
new Array:a=ArrayCreate(1);
|
||||
new Array:a = ArrayCreate(1);
|
||||
|
||||
if (a == Invalid_Array)
|
||||
{
|
||||
}
|
||||
for (new i=0; i<1000; i++)
|
||||
|
||||
for (new i = 0; i < 1000; i++)
|
||||
{
|
||||
f=float(i);
|
||||
f = float(i);
|
||||
ArrayPushCell(a,f);
|
||||
}
|
||||
|
||||
new Float:r;
|
||||
for (new i=0; i<1000; i++)
|
||||
for (new i = 0; i < 1000; i++)
|
||||
{
|
||||
f=float(i);
|
||||
r=Float:ArrayGetCell(a, i);
|
||||
|
||||
f = float(i);
|
||||
r = Float:ArrayGetCell(a, i);
|
||||
|
||||
// This is normally bad for float "casting", but in this case it should be fine.
|
||||
test(_:f, _:r);
|
||||
|
||||
|
||||
|
||||
// Reset with inversed values
|
||||
new g=_:f;
|
||||
g=~g;
|
||||
|
||||
|
||||
ArraySetCell(a, i, g);
|
||||
|
||||
r=Float:ArrayGetCell(a,i);
|
||||
|
||||
r = Float:ArrayGetCell(a,i);
|
||||
test(g, _:r);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
stock bool:checkarray(const a[], const b[], size)
|
||||
{
|
||||
while (size--)
|
||||
{
|
||||
if (a[size]!=b[size])
|
||||
if (a[size] != b[size])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
stock invarray(a[],size)
|
||||
{
|
||||
while (size--)
|
||||
{
|
||||
a[size] = ~a[size];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public arraytest2()
|
||||
{
|
||||
server_print("Testing 1000 iterations of 40-cell arrays...");
|
||||
|
||||
new Array:a=ArrayCreate(40);
|
||||
|
||||
new Array:a = ArrayCreate(40);
|
||||
new buff[40];
|
||||
new buffb[40];
|
||||
for (new i=0; i<1000; i++)
|
||||
{
|
||||
arrayset(buff,i,sizeof(buff));
|
||||
|
||||
ArrayPushArray(a, buff);
|
||||
}
|
||||
for (new i=0; i<1000; i++)
|
||||
|
||||
for (new i = 0; i < 1000; i++)
|
||||
{
|
||||
arrayset(buff, i, sizeof(buff));
|
||||
|
||||
ArrayGetArray(a, i, buffb);
|
||||
|
||||
test(_:checkarray(buff,buffb,sizeof(buff)),1);
|
||||
|
||||
// Now overwrite the array with inversed value
|
||||
invarray(buff,sizeof(buff));
|
||||
|
||||
ArraySetArray(a, i, buff);
|
||||
|
||||
ArrayGetArray(a, i, buffb);
|
||||
|
||||
test(_:checkarray(buff,buffb,sizeof(buff)),1);
|
||||
|
||||
ArrayPushArray(a, buff);
|
||||
}
|
||||
|
||||
for (new i = 0; i < 1000; i++)
|
||||
{
|
||||
arrayset(buff, i, sizeof(buff));
|
||||
ArrayGetArray(a, i, buffb);
|
||||
test(_:checkarray(buff, buffb, sizeof(buff)), 1);
|
||||
|
||||
// Now overwrite the array with inversed value
|
||||
invarray(buff, sizeof(buff));
|
||||
|
||||
ArraySetArray(a, i, buff);
|
||||
ArrayGetArray(a, i, buffb);
|
||||
test(_:checkarray(buff, buffb, sizeof(buff)), 1);
|
||||
}
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest3()
|
||||
{
|
||||
server_print("Testing 1000 iterations of strings...");
|
||||
|
||||
|
||||
// The string is 10 long, the string we're trying to pass is 20 long.
|
||||
|
||||
new Array:a=ArrayCreate(10);
|
||||
|
||||
new buff[20]="1234567890abcdefghi";
|
||||
new Array:a = ArrayCreate(10);
|
||||
|
||||
new buff[20] = "1234567890abcdefghi";
|
||||
new buffb[20];
|
||||
|
||||
for (new i=0; i<1000; i++)
|
||||
|
||||
for (new i = 0; i < 1000; i++)
|
||||
{
|
||||
ArrayPushString(a, buff);
|
||||
}
|
||||
for (new i=0; i<1000; i++)
|
||||
|
||||
for (new i = 0; i < 1000; i++)
|
||||
{
|
||||
ArrayGetString(a, i, buffb, sizeof(buffb)-1);
|
||||
|
||||
ArrayGetString(a, i, buffb, charsmax(buffb));
|
||||
test(strcmp(buffb,"123456789"),0);
|
||||
|
||||
|
||||
ArraySetString(a, i, "9876543210");
|
||||
|
||||
ArrayGetString(a, i, buffb, sizeof(buffb)-1);
|
||||
|
||||
ArrayGetString(a, i, buffb, charsmax(buffb));
|
||||
test(strcmp(buffb,"987654321"),0);
|
||||
|
||||
buffb[0]=0;
|
||||
|
||||
formatex(buffb,sizeof(buffb)-1,"%a", ArrayGetStringHandle(a, i));
|
||||
|
||||
|
||||
buffb[0] = EOS;
|
||||
formatex(buffb, charsmax(buffb),"%a", ArrayGetStringHandle(a, i));
|
||||
test(strcmp(buffb, "987654321"),0);
|
||||
}
|
||||
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
@ -231,17 +225,19 @@ public sortcallback(Array:a, b, c)
|
||||
{
|
||||
static stra[40];
|
||||
static strb[40];
|
||||
|
||||
ArrayGetString(a, b, stra, sizeof(stra)-1);
|
||||
ArrayGetString(a, c, strb, sizeof(strb)-1);
|
||||
|
||||
ArrayGetString(a, b, stra, charsmax(stra));
|
||||
ArrayGetString(a, c, strb, charsmax(strb));
|
||||
|
||||
return strcmp(stra,strb);
|
||||
}
|
||||
|
||||
public arraytest4()
|
||||
{
|
||||
server_print("Testing sorting function...");
|
||||
|
||||
new Array:a=ArrayCreate(40);
|
||||
|
||||
|
||||
new Array:a = ArrayCreate(40);
|
||||
|
||||
ArrayPushString(a, "z");
|
||||
ArrayPushString(a, "yz");
|
||||
ArrayPushString(a, "xyz");
|
||||
@ -268,203 +264,286 @@ public arraytest4()
|
||||
ArrayPushString(a, "cdefghijklmnopqrstuvwxyz");
|
||||
ArrayPushString(a, "bcdefghijklmnopqrstuvwxyz");
|
||||
ArrayPushString(a, "abcdefghijklmnopqrstuvwxyz");
|
||||
|
||||
new OldSize=ArraySize(a);
|
||||
|
||||
|
||||
new OldSize = ArraySize(a);
|
||||
|
||||
ArraySort(a, "sortcallback");
|
||||
|
||||
test(ArraySize(a),OldSize);
|
||||
|
||||
test(ArraySize(a), OldSize);
|
||||
|
||||
new buff[40];
|
||||
|
||||
ArrayGetString(a,0,buff,sizeof(buff)-1);
|
||||
|
||||
ArrayGetString(a, 0, buff, charsmax(buff));
|
||||
test(strcmp(buff,"abcdefghijklmnopqrstuvwxyz"),0);
|
||||
|
||||
ArrayGetString(a,25,buff,sizeof(buff)-1);
|
||||
|
||||
test(strcmp(buff,"z"),0);
|
||||
|
||||
|
||||
new start='a';
|
||||
|
||||
for (new i=0;i<OldSize;i++)
|
||||
ArrayGetString(a, 25, buff, charsmax(buff));
|
||||
test(strcmp(buff, "z"), 0);
|
||||
|
||||
new start = 'a';
|
||||
|
||||
for (new i = 0; i < OldSize; i++)
|
||||
{
|
||||
ArrayGetString(a,i,buff,sizeof(buff)-1)
|
||||
|
||||
test(buff[0],start++);
|
||||
ArrayGetString(a, i, buff, charsmax(buff));
|
||||
test(buff[0], start++);
|
||||
}
|
||||
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest5()
|
||||
{
|
||||
server_print("Testing ArrayDeleteItem()...");
|
||||
new Array:a=ArrayCreate(1);
|
||||
|
||||
|
||||
new Array:a = ArrayCreate(1);
|
||||
new v;
|
||||
|
||||
for (new i=0; i<1000; i++)
|
||||
|
||||
for (new i = 0; i < 1000; i++)
|
||||
{
|
||||
ArrayPushCell(a, i);
|
||||
}
|
||||
for (new i=ArraySize(a) - 1; i>=0 ; i--)
|
||||
|
||||
for (new i = ArraySize(a) - 1; i >= 0; i--)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
ArrayDeleteItem(a, i);
|
||||
}
|
||||
}
|
||||
|
||||
test(ArraySize(a), 500);
|
||||
for (new i=0; i< 500; i++)
|
||||
|
||||
for (new i = 0; i < 500; i++)
|
||||
{
|
||||
v=ArrayGetCell(a, i);
|
||||
|
||||
v = ArrayGetCell(a, i);
|
||||
|
||||
// All items should be incrementing odd numbers
|
||||
test(((i + 1) * 2) - 1, v);
|
||||
|
||||
// All remaining entries should be odd
|
||||
test((v & 1), 1);
|
||||
}
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
a=ArrayCreate(1);
|
||||
|
||||
a = ArrayCreate(1);
|
||||
|
||||
// Repeat the same test, but check even numbers
|
||||
for (new i=0; i<1000; i++)
|
||||
for (new i = 0; i < 1000; i++)
|
||||
{
|
||||
ArrayPushCell(a, i);
|
||||
}
|
||||
for (new i=ArraySize(a) - 1; i>=0 ; i--)
|
||||
|
||||
for (new i = ArraySize(a) - 1; i >= 0 ; i--)
|
||||
{
|
||||
if (i % 2 == 1)
|
||||
{
|
||||
ArrayDeleteItem(a, i);
|
||||
}
|
||||
}
|
||||
|
||||
test(ArraySize(a), 500);
|
||||
for (new i=0; i< 500; i++)
|
||||
|
||||
for (new i = 0; i < 500; i++)
|
||||
{
|
||||
v=ArrayGetCell(a, i);
|
||||
|
||||
v = ArrayGetCell(a, i);
|
||||
|
||||
// All items should be incrementing even numbers
|
||||
test(((i + 1) * 2) - 2, v);
|
||||
|
||||
// All remaining entries should be even
|
||||
test((v & 1), 0);
|
||||
}
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest6()
|
||||
{
|
||||
server_print("Testing ArrayInsertCellAfter()...");
|
||||
|
||||
new Array:a=ArrayCreate(1);
|
||||
|
||||
for (new i=0; i<10;i++)
|
||||
|
||||
new Array:a = ArrayCreate(1);
|
||||
|
||||
for (new i = 0; i < 10;i++)
|
||||
{
|
||||
ArrayPushCell(a, i);
|
||||
new item=ArraySize(a)-1;
|
||||
for (new j=0; j<10; j++)
|
||||
new item = ArraySize(a) - 1;
|
||||
|
||||
for (new j = 0; j < 10; j++)
|
||||
{
|
||||
ArrayInsertCellAfter(a, item + j, j);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
test(ArraySize(a), 110);
|
||||
|
||||
|
||||
new v;
|
||||
for (new i=0; i<110; i++)
|
||||
for (new i = 0; i < 110; i++)
|
||||
{
|
||||
v=ArrayGetCell(a, i);
|
||||
|
||||
v = ArrayGetCell(a, i);
|
||||
test(v, i / 10);
|
||||
for (new j=0; j<10; j++)
|
||||
|
||||
for (new j = 0; j < 10; j++)
|
||||
{
|
||||
v=ArrayGetCell(a, ++i);
|
||||
v = ArrayGetCell(a, ++i);
|
||||
test(v, j);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest7()
|
||||
{
|
||||
server_print("Testing ArrayInsertCellBefore()...");
|
||||
server_print("Testing ArrayInsertStringAfter()...");
|
||||
|
||||
new Array:a = ArrayCreate(4);
|
||||
new buffer[4];
|
||||
|
||||
new Array:a=ArrayCreate(1);
|
||||
|
||||
for (new i=0; i<10;i++)
|
||||
for (new i = 0; i < 10;i++)
|
||||
{
|
||||
ArrayPushCell(a, i);
|
||||
new item=ArraySize(a)-1;
|
||||
for (new j=0; j<10; j++)
|
||||
formatex(buffer, charsmax(buffer), "%d", i);
|
||||
ArrayPushString(a, buffer);
|
||||
new item = ArraySize(a) - 1;
|
||||
|
||||
for (new j = 0; j < 10; j++)
|
||||
{
|
||||
formatex(buffer, charsmax(buffer), "%d", j);
|
||||
ArrayInsertStringAfter(a, item + j, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
test(ArraySize(a), 110);
|
||||
|
||||
for (new i = 0; i < 110; i++)
|
||||
{
|
||||
ArrayGetString(a, i, buffer, charsmax(buffer));
|
||||
test(str_to_num(buffer), i / 10);
|
||||
|
||||
for (new j = 0; j < 10; j++)
|
||||
{
|
||||
ArrayGetString(a, ++i, buffer, charsmax(buffer));
|
||||
test(str_to_num(buffer), j);
|
||||
}
|
||||
}
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest8()
|
||||
{
|
||||
server_print("Testing ArrayInsertCellBefore()...");
|
||||
|
||||
new Array:a = ArrayCreate(1);
|
||||
|
||||
for (new i = 0; i < 10; i++)
|
||||
{
|
||||
new item = ArrayPushCell(a, i);
|
||||
|
||||
for (new j = 0; j < 10; j++)
|
||||
{
|
||||
ArrayInsertCellBefore(a, item, j);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
test(ArraySize(a), 110);
|
||||
|
||||
new v;
|
||||
for (new i=0; i<110; i++)
|
||||
|
||||
for (new i = 0; i < 110; i++)
|
||||
{
|
||||
for (new j=9; j>=0; j--)
|
||||
for (new j = 9; j >= 0; j--)
|
||||
{
|
||||
v=ArrayGetCell(a, i++);
|
||||
test(v, j);
|
||||
test(ArrayGetCell(a, i++), j);
|
||||
}
|
||||
|
||||
v=ArrayGetCell(a, i);
|
||||
|
||||
test(v, (i - 10) / 10);
|
||||
|
||||
test(ArrayGetCell(a, i), (i - 10) / 10);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
showres();
|
||||
}
|
||||
public arraytest8()
|
||||
{
|
||||
server_print("Testing ArraySwap()...");
|
||||
new Array:a=ArrayCreate(1);
|
||||
|
||||
for (new i=0; i<10; i++)
|
||||
{
|
||||
ArrayPushCell(a, i);
|
||||
}
|
||||
for (new i=0; i<5; i++)
|
||||
{
|
||||
ArraySwap(a, i, (10 - (i + 1)));
|
||||
}
|
||||
new v;
|
||||
for (new i=0; i<5; i++)
|
||||
{
|
||||
v=ArrayGetCell(a, i);
|
||||
|
||||
test(v, (10 - (i + 1)));
|
||||
}
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public sortcallbackex_string(Array:a, const b[], const c[], d)
|
||||
{
|
||||
return strcmp(b,c);
|
||||
}
|
||||
public arraytest9()
|
||||
{
|
||||
server_print("Testing ArrayInsertStringBefore()...");
|
||||
|
||||
new buffer[4];
|
||||
new Array:a = ArrayCreate(4);
|
||||
|
||||
for (new i = 0; i < 10; i++)
|
||||
{
|
||||
formatex(buffer, charsmax(buffer), "%d", i);
|
||||
new item = ArrayPushString(a, buffer);
|
||||
|
||||
for (new j = 0; j < 10; j++)
|
||||
{
|
||||
formatex(buffer, charsmax(buffer), "%d", j);
|
||||
ArrayInsertStringBefore(a, item, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
test(ArraySize(a), 110);
|
||||
|
||||
for (new i = 0; i < 110; i++)
|
||||
{
|
||||
for (new j = 9; j >= 0; j--)
|
||||
{
|
||||
ArrayGetString(a, i++, buffer, charsmax(buffer));
|
||||
test(str_to_num(buffer), j);
|
||||
}
|
||||
|
||||
ArrayGetString(a, i, buffer, charsmax(buffer));
|
||||
test(str_to_num(buffer), (i - 10) / 10);
|
||||
}
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest10()
|
||||
{
|
||||
server_print("Testing ArraySwap()...");
|
||||
|
||||
new Array:a = ArrayCreate(1);
|
||||
|
||||
for (new i = 0; i < 10; i++)
|
||||
{
|
||||
ArrayPushCell(a, i);
|
||||
}
|
||||
|
||||
for (new i = 0; i < 5; i++)
|
||||
{
|
||||
ArraySwap(a, i, (10 - (i + 1)));
|
||||
}
|
||||
|
||||
new v;
|
||||
for (new i = 0; i < 5; i++)
|
||||
{
|
||||
v = ArrayGetCell(a, i);
|
||||
|
||||
test(v, (10 - (i + 1)));
|
||||
}
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public Sortcallbackex_string(Array:a, const b[], const c[], d)
|
||||
{
|
||||
return strcmp(b, c);
|
||||
}
|
||||
|
||||
public arraytest11()
|
||||
{
|
||||
server_print("Testing (new) sorting function with string...");
|
||||
|
||||
new Array:a=ArrayCreate(40);
|
||||
|
||||
|
||||
new Array:a = ArrayCreate(40);
|
||||
|
||||
ArrayPushString(a, "z");
|
||||
ArrayPushString(a, "yz");
|
||||
ArrayPushString(a, "xyz");
|
||||
@ -491,48 +570,44 @@ public arraytest9()
|
||||
ArrayPushString(a, "cdefghijklmnopqrstuvwxyz");
|
||||
ArrayPushString(a, "bcdefghijklmnopqrstuvwxyz");
|
||||
ArrayPushString(a, "abcdefghijklmnopqrstuvwxyz");
|
||||
|
||||
new OldSize=ArraySize(a);
|
||||
|
||||
ArraySortEx(a, "sortcallbackex_string");
|
||||
|
||||
test(ArraySize(a),OldSize);
|
||||
|
||||
|
||||
new OldSize = ArraySize(a);
|
||||
|
||||
ArraySortEx(a, "Sortcallbackex_string");
|
||||
test(ArraySize(a), OldSize);
|
||||
|
||||
new buff[40];
|
||||
|
||||
ArrayGetString(a,0,buff,sizeof(buff)-1);
|
||||
ArrayGetString(a, 0, buff, charsmax(buff));
|
||||
test(strcmp(buff, "abcdefghijklmnopqrstuvwxyz"), 0);
|
||||
|
||||
test(strcmp(buff,"abcdefghijklmnopqrstuvwxyz"),0);
|
||||
|
||||
ArrayGetString(a,25,buff,sizeof(buff)-1);
|
||||
|
||||
test(strcmp(buff,"z"),0);
|
||||
ArrayGetString(a, 25, buff, charsmax(buff));
|
||||
test(strcmp(buff, "z"),0);
|
||||
|
||||
|
||||
new start='a';
|
||||
|
||||
for (new i=0;i<OldSize;i++)
|
||||
new start = 'a';
|
||||
|
||||
for (new i = 0; i < OldSize; i++)
|
||||
{
|
||||
ArrayGetString(a,i,buff,sizeof(buff)-1)
|
||||
|
||||
test(buff[0],start++);
|
||||
ArrayGetString(a, i, buff, charsmax(buff))
|
||||
test(buff[0], start++);
|
||||
}
|
||||
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public sortcallbackex_int(Array:a, const b, const c, d)
|
||||
|
||||
public Sortcallbackex_int(Array:a, const b, const c, d)
|
||||
{
|
||||
return b < c ? -1 : 1;
|
||||
}
|
||||
public arraytest10()
|
||||
|
||||
public arraytest12()
|
||||
{
|
||||
server_print("Testing (new) sorting function with integer...");
|
||||
|
||||
new Array:a=ArrayCreate(1);
|
||||
|
||||
|
||||
new Array:a = ArrayCreate(1);
|
||||
|
||||
ArrayPushCell(a, 8);
|
||||
ArrayPushCell(a, 1);
|
||||
ArrayPushCell(a, 3);
|
||||
@ -543,76 +618,19 @@ public arraytest10()
|
||||
ArrayPushCell(a, 4);
|
||||
ArrayPushCell(a, 10);
|
||||
ArrayPushCell(a, 6);
|
||||
|
||||
new OldSize=ArraySize(a);
|
||||
|
||||
ArraySortEx(a, "sortcallbackex_int");
|
||||
|
||||
test(ArraySize(a),OldSize);
|
||||
test(ArrayGetCell(a, 0),1);
|
||||
test(ArrayGetCell(a, 9),10);
|
||||
new OldSize = ArraySize(a);
|
||||
|
||||
for (new i=0;i<OldSize;i++)
|
||||
ArraySortEx(a, "Sortcallbackex_int");
|
||||
|
||||
test(ArraySize(a), OldSize);
|
||||
test(ArrayGetCell(a, 0), 1);
|
||||
test(ArrayGetCell(a, 9), 10);
|
||||
|
||||
for (new i = 0; i < OldSize; i++)
|
||||
{
|
||||
test(ArrayGetCell(a, i),i+1);
|
||||
test(ArrayGetCell(a, i), i+1);
|
||||
}
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest11()
|
||||
{
|
||||
server_print("Testing cloning function...");
|
||||
|
||||
new Array:a = ArrayCreate(1);
|
||||
|
||||
ArrayPushCell(a, 42);
|
||||
ArrayPushCell(a, 9);
|
||||
ArrayPushCell(a, -1);
|
||||
ArrayPushCell(a, 0);
|
||||
ArrayPushCell(a, 5);
|
||||
ArrayPushCell(a, 10);
|
||||
ArrayPushCell(a, 15);
|
||||
ArrayPushCell(a, 6.5);
|
||||
|
||||
new Array:b = ArrayClone(a);
|
||||
|
||||
ArrayPushCell(b, 48);
|
||||
ArrayPushCell(b, 3.14);
|
||||
|
||||
test(a, b, TT_NotEqual);
|
||||
test(ArraySize(a), ArraySize(b) - 2);
|
||||
test(ArrayGetCell(b, 0), 42);
|
||||
test(ArrayGetCell(b, 2), -1);
|
||||
test(ArrayGetCell(b, 7), 6.5);
|
||||
test(ArrayGetCell(b, 9), 3.14);
|
||||
|
||||
ArrayDestroy(a);
|
||||
ArrayDestroy(b);
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest12()
|
||||
{
|
||||
server_print("Testing resizing function...");
|
||||
|
||||
new Array:a = ArrayCreate(16);
|
||||
|
||||
ArrayPushString(a, "egg");
|
||||
|
||||
ArrayResize(a, 50);
|
||||
ArrayPushString(a, "boileregg");
|
||||
|
||||
ArraySetString(a, 50, "no more egg v2");
|
||||
|
||||
new buffer[16];
|
||||
ArrayGetString(a, 50, buffer, charsmax(buffer));
|
||||
|
||||
test(ArraySize(a), 50 + 1);
|
||||
test(strcmp(buffer, "no more egg v2"), 0);
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
@ -621,10 +639,67 @@ public arraytest12()
|
||||
|
||||
public arraytest13()
|
||||
{
|
||||
server_print("Testing finding string in array...");
|
||||
|
||||
server_print("Testing cloning function...");
|
||||
|
||||
new Array:a = ArrayCreate(1);
|
||||
|
||||
ArrayPushCell(a, 42);
|
||||
ArrayPushCell(a, 9);
|
||||
ArrayPushCell(a, -1);
|
||||
ArrayPushCell(a, 0);
|
||||
ArrayPushCell(a, 5);
|
||||
ArrayPushCell(a, 10);
|
||||
ArrayPushCell(a, 15);
|
||||
ArrayPushCell(a, 6.5);
|
||||
|
||||
new Array:b = ArrayClone(a);
|
||||
|
||||
ArrayPushCell(b, 48);
|
||||
ArrayPushCell(b, 3.14);
|
||||
|
||||
test(a, b, TT_NotEqual);
|
||||
test(ArraySize(a), ArraySize(b) - 2);
|
||||
test(ArrayGetCell(b, 0), 42);
|
||||
test(ArrayGetCell(b, 2), -1);
|
||||
test(ArrayGetCell(b, 7), 6.5);
|
||||
test(ArrayGetCell(b, 9), 3.14);
|
||||
|
||||
ArrayDestroy(a);
|
||||
ArrayDestroy(b);
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest14()
|
||||
{
|
||||
server_print("Testing resizing function...");
|
||||
|
||||
new Array:a = ArrayCreate(16);
|
||||
|
||||
|
||||
ArrayPushString(a, "egg");
|
||||
|
||||
ArrayResize(a, 50);
|
||||
ArrayPushString(a, "boileregg");
|
||||
|
||||
ArraySetString(a, 50, "no more egg v2");
|
||||
|
||||
new buffer[16];
|
||||
ArrayGetString(a, 50, buffer, charsmax(buffer));
|
||||
|
||||
test(ArraySize(a), 50 + 1);
|
||||
test(strcmp(buffer, "no more egg v2"), 0);
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest15()
|
||||
{
|
||||
server_print("Testing finding string in array...");
|
||||
|
||||
new Array:a = ArrayCreate(16);
|
||||
|
||||
ArrayPushString(a, "z");
|
||||
ArrayPushString(a, "egg");
|
||||
ArrayPushString(a, "boilerplate");
|
||||
@ -632,36 +707,36 @@ public arraytest13()
|
||||
ArrayPushString(a, "something");
|
||||
ArrayPushString(a, "");
|
||||
ArrayPushString(a, "eggeggeggeggeggeggegg");
|
||||
|
||||
|
||||
test(ArrayFindString(a, "egg"), 1);
|
||||
test(ArrayFindString(a, "doh"), -1);
|
||||
test(ArrayFindString(a, "something"), 4);
|
||||
test(ArrayFindString(a, "eggeggeggeggegg"), 6);
|
||||
test(ArrayFindString(a, ""), 5);
|
||||
test(ArrayFindString(a, "zz"), -1);
|
||||
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
showres();
|
||||
}
|
||||
|
||||
public arraytest14()
|
||||
public arraytest16()
|
||||
{
|
||||
server_print("Testing finding value in array...");
|
||||
|
||||
|
||||
new Array:a = ArrayCreate(1);
|
||||
|
||||
|
||||
ArrayPushCell(a, 2);
|
||||
ArrayPushCell(a, 1);
|
||||
ArrayPushCell(a, 5);
|
||||
ArrayPushCell(a, 3.14);
|
||||
ArrayPushCell(a, -1);
|
||||
|
||||
|
||||
test(ArrayFindValue(a, -1), 4);
|
||||
test(ArrayFindValue(a, 2), 0);
|
||||
test(ArrayFindValue(a, 3), -1);
|
||||
test(ArrayFindValue(a, 3.14), 3);
|
||||
|
||||
|
||||
ArrayDestroy(a);
|
||||
|
||||
showres();
|
||||
|
Reference in New Issue
Block a user