Spaces:
Sleeping
Sleeping
Add test for mask update
Browse files- wordle_env/test_wordle.py +131 -0
wordle_env/test_wordle.py
CHANGED
@@ -290,3 +290,134 @@ def test_special_step_cases(wordleEnv):
|
|
290 |
1, 0, 0,
|
291 |
1, 0, 0)
|
292 |
letter_test('P', new_state, letter_state)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
1, 0, 0,
|
291 |
1, 0, 0)
|
292 |
letter_test('P', new_state, letter_state)
|
293 |
+
|
294 |
+
def test_mask_update(wordleEnv):
|
295 |
+
wordleEnv.reset()
|
296 |
+
wordleEnv.set_goal_encoded(0)
|
297 |
+
|
298 |
+
cur_state = wordleEnv.state
|
299 |
+
#"APPAA"
|
300 |
+
#"APPAB"
|
301 |
+
new_state = state.update_from_mask(cur_state, wordleEnv.words[1], [2, 2, 2, 2, 0])
|
302 |
+
# Expect B to be all 1,0,0
|
303 |
+
letter_test('B', new_state, tuple([1, 0, 0]*5))
|
304 |
+
|
305 |
+
# Expect A to be right in position 0 3, no in 1 2 and 0 otherwise
|
306 |
+
letter_state = (0, 0, 1,
|
307 |
+
1, 0, 0,
|
308 |
+
1, 0, 0,
|
309 |
+
0, 0, 1,
|
310 |
+
0, 0, 0)
|
311 |
+
letter_test('A', new_state, letter_state)
|
312 |
+
|
313 |
+
# Expect P to be right in position 1 2, no in 0 2 and 0 otherwise
|
314 |
+
letter_state = (1, 0, 0,
|
315 |
+
0, 0, 1,
|
316 |
+
0, 0, 1,
|
317 |
+
1, 0, 0,
|
318 |
+
0, 0, 0)
|
319 |
+
letter_test('P', new_state, letter_state)
|
320 |
+
|
321 |
+
# Expect C to be no everywhere except in 4
|
322 |
+
letter_state = (1, 0, 0,
|
323 |
+
1, 0, 0,
|
324 |
+
1, 0, 0,
|
325 |
+
1, 0, 0,
|
326 |
+
0, 0, 0)
|
327 |
+
letter_test('C', new_state, letter_state)
|
328 |
+
# "APPAA",
|
329 |
+
# "APPAB",
|
330 |
+
# "APAPD",
|
331 |
+
new_state = state.update_from_mask(new_state, wordleEnv.words[3], [2, 2, 1, 1, 0])
|
332 |
+
# Expect D to be all 1,0,0
|
333 |
+
letter_state = tuple([1, 0, 0]*5)
|
334 |
+
letter_test('D', new_state, letter_state)
|
335 |
+
|
336 |
+
# Expect A to be right in position 0 3 and Maybe in 4
|
337 |
+
letter_state = (0, 0, 1,
|
338 |
+
1, 0, 0,
|
339 |
+
1, 0, 0,
|
340 |
+
0, 0, 1,
|
341 |
+
0, 1, 0)
|
342 |
+
letter_test('A', new_state, letter_state)
|
343 |
+
|
344 |
+
# Expect P to be right in position 1 2 no in 3 and maybe in 4
|
345 |
+
letter_state = (1, 0, 0,
|
346 |
+
0, 0, 1,
|
347 |
+
0, 0, 1,
|
348 |
+
1, 0, 0,
|
349 |
+
0, 1, 0)
|
350 |
+
letter_test('P', new_state, letter_state)
|
351 |
+
|
352 |
+
wordleEnv.reset()
|
353 |
+
cur_state = wordleEnv.state
|
354 |
+
wordleEnv.set_goal_encoded(4)
|
355 |
+
# BPPAB - goal
|
356 |
+
# PPAPB - 1st guess
|
357 |
+
new_state = state.update_from_mask(cur_state, wordleEnv.words[5], [1, 2, 1, 0, 2])
|
358 |
+
# Expect A to be all maybe except 2, 1 and 4 that are no
|
359 |
+
letter_state = (0, 1, 0,
|
360 |
+
1, 0, 0,
|
361 |
+
1, 0, 0,
|
362 |
+
0, 1, 0,
|
363 |
+
1, 0, 0)
|
364 |
+
letter_test('A', new_state, letter_state)
|
365 |
+
# Expect B to be all 0 except 4 that is yes and 1 that is no
|
366 |
+
letter_state = (0, 0, 0,
|
367 |
+
1, 0, 0,
|
368 |
+
0, 0, 0,
|
369 |
+
0, 0, 0,
|
370 |
+
0, 0, 1)
|
371 |
+
letter_test('B', new_state, letter_state)
|
372 |
+
# Expect P to be yes at 1, maybe at 2 and 4, and no in 0, 3 and 4
|
373 |
+
letter_state = (1, 0, 0,
|
374 |
+
0, 0, 1,
|
375 |
+
0, 1, 0,
|
376 |
+
1, 0, 0,
|
377 |
+
1, 0, 0)
|
378 |
+
letter_test('P', new_state, letter_state)
|
379 |
+
# BPPAB - goal
|
380 |
+
# PPAPB - 1st guess
|
381 |
+
# PPBBA - 2nd guess
|
382 |
+
new_state = state.update_from_mask(new_state, wordleEnv.words[6], [1, 2, 1, 1, 1])
|
383 |
+
# Expect A to be all maybe except 2, 1 and 4 that are no
|
384 |
+
letter_state = (0, 1, 0,
|
385 |
+
1, 0, 0,
|
386 |
+
1, 0, 0,
|
387 |
+
0, 1, 0,
|
388 |
+
1, 0, 0)
|
389 |
+
letter_test('A', new_state, letter_state)
|
390 |
+
# Expect B to be maybe at 0, yes at 4, and 1 2 and 3 are no
|
391 |
+
letter_state = (0, 1, 0,
|
392 |
+
1, 0, 0,
|
393 |
+
1, 0, 0,
|
394 |
+
1, 0, 0,
|
395 |
+
0, 0, 1)
|
396 |
+
letter_test('B', new_state, letter_state)
|
397 |
+
# Expect P to be yes at 1, maybe at 2, and no in 0, 3 and 4
|
398 |
+
letter_state = (1, 0, 0,
|
399 |
+
0, 0, 1,
|
400 |
+
0, 1, 0,
|
401 |
+
1, 0, 0,
|
402 |
+
1, 0, 0)
|
403 |
+
letter_test('P', new_state, letter_state)
|
404 |
+
wordleEnv.reset()
|
405 |
+
wordleEnv.set_goal_encoded(7)
|
406 |
+
# BPABB - goal
|
407 |
+
# PPPAC - 1st guess
|
408 |
+
new_state = state.update_from_mask(new_state, wordleEnv.words[8], [0, 2, 0, 1, 0])
|
409 |
+
new_state, _, _, _ = wordleEnv.step(8)
|
410 |
+
# Expect A to be all maybe except 1 and 3 that is no
|
411 |
+
letter_state = (0, 1, 0,
|
412 |
+
1, 0, 0,
|
413 |
+
0, 1, 0,
|
414 |
+
1, 0, 0,
|
415 |
+
0, 1, 0)
|
416 |
+
letter_test('A', new_state, letter_state)
|
417 |
+
# Expect P to be yes at 1, maybe at 3 and 4 and no otherwise
|
418 |
+
letter_state = (1, 0, 0,
|
419 |
+
0, 0, 1,
|
420 |
+
1, 0, 0,
|
421 |
+
1, 0, 0,
|
422 |
+
1, 0, 0)
|
423 |
+
letter_test('P', new_state, letter_state)
|