예제 #1
0
 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
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 def test_empty(self):
     poly = BinaryPolynomial({}, 'SPIN')
     poly.normalize()