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.
Stardew Valley: simplify in-place (ArchipelagoMW#2393)
this allows skipping multiple simplifications of the same object, e.g. item_rules also update the logic simplification tests to be a proper unittest.TestCase
- Loading branch information
1 parent
9e140f6
commit a64dd4f
Showing
2 changed files
with
67 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,57 @@ | ||
import unittest | ||
from .. import True_ | ||
from ..logic import Received, Has, False_, And, Or | ||
|
||
|
||
def test_simplify_true_in_and(): | ||
rules = { | ||
"Wood": True_(), | ||
"Rock": True_(), | ||
} | ||
summer = Received("Summer", 0, 1) | ||
assert (Has("Wood", rules) & summer & Has("Rock", rules)).simplify() == summer | ||
|
||
|
||
def test_simplify_false_in_or(): | ||
rules = { | ||
"Wood": False_(), | ||
"Rock": False_(), | ||
} | ||
summer = Received("Summer", 0, 1) | ||
assert (Has("Wood", rules) | summer | Has("Rock", rules)).simplify() == summer | ||
|
||
|
||
def test_simplify_and_in_and(): | ||
rule = And(And(Received('Summer', 0, 1), Received('Fall', 0, 1)), | ||
And(Received('Winter', 0, 1), Received('Spring', 0, 1))) | ||
assert rule.simplify() == And(Received('Summer', 0, 1), Received('Fall', 0, 1), Received('Winter', 0, 1), | ||
Received('Spring', 0, 1)) | ||
|
||
|
||
def test_simplify_duplicated_and(): | ||
rule = And(And(Received('Summer', 0, 1), Received('Fall', 0, 1)), | ||
And(Received('Summer', 0, 1), Received('Fall', 0, 1))) | ||
assert rule.simplify() == And(Received('Summer', 0, 1), Received('Fall', 0, 1)) | ||
|
||
|
||
def test_simplify_or_in_or(): | ||
rule = Or(Or(Received('Summer', 0, 1), Received('Fall', 0, 1)), | ||
Or(Received('Winter', 0, 1), Received('Spring', 0, 1))) | ||
assert rule.simplify() == Or(Received('Summer', 0, 1), Received('Fall', 0, 1), Received('Winter', 0, 1), | ||
Received('Spring', 0, 1)) | ||
|
||
|
||
def test_simplify_duplicated_or(): | ||
rule = And(Or(Received('Summer', 0, 1), Received('Fall', 0, 1)), | ||
Or(Received('Summer', 0, 1), Received('Fall', 0, 1))) | ||
assert rule.simplify() == Or(Received('Summer', 0, 1), Received('Fall', 0, 1)) | ||
|
||
|
||
def test_simplify_true_in_or(): | ||
rule = Or(True_(), Received('Summer', 0, 1)) | ||
assert rule.simplify() == True_() | ||
|
||
|
||
def test_simplify_false_in_and(): | ||
rule = And(False_(), Received('Summer', 0, 1)) | ||
assert rule.simplify() == False_() | ||
class TestSimplification(unittest.TestCase): | ||
def test_simplify_true_in_and(self): | ||
rules = { | ||
"Wood": True_(), | ||
"Rock": True_(), | ||
} | ||
summer = Received("Summer", 0, 1) | ||
self.assertEqual((Has("Wood", rules) & summer & Has("Rock", rules)).simplify(), | ||
summer) | ||
|
||
def test_simplify_false_in_or(self): | ||
rules = { | ||
"Wood": False_(), | ||
"Rock": False_(), | ||
} | ||
summer = Received("Summer", 0, 1) | ||
self.assertEqual((Has("Wood", rules) | summer | Has("Rock", rules)).simplify(), | ||
summer) | ||
|
||
def test_simplify_and_in_and(self): | ||
rule = And(And(Received('Summer', 0, 1), Received('Fall', 0, 1)), | ||
And(Received('Winter', 0, 1), Received('Spring', 0, 1))) | ||
self.assertEqual(rule.simplify(), | ||
And(Received('Summer', 0, 1), Received('Fall', 0, 1), | ||
Received('Winter', 0, 1), Received('Spring', 0, 1))) | ||
|
||
def test_simplify_duplicated_and(self): | ||
rule = And(And(Received('Summer', 0, 1), Received('Fall', 0, 1)), | ||
And(Received('Summer', 0, 1), Received('Fall', 0, 1))) | ||
self.assertEqual(rule.simplify(), | ||
And(Received('Summer', 0, 1), Received('Fall', 0, 1))) | ||
|
||
def test_simplify_or_in_or(self): | ||
rule = Or(Or(Received('Summer', 0, 1), Received('Fall', 0, 1)), | ||
Or(Received('Winter', 0, 1), Received('Spring', 0, 1))) | ||
self.assertEqual(rule.simplify(), | ||
Or(Received('Summer', 0, 1), Received('Fall', 0, 1), Received('Winter', 0, 1), | ||
Received('Spring', 0, 1))) | ||
|
||
def test_simplify_duplicated_or(self): | ||
rule = And(Or(Received('Summer', 0, 1), Received('Fall', 0, 1)), | ||
Or(Received('Summer', 0, 1), Received('Fall', 0, 1))) | ||
self.assertEqual(rule.simplify(), | ||
Or(Received('Summer', 0, 1), Received('Fall', 0, 1))) | ||
|
||
def test_simplify_true_in_or(self): | ||
rule = Or(True_(), Received('Summer', 0, 1)) | ||
self.assertEqual(rule.simplify(), True_()) | ||
|
||
def test_simplify_false_in_and(self): | ||
rule = And(False_(), Received('Summer', 0, 1)) | ||
self.assertEqual(rule.simplify(), False_()) |