def test_eval(self): r30p1 = bt.BooleanFunction([[0], [1], [2], [1, 2], []], 3) self.assertEqual(r30(1, 0, 0), 1) self.assertEqual(r30(0, 0, 0), 0) self.assertEqual(r30p1(0, 0, 0), 1) self.assertEqual(r90(1, 0, 1), 0) self.assertEqual(r90(1, 1, 0), 1)
def test_siegenthaler(self): expected_comb = bt.BooleanFunction( [[0], [1], [2], [1, 2], [1, 3], [1, 2, 3]], 4) got = bt.siegenthaler_combination(r90, r30, x[3]) self.assertEqual(expected_comb, got)
def test_mult(self): prod = bt.BooleanFunction([[0], [2], [0, 1], [0, 1, 2]], 3) self.assertEqual(prod, r30 * r90)
def test_add(self): rule = bt.BooleanFunction([[1], [1, 2]], 3) self.assertEqual(r30 + r90, rule)
import booleantools as bt import unittest r30 = bt.BooleanFunction([[0], [1], [2], [1, 2]], 3) r90 = bt.BooleanFunction([[0], [2]], 3) x = bt.getX(5) class BTUnitTest(unittest.TestCase): def test_hamming_wt(self): self.assertEqual(r30.hamming_weight(), 4) def test_ham_dist(self): self.assertEqual(r30.hamming_distance(r90), 2) self.assertEqual(r30.hamming_distance([r90, r30]), [2, 0]) def test_nonlinearity(self): self.assertEqual(r30.nonlinearity(), 2) self.assertEqual(r90.nonlinearity(), 0) def test_eval(self): r30p1 = bt.BooleanFunction([[0], [1], [2], [1, 2], []], 3) self.assertEqual(r30(1, 0, 0), 1) self.assertEqual(r30(0, 0, 0), 0) self.assertEqual(r30p1(0, 0, 0), 1) self.assertEqual(r90(1, 0, 1), 0) self.assertEqual(r90(1, 1, 0), 1) def test_perm(self): self.assertEqual(r30.apply_permutation([0, 1, 2]), r30)