def test_isStateValid_multiRelation_sameTail_ambiguous(self):
        state1 = {
            "A": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.MINUS))
            },
            "B": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.MINUS))
            },
            "C": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.ZERO))
            },
        }
        state2 = {
            "A": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.MINUS))
            },
            "B": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.ZERO))
            },
            "C": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.ZERO))
            },
        }
        state3 = {
            "A": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.MINUS))
            },
            "B": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.PLUS))
            },
            "C": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.ZERO))
            },
        }
        relations = [
            {
                "type": "EX",
                "args": None,
                "Q1": ("A", "Q"),
                "Q2": ("A", "Q"),
            },
            {
                "type": "P+",
                "args": None,
                "Q1": ("A", "Q"),
                "Q2": ("B", "Q"),
            },
            {
                "type": "I+",
                "args": None,
                "Q1": ("C", "Q"),
                "Q2": ("B", "Q"),
            },
        ]

        self.assertEqual(isStateValid(state1, relations), True)
        self.assertEqual(isStateValid(state2, relations), True)
        self.assertEqual(isStateValid(state3, relations), True)
    def test_isStateValid_multiRelation_valid(self):
        state = {
            "B": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.MINUS))
            },
            "C": {
                "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.MINUS))
            },
        }
        relations = [
            {
                "type": "EX",
                "args": None,
                "Q1": ("B", "Q"),
                "Q2": ("B", "Q"),
            },
            {
                "type": "I-",
                "args": None,
                "Q1": ("C", "Q"),
                "Q2": ("B", "Q"),
            },
            {
                "type": "P+",
                "args": None,
                "Q1": ("B", "Q"),
                "Q2": ("C", "Q"),
            },
        ]

        self.assertEqual(isStateValid(state, relations), True)
 def test_isStateValid_relationOrder(self):
     state = {
         "A": {
             "Q": Quantity(Magnitude(MValue.ZERO), Derivative(DValue.ZERO))
         },
         "B": {
             "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.MINUS))
         },
         "C": {
             "Q": Quantity(Magnitude(MValue.PLUS), Derivative(DValue.ZERO))
         },
     }
     relations = [
         {
             "type": "I+",
             "args": None,
             "Q1": ("A", "Q"),
             "Q2": ("B", "Q"),
         },
         {
             "type": "I-",
             "args": None,
             "Q1": ("C", "Q"),
             "Q2": ("B", "Q"),
         },
         {
             "type": "P+",
             "args": None,
             "Q1": ("B", "Q"),
             "Q2": ("C", "Q"),
         },
     ]
     self.assertEqual(isStateValid(state, relations), False)
    def test_isStateValid_noEX(self):
        state = {
            "A": {
                "Q": Quantity(Magnitude(MValue.ZERO), Derivative(DValue.PLUS))
            }
        }
        relations = []

        self.assertEqual(isStateValid(state, relations), False)
    def test_isStateValid_lower_boundary_derivatives(self):
        state_invalid = {
            "A": {
                "Q": Quantity(Magnitude(MValue.ZERO), Derivative(DValue.MINUS))
            },
        }
        state_valid = {
            "A": {
                "Q": Quantity(Magnitude(MValue.ZERO), Derivative(DValue.PLUS))
            },
        }
        relations = [{
            "type": "EX",
            "args": None,
            "Q1": ("A", "Q"),
            "Q2": ("A", "Q"),
        }]

        self.assertEqual(isStateValid(state_invalid, relations), False)
        self.assertEqual(isStateValid(state_valid, relations), True)
    def test_isStateValid_singleRelation_valid(self):
        state = {
            "B": {
                "Q": Quantity(Magnitude(MValue.ZERO), Derivative(DValue.ZERO))
            },
            "C": {
                "Q": Quantity(Magnitude(MValue.ZERO), Derivative(DValue.ZERO))
            },
        }
        relations = [
            {
                "type": "P+",
                "args": None,
                "Q1": ("B", "Q"),
                "Q2": ("C", "Q"),
            },
        ]

        self.assertEqual(isStateValid(state, relations), True)
 def test_isStateValid_complexValid(self):
     state = {
         "A": {
             "Q": Quantity(Magnitude(0), Derivative(0))
         },
         "B": {
             "Q": Quantity(Magnitude(0), Derivative(0))
         },
         "C": {
             "Q": Quantity(Magnitude(0), Derivative(0))
         },
     }
     relations = [
         {
             "type": "EX",
             "args": 1,
             "Q1": ("A", "Q"),
             "Q2": ("A", "Q"),
         },
         {
             "type": "I+",
             "args": None,
             "Q1": ("A", "Q"),
             "Q2": ("B", "Q"),
         },
         {
             "type": "I-",
             "args": None,
             "Q1": ("C", "Q"),
             "Q2": ("B", "Q"),
         },
         {
             "type": "P+",
             "args": None,
             "Q1": ("B", "Q"),
             "Q2": ("C", "Q"),
         },
         {
             "type": "VC",
             "args": MValue.MAX,
             "Q1": ("B", "Q"),
             "Q2": ("C", "Q"),
         },
         {
             "type": "VC",
             "args": MValue.ZERO,
             "Q1": ("B", "Q"),
             "Q2": ("C", "Q"),
         },
         {
             "type": "VC",
             "args": MValue.MAX,
             "Q1": ("C", "Q"),
             "Q2": ("B", "Q"),
         },
         {
             "type": "VC",
             "args": MValue.ZERO,
             "Q1": ("C", "Q"),
             "Q2": ("B", "Q"),
         },
     ]
     self.assertEqual(isStateValid(state, relations), True)
    def test_isStateValid_no_relations(self):
        state = {}
        relations = []

        self.assertEqual(isStateValid(state, relations), True)