def test_ignored(self): poly = BinaryPolynomial({'a': 4, 'b': 2}, 'SPIN') poly.normalize(bias_range=1, poly_range=None, ignored_terms=['a']) self.assertEqual(poly['a'], 4) # should not be scaled or used in calcs self.assertEqual(poly['b'], 1) # should be normalized correctly
def test_typical(self): poly = BinaryPolynomial({'a': 1, 'ab': 1, '': 1}, 'BINARY') poly.normalize(.5) self.assertEqual(poly['a'], .5) self.assertEqual(poly['ba'], .5) self.assertEqual(poly[tuple()], .5)
def test_int_division(self): # we use division which previous caused issues in python2 poly = BinaryPolynomial({'a': 4}, 'SPIN') poly.normalize(bias_range=1, poly_range=None, ignored_terms=[]) self.assertEqual(poly['a'], 1)
def test_empty(self): poly = BinaryPolynomial({}, 'SPIN') poly.normalize()