@@ -11,45 +11,43 @@ func TestEffectString_GetKey(t *testing.T) {
1111
1212func TestEffectString_Check (t * testing.T ) {
1313 tests := []struct {
14- name string
15- stateVal string
16- effectKey StateKey
17- effectVal string
18- operator arithmetic
19- want bool
14+ name string
15+ stateVal string
16+ effectKey StateKey
17+ effectVal string
18+ operator arithmetic
19+ want bool
2020 }{
2121 {
22- name : "SET match" ,
23- stateVal : "hello" ,
24- effectKey : 1 ,
25- effectVal : "hello" ,
26- operator : SET ,
27- want : true ,
22+ name : "SET match" ,
23+ stateVal : "hello" ,
24+ effectKey : 1 ,
25+ effectVal : "hello" ,
26+ operator : SET ,
27+ want : true ,
2828 },
2929 {
30- name : "SET no match" ,
31- stateVal : "hello" ,
32- effectKey : 1 ,
33- effectVal : "world" ,
34- operator : SET ,
35- want : false ,
30+ name : "SET no match" ,
31+ stateVal : "hello" ,
32+ effectKey : 1 ,
33+ effectVal : "world" ,
34+ operator : SET ,
35+ want : false ,
3636 },
3737 {
38- name : "key not found" ,
39- stateVal : "hello" ,
40- effectKey : 99 ,
41- effectVal : "test" ,
42- operator : SET ,
43- want : false ,
38+ name : "key not found" ,
39+ stateVal : "hello" ,
40+ effectKey : 99 ,
41+ effectVal : "test" ,
42+ operator : SET ,
43+ want : false ,
4444 },
4545 }
4646
4747 for _ , tt := range tests {
4848 t .Run (tt .name , func (t * testing.T ) {
4949 agent := CreateAgent (Goals {}, Actions {})
50- if tt .effectKey == tt .effectKey { // Only set state if key matches
51- SetState [string ](& agent , 1 , tt .stateVal )
52- }
50+ SetState [string ](& agent , 1 , tt .stateVal )
5351
5452 effect := EffectString {Key : tt .effectKey , Value : tt .effectVal , Operator : tt .operator }
5553 got := effect .check (agent .w )
@@ -183,24 +181,24 @@ func TestEffectBool_GetKey(t *testing.T) {
183181
184182func TestEffectBool_Apply_Errors (t * testing.T ) {
185183 tests := []struct {
186- name string
187- operator arithmetic
188- wantErr bool
184+ name string
185+ operator arithmetic
186+ wantErr bool
189187 }{
190188 {
191- name : "SET allowed" ,
192- operator : SET ,
193- wantErr : false ,
189+ name : "SET allowed" ,
190+ operator : SET ,
191+ wantErr : false ,
194192 },
195193 {
196- name : "ADD not allowed" ,
197- operator : ADD ,
198- wantErr : true ,
194+ name : "ADD not allowed" ,
195+ operator : ADD ,
196+ wantErr : true ,
199197 },
200198 {
201- name : "SUBSTRACT not allowed" ,
202- operator : SUBSTRACT ,
203- wantErr : true ,
199+ name : "SUBSTRACT not allowed" ,
200+ operator : SUBSTRACT ,
201+ wantErr : true ,
204202 },
205203 }
206204
@@ -224,70 +222,80 @@ func TestEffectBool_Apply_Errors(t *testing.T) {
224222
225223func TestEffect_Apply_AllOperators (t * testing.T ) {
226224 tests := []struct {
227- name string
228- initial int
229- operator arithmetic
230- value int
231- wantVal int
232- wantErr bool
225+ key StateKey
226+ name string
227+ initial int
228+ operator arithmetic
229+ value int
230+ wantVal int
231+ wantErr bool
233232 }{
234233 {
234+ key : 1 ,
235235 name : "SET" ,
236236 initial : 100 ,
237237 operator : SET ,
238238 value : 50 ,
239239 wantVal : 50 ,
240240 },
241241 {
242+ key : 1 ,
242243 name : "ADD" ,
243244 initial : 100 ,
244245 operator : ADD ,
245246 value : 50 ,
246247 wantVal : 150 ,
247248 },
248249 {
250+ key : 1 ,
249251 name : "SUBSTRACT" ,
250252 initial : 100 ,
251253 operator : SUBSTRACT ,
252254 value : 30 ,
253255 wantVal : 70 ,
254256 },
255257 {
258+ key : 1 ,
256259 name : "MULTIPLY" ,
257260 initial : 10 ,
258261 operator : MULTIPLY ,
259262 value : 5 ,
260263 wantVal : 50 ,
261264 },
262265 {
266+ key : 1 ,
263267 name : "DIVIDE" ,
264268 initial : 100 ,
265269 operator : DIVIDE ,
266270 value : 4 ,
267271 wantVal : 25 ,
268272 },
269273 {
274+ key : 1 ,
270275 name : "ADD on non-existing key" ,
271276 initial : 0 , // Not set
272277 operator : ADD ,
273278 value : 50 ,
274279 wantVal : 50 ,
275280 },
276281 {
282+ key : 1 ,
277283 name : "SUBSTRACT on non-existing key" ,
278284 initial : 0 , // Not set
279285 operator : SUBSTRACT ,
280286 value : 50 ,
281287 wantVal : - 50 ,
282288 },
283289 {
290+ key : 99 ,
284291 name : "MULTIPLY on non-existing key error" ,
285292 initial : 0 , // Not set
286293 operator : MULTIPLY ,
287294 value : 50 ,
288295 wantErr : true ,
289296 },
290297 {
298+ key : 99 ,
291299 name : "DIVIDE on non-existing key error" ,
292300 initial : 0 , // Not set
293301 operator : DIVIDE ,
@@ -299,11 +307,9 @@ func TestEffect_Apply_AllOperators(t *testing.T) {
299307 for _ , tt := range tests {
300308 t .Run (tt .name , func (t * testing.T ) {
301309 agent := CreateAgent (Goals {}, Actions {})
302- if tt .initial != 0 || (tt .operator != ADD && tt .operator != SUBSTRACT && tt .operator != MULTIPLY && tt .operator != DIVIDE ) {
303- SetState [int ](& agent , 1 , tt .initial )
304- }
310+ SetState [int ](& agent , 1 , tt .initial )
305311
306- effect := Effect [int ]{Key : 1 , Value : tt .value , Operator : tt .operator }
312+ effect := Effect [int ]{Key : tt . key , Value : tt .value , Operator : tt .operator }
307313 err := effect .apply (& agent .w )
308314
309315 if tt .wantErr {
0 commit comments