[Half-Life AMXX] / testsuite / sorttest.sma Repository:
ViewVC logotype

Annotation of /testsuite/sorttest.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : ian 1 #include <amxmodx>
2 :    
3 :     public plugin_init()
4 :     {
5 :     register_plugin("Sort Test", "1.0", "BAILOPAN")
6 :    
7 :     register_srvcmd("test_sort_ints", "Command_TestSortInts")
8 :     register_srvcmd("test_sort_floats", "Command_TestSortFloats")
9 :     register_srvcmd("test_sort_strings", "Command_TestSortStrings")
10 :     register_srvcmd("test_sort_1d", "Command_TestSort1D")
11 :     register_srvcmd("test_sort_2d", "Command_TestSort2D")
12 :     }
13 :    
14 :     /*****************
15 :     * INTEGER TESTS *
16 :     *****************/
17 :     // Note that integer comparison is just int1-int2 (or a variation therein)
18 :    
19 :     PrintIntegers(const array[], size)
20 :     {
21 :     for (new i=0; i<size; i++)
22 :     {
23 :     server_print("array[%d] = %d", i, array[i])
24 :     }
25 :     }
26 :    
27 :     public Command_TestSortInts()
28 :     {
29 :     new array[10] = {6, 7, 3, 2, 8, 5, 0, 1, 4, 9}
30 :    
31 :     server_print("Testing ascending sort:")
32 :     SortIntegers(array, 10, Sort_Ascending)
33 :     PrintIntegers(array, 10)
34 :    
35 :     server_print("Testing descending sort:")
36 :     SortIntegers(array, 10, Sort_Descending)
37 :     PrintIntegers(array, 10)
38 :     }
39 :    
40 :     /**************************
41 :     * Float comparison tests *
42 :     **************************/
43 :    
44 :     PrintFloats(const Float:array[], size)
45 :     {
46 :     for (new i=0; i<size; i++)
47 :     {
48 :     server_print("array[%d] = %f", i, array[i])
49 :     }
50 :     }
51 :    
52 :     public Command_TestSortFloats()
53 :     {
54 :     new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
55 :    
56 :     server_print("Testing ascending sort:")
57 :     SortFloats(array, 10, Sort_Ascending)
58 :     PrintFloats(array, 10)
59 :    
60 :     server_print("Testing descending sort:")
61 :     SortFloats(array, 10, Sort_Descending)
62 :     PrintFloats(array, 10)
63 :    
64 :     return PLUGIN_HANDLED
65 :     }
66 :    
67 :     public Custom1DSort(Float:elem1, Float:elem2)
68 :     {
69 :     if (elem1 > elem2)
70 :     {
71 :     return -1;
72 :     } else if (elem1 < elem2) {
73 :     return 1;
74 :     }
75 :    
76 :     return 0;
77 :     }
78 :    
79 :     public Command_TestSort1D()
80 :     {
81 :     new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
82 :    
83 :     SortCustom1D(_:array, 10, "Custom1DSort")
84 :     PrintFloats(array, 10)
85 :    
86 :     return PLUGIN_HANDLED
87 :     }
88 :    
89 :     /***************************
90 :     * String comparison tests *
91 :     ***************************/
92 :    
93 :     PrintStrings(const array[][], size)
94 :     {
95 :     for (new i=0; i<size; i++)
96 :     {
97 :     server_print("array[%d] = %s", i, array[i])
98 :     }
99 :     }
100 :    
101 :     public Command_TestSortStrings()
102 :     {
103 :     new array[][] =
104 :     {
105 :     "faluco",
106 :     "bailopan",
107 :     "pm onoto",
108 :     "damaged soul",
109 :     "sniperbeamer",
110 :     "sidluke",
111 :     "johnny got his gun",
112 :     "gabe newell",
113 :     "hello",
114 :     "WHAT?!"
115 :     }
116 :    
117 :     server_print("Testing ascending sort:")
118 :     SortStrings(array, 10, Sort_Ascending)
119 :     PrintStrings(array, 10)
120 :    
121 :     server_print("Testing descending sort:")
122 :     SortStrings(array, 10, Sort_Descending)
123 :     PrintStrings(array, 10)
124 :    
125 :     return PLUGIN_HANDLED
126 :     }
127 :    
128 :     public Custom2DSort(const elem1[], const elem2[])
129 :     {
130 :     return strcmp(elem1, elem2)
131 :     }
132 :    
133 :     public Command_TestSort2D()
134 :     {
135 :     new array[][] =
136 :     {
137 :     "faluco",
138 :     "bailopan",
139 :     "pm onoto",
140 :     "damaged soul",
141 :     "sniperbeamer",
142 :     "sidluke",
143 :     "johnny got his gun",
144 :     "gabe newell",
145 :     "hello",
146 :     "WHAT?!"
147 :     }
148 :    
149 :     SortCustom2D(array, 10, "Custom2DSort")
150 :     PrintStrings(array, 10)
151 :    
152 :     return PLUGIN_HANDLED
153 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4