Skip to content

Commit a7025b6

Browse files
committed
content: L24.P1: make feedback messages more precise and descriptive
1 parent 58672a1 commit a7025b6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

course/lesson-25-creating-dictionaries/creating-inventory/TestInventory.gd

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,36 @@ func _prepare() -> void:
1313

1414

1515
func test_inventory_has_correct_keys():
16-
var source: Dictionary = inventory.get("inventory")
17-
16+
var source: Dictionary = inventory.get("inventory")
17+
1818
if source.size() != desired_inventory.size():
1919
return tr(
20-
"The amount of items is not correct. Are you missing any or add to many?"
21-
)
22-
20+
"The amount of items is not as expected. The inventory should have %s items but your inventory has %s."
21+
) % [desired_inventory.size(), source.size()] + " " +\
22+
tr("Are you missing any items?")
23+
2324
var inventories_match := desired_inventory.has_all(source.keys())
2425
if inventories_match:
2526
return ""
2627

2728
return tr(
28-
"The item names aren't correct. Are you missing any?"
29-
)
29+
"The inventory doesn't contain all the required items. Make sure you have '%s' as keys in your inventory dictionary."
30+
) % PoolStringArray(desired_inventory.keys()).join("', '")
3031

3132
return ""
3233

3334

3435
func test_inventory_has_correct_values():
3536
var source: Dictionary = inventory.get("inventory")
36-
var inventories_match := desired_inventory.has_all(source.keys())
37+
var inventories_match := desired_inventory.size() == source.size() and desired_inventory.has_all(source.keys())
3738
if inventories_match:
3839
for key in source.keys():
3940
if not desired_inventory[key] == source[key]:
4041
inventories_match = false
4142
break
42-
43-
if not inventories_match:
43+
else:
4444
return tr(
45-
"The amount of items isn't correct. Does each key have the correct value?"
46-
)
45+
"The values for one or more items aren't correct. You need %s healing hearts, %s gems, and %s sword."
46+
) % [desired_inventory["healing heart"], desired_inventory["gems"], desired_inventory["sword"]]
4747

4848
return ""

0 commit comments

Comments
 (0)