summaryrefslogtreecommitdiff
path: root/doc/sample/npc_test_chekweight.txt
blob: 1f4d1d2d8e78f67d59511965ff23244f091665cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//===== rAthena Script =======================================
//= Sample: ChekWeight
//===== By: ==================================================
//= rAthena Dev Team
//===== Current Version: =====================================
//= 20121113
//===== Description: ========================================= 
//= Demonstrates ChekWeight commands.
//============================================================

new_1-1,56,106,5	script	ChkSpace	763,{

function ChkResult;
function FinalReport;

L_RESET:
	resetlvl(1);
	getinventorylist; 
	for(set .@i,0; .@i < @inventorylist_count; set .@i,.@i+1){	
		delitem(@inventorylist_id[.@i],@inventorylist_amount[.@i]); //clear inventory
	}
	

L_TEST1: //basic backward chk
	.@testid = 0;
	.@succes = 0;
	.@ret = checkweight(512,10);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success
	.@ret =	checkweight("Apple",10);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success
	.@ret = checkweight(6320,33000);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure too many item amount item weight=0
	.@ret = checkweight("Premium_Reset_Stone",33000);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure too many item amount
	.@ret = checkweight(717,500);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success weight based on max weight=2030
	.@ret = checkweight(717,1000);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure weight based on max weight=2030
	.@ret = checkweight(2794,100);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success
	.@ret = checkweight(2794,101);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure (with MAX_INVENTORY = 100)
	.@ret = checkweight(-1,1);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure invalide item id
	.@ret = checkweight(512,0);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure invalide amount

	debugmes "End backward test";
	FinalReport(.@testid,.@succes);


L_TEST2: //update using list test
	.@testid = 0;
	.@succes = 0;

	.@ret = checkweight(512,10,513,10);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success
	.@ret =	checkweight("Apple",10,"Banana",10);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success
	.@ret = checkweight(512,80,513,33000);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure
	.@ret = checkweight("Apple",80,"Banana",33000);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure too many item amount
	.@ret = checkweight("Apple",10,"Banana",21,512);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure invalid nb of args
	.@ret = checkweight(717,500,716,100);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be succes weight 1800/2030
	.@ret = checkweight(717,500,716,500);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure weight 3000/2030
	.@ret = checkweight(2794,95,2795,5);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success 
	.@ret = checkweight(2794,95,2795,10);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure (with MAX_INVENTORY = 100)
	.@ret = checkweight(512,1,-1,1);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure invalide item id
	.@ret = checkweight(512,1,513,0);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure invalide amount
	.@ret = checkweight(6320,31000,6320,2000);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure overamount inventory
	.@ret = checkweight(512,1,513,1,514,1,515,1);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be sucess
	
	debugmes "End update by list tests";
	FinalReport(.@testid,.@succes);

L_TEST3: //update using array tests
	.@testid = 0;
	.@succes = 0;

	setarray .@item[0], 512,513,514,515;
        setarray .@count[0], 1,5,9,12;
	.@ret = checkweight2(.@item,.@count);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be sucess
	cleararray .@item[0], 0, 4;
	cleararray .@count[0], 0, 4;
	setarray .@item[0], 512,513,514,515;
        setarray .@count[0], 1,5,-1,12;
	.@ret = checkweight2(.@item,.@count);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, invalide amout
	cleararray .@item[0], 0, 4;
	cleararray .@count[0], 0, 4;
	setarray .@item[0], 512,513,514,-1;
        setarray .@count[0], 1,5,15,12;
	.@ret = checkweight2(.@item,.@count);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, invalide id
	cleararray .@item[0], 0, 4;
	cleararray .@count[0], 0, 4;
	setarray .@item[0], 717,715,716,714;
        setarray .@count[0], 300,300,300,300;
	.@ret = checkweight2(.@item,.@count);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, total by weight
	cleararray .@item[0], 0, 4;
	cleararray .@count[0], 0, 4;
	setarray .@item[0], 6320,6320;
        setarray .@count[0], 31000,2000;
	.@ret = checkweight2(.@item,.@count);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, total by weight
	cleararray .@item[0], 0, 2;
	cleararray .@count[0], 0, 2;
	setarray .@item[0], 2794,2795;
        setarray .@count[0], 95,5;
	.@ret = checkweight2(.@item,.@count);
	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success
        setarray .@count[0], 95,10;
	.@ret = checkweight2(.@item,.@count);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure overamount item
	cleararray .@item[0], 0, 2;
	cleararray .@count[0], 0, 2;
	setarray .@item[0], 6320,6320,512;
        setarray .@count[0], 1,3;
	.@ret = checkweight2(.@item,.@count);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, size mistmatch
	cleararray .@item[0], 0, 3;
	cleararray .@count[0], 0, 2;
	setarray .@item[0], 6320,6320;
        setarray .@count[0], 1,3,5;
	.@ret = checkweight2(.@item,.@count);
	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, size mistmatch		


	debugmes "End update by array tests";
	FinalReport(.@testid,.@succes);

L_FINAL:
	end;
	

	function ChkResult {
		.@tid = getarg(0);
		.@expected = getarg(1);
		.@ret = getarg(2);
		.@sucess = (.@ret==.@expected);
		debugmes "Test "+.@tid+" = "+(.@sucess?"Sucess":"Fail");
		return .@sucess;
	}

	function FinalReport {
		.@tdone = getarg(0);
		.@succes = getarg(1);
		debugmes "Results = Pass : "+.@succes+"/"+.@tdone+" Fails : "+(.@tdone-.@succes)+"/"+.@tdone;
		if(.@succes != .@tdone) { debugmes "Some failure as occured, enable chkresult print to found out"; }
		return;
	}
}