コード例 #1
0
    def test_caller_is_not_full(self):
        """Test checking equivalence when the caller is not full."""
        partially_filled = TruthTable('A xor B', fill_all=False)
        partially_filled.fill(A=0)

        with self.assertRaises(RequiresFullTableError):
            partially_filled.equivalent_to('B xor A')
コード例 #2
0
ファイル: _helpers.py プロジェクト: GDApsy/tt
    def helper_test_truth_table_fill_raises(self,
                                            expr,
                                            expected_exc_type=None,
                                            **kwargs):
        """Helper for testing exception conditions when filling a table.

        :param expr: The value to pass to the ``TruthTable`` constructor.
        :type expr: BooleanExpression or str

        :param expected_exc_type: The exception type expected to be raised.
        :type expected_exc_type: Exception

        :param kwargs: Keyword args to pass to the ``TruthTable`` constructor.

        """
        did_catch = False

        try:
            t = TruthTable(expr, fill_all=False)
            t.fill(**kwargs)
        except expected_exc_type as e:
            did_catch = True
        except Exception as e:
            traceback.print_exc()
            self.fail('Received exception of type ' + type(e).__name__ +
                      ' but was expecting type ' + expected_exc_type.__name__ +
                      '.')
            did_catch = True

        if not did_catch:
            self.fail('No exception thrown.')
コード例 #3
0
 def test_attempt_to_fill_table_already_iteratively_filled(self):
     """Ensure that we cannot fill a table already iteratively filled."""
     t = TruthTable('A nand B', fill_all=False)
     t.fill(A=0)
     t.fill(A=1)
     with self.assertRaises(AlreadyFullTableError):
         t.fill(A=0)
コード例 #4
0
    def test_other_is_not_full(self):
        """Test checking equivalence when the argument table is not full."""
        full_table = TruthTable('A or B')
        partially_filled = TruthTable('A or B', fill_all=False)
        partially_filled.fill(B=1)

        with self.assertRaises(RequiresFullTableError):
            full_table.equivalent_to(partially_filled)
コード例 #5
0
ファイル: test_truth_table_is_full.py プロジェクト: GDApsy/tt
 def test_is_full_iterative(self):
     """Test is_full attr when table is iteratively filled."""
     t = TruthTable('A nand B xor C', fill_all=False)
     self.assertFalse(t.is_full)
     t.fill(A=0)
     self.assertFalse(t.is_full)
     t.fill(B=1)
     self.assertFalse(t.is_full)
     t.fill(C=0)
     self.assertFalse(t.is_full)
     t.fill(B=0)
     self.assertTrue(t.is_full)
コード例 #6
0
    def test_table_iter_partially_filled(self):
        """Test iterating through a table that is partially filled."""
        t = TruthTable('A xor C', fill_all=False)
        t.fill(C=1)
        count = 0

        for inputs, result in t:
            if count == 0:
                self.assertEqual(inputs.A, False)
                self.assertEqual(inputs.C, True)
                self.assertEqual(result, True)
            elif count == 1:
                self.assertEqual(inputs.A, True)
                self.assertEqual(inputs.C, True)
                self.assertEqual(result, False)

            count += 1

        self.assertEqual(count, 2)
コード例 #7
0
    def test_table_getitem(self):
        """Test indexing the table to get its results."""
        t = TruthTable('A or B', fill_all=False)
        for i in range(4):
            self.assertEqual(None, t[i])

        t.fill(A=0)
        self.assertEqual(t[0], False)
        self.assertEqual(t[1], True)

        t.fill()
        self.assertEqual(t[0b00], False)
        self.assertEqual(t[0b01], True)
        self.assertEqual(t[0b10], True)
        self.assertEqual(t[0b11], True)

        t = TruthTable(from_values='1xx1')
        self.assertEqual(t[0b00], True)
        self.assertEqual(t[0b01], 'x')
        self.assertEqual(t[0b10], 'x')
        self.assertEqual(t[0b11], True)
コード例 #8
0
ファイル: _helpers.py プロジェクト: GDApsy/tt
    def helper_test_truth_table_fill(self,
                                     expr,
                                     expected_table_str=None,
                                     init_kwargs={},
                                     **kwargs):
        """Helper to test filling a truth table.

        :param expr: The value to pass to the ``TruthTable`` constructor.
        :type expr: BooleanExpression or str

        :param expected_table_str: The expected string representation of the
            table.
        :type expected_table_str: str

        :param init_kwargs: A dict to pass as the kwargs to the ``TruthTable``
            constructor.
        :type init_kwargs: Dict

        :param kwargs: Keyword args to pass to the fill method.

        """
        t = TruthTable(expr, fill_all=False, **init_kwargs)
        t.fill(**kwargs)
        self.assertEqual(expected_table_str, str(t))
コード例 #9
0
ファイル: test_truth_table_is_full.py プロジェクト: GDApsy/tt
 def test_is_full_from_single_fill_call(self):
     """Test is_full attr when filled via one fill() call."""
     t = TruthTable('A nand B xor C', fill_all=False)
     self.assertFalse(t.is_full)
     t.fill()
     self.assertTrue(t.is_full)
コード例 #10
0
 def test_attempt_to_fill_table_already_filled_on_init_from_expr(self):
     """Ensure that we cannot fill a table already filled from an expr."""
     t = TruthTable('A or B')
     with self.assertRaises(AlreadyFullTableError):
         t.fill(A=0)
コード例 #11
0
 def test_attempt_to_fill_table_already_filled_from_values(self):
     """Ensure that we cannot fill() a table built from specified values."""
     t = TruthTable(from_values='xxxx', ordering=['A', 'B'])
     with self.assertRaises(AlreadyFullTableError):
         t.fill(A=1)