def test_problem_large(self): problem = Problem(name="test", terms=[], problem_type=ProblemType.pubo) self.assertTrue(not problem.is_large()) problem.add_term(5.0, []) self.assertTrue(not problem.is_large()) problem.add_term(6.0, list(range(3000))) self.assertTrue(not problem.is_large()) problem.add_terms([Term(indices=[9999], c=1.0)] * int(1e6)) # create 1mil dummy terms self.assertTrue(problem.is_large())
def test_add_terms_cterms(self): problem = Problem(name="test") count = 4 for i in range(count): problem.add_term(c=i, indices=[i, i + 1]) self.assertEqual(ProblemType.ising, problem.problem_type) self.assertEqual(count, len(problem.terms)) self.assertEqual(Term(c=1, indices=[1, 2]), problem.terms[1]) more = [] for i in range(count + 1): more.append(Term(c=i, indices=[i, i - 1])) problem.add_terms(more) self.assertEqual((count * 2) + 1, len(problem.terms)) self.assertEqual(Term(c=count, indices=[count, count - 1]), problem.terms[count * 2])