forked from ArchipelagoMW/Archipelago
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: add list/dict merging feature to triggers (ArchipelagoMW#2793)
* proof of concept * add dict support, block top/game level merge * prevent key error when option being merged is new * update triggers guide * Add documentation about add/remove/replace * move to trailing name instead of proper tag * update docs * confirm types * Update Utils.py * Update Generate.py * pep8 * move to + syntax * forgot to support sets * specify received type of type error * Update Generate.py Co-authored-by: Fabian Dill <[email protected]> * Apply suggestion from review * add test for update weights * move test to new test case * Apply suggestions from code review Co-authored-by: black-sliver <[email protected]> --------- Co-authored-by: Fabian Dill <[email protected]> Co-authored-by: black-sliver <[email protected]>
- Loading branch information
Showing
4 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import unittest | ||
import Generate | ||
|
||
|
||
class TestPlayerOptions(unittest.TestCase): | ||
|
||
def test_update_weights(self): | ||
original_weights = { | ||
"scalar_1": 50, | ||
"scalar_2": 25, | ||
"list_1": ["string"], | ||
"dict_1": {"option_a": 50, "option_b": 50}, | ||
"dict_2": {"option_f": 50}, | ||
"set_1": {"option_c"} | ||
} | ||
|
||
# test that we don't allow +merge syntax on scalar variables | ||
with self.assertRaises(BaseException): | ||
Generate.update_weights(original_weights, {"+scalar_1": 0}, "Tested", "") | ||
|
||
new_weights = Generate.update_weights(original_weights, {"scalar_2": 0, | ||
"+list_1": ["string_2"], | ||
"+dict_1": {"option_b": 0, "option_c": 50}, | ||
"+set_1": {"option_c", "option_d"}, | ||
"dict_2": {"option_g": 50}, | ||
"+list_2": ["string_3"]}, | ||
"Tested", "") | ||
|
||
self.assertEqual(new_weights["scalar_1"], 50) | ||
self.assertEqual(new_weights["scalar_2"], 0) | ||
self.assertEqual(new_weights["list_2"], ["string_3"]) | ||
self.assertEqual(new_weights["list_1"], ["string", "string_2"]) | ||
self.assertEqual(new_weights["dict_1"]["option_a"], 50) | ||
self.assertEqual(new_weights["dict_1"]["option_b"], 0) | ||
self.assertEqual(new_weights["dict_1"]["option_c"], 50) | ||
self.assertNotIn("option_f", new_weights["dict_2"]) | ||
self.assertEqual(new_weights["dict_2"]["option_g"], 50) | ||
self.assertEqual(len(new_weights["set_1"]), 2) | ||
self.assertIn("option_d", new_weights["set_1"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters