Introduce API to create Stack structures
This commit is contained in:
73
plugins/testsuite/stacktest.sma
Normal file
73
plugins/testsuite/stacktest.sma
Normal file
@ -0,0 +1,73 @@
|
||||
#include <amxmodx>
|
||||
|
||||
new FailCount;
|
||||
new PassCount;
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Stack Tests", AMXX_VERSION_STR, "AMXX Dev Team");
|
||||
register_srvcmd("test_stack", "ServerCommand_TestStack");
|
||||
}
|
||||
|
||||
assertEqual(const testname[], bool:pass)
|
||||
{
|
||||
if (!pass)
|
||||
{
|
||||
server_print("[FAIL] %s", testname);
|
||||
FailCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
server_print("[PASS] %s", testname);
|
||||
PassCount++;
|
||||
}
|
||||
}
|
||||
|
||||
done()
|
||||
{
|
||||
server_print("Finished. %d tests, %d failed", FailCount + PassCount, FailCount);
|
||||
}
|
||||
|
||||
public ServerCommand_TestStack()
|
||||
{
|
||||
new Stack:stack;
|
||||
new test[20];
|
||||
new buffer[42];
|
||||
|
||||
test[0] = 5;
|
||||
test[1] = 7;
|
||||
|
||||
stack = CreateStack(30);
|
||||
{
|
||||
PushStackCell(stack, 50);
|
||||
PushStackArray(stack, test, 2);
|
||||
PushStackArray(stack, test, 2);
|
||||
PushStackString(stack, "space craaab");
|
||||
PushStackCell(stack, 12);
|
||||
}
|
||||
|
||||
assertEqual("Size test #1", IsStackEmpty(stack) == false);
|
||||
|
||||
PopStack(stack);
|
||||
PopStackString(stack, buffer, charsmax(buffer));
|
||||
assertEqual("String test", bool:equal(buffer, "space craaab"));
|
||||
|
||||
test[0] = 0;
|
||||
test[1] = 0;
|
||||
assertEqual("Array test #1", test[0] == 0 && test[1] == 0);
|
||||
|
||||
PopStackArray(stack, test, 2);
|
||||
assertEqual("Array test #1", test[0] == 5 && test[1] == 7);
|
||||
|
||||
PopStackCell(stack, test[0], 1);
|
||||
assertEqual("Value test #1", test[0] == 7);
|
||||
|
||||
PopStackCell(stack, test[0]);
|
||||
assertEqual("Value test #2", test[0] == 50);
|
||||
|
||||
assertEqual("Size test #2", IsStackEmpty(stack) == true);
|
||||
|
||||
DestroyStack(stack);
|
||||
|
||||
done();
|
||||
}
|
Reference in New Issue
Block a user