def test_wrong_term_length(self): """Test exception raised for wrong terms""" with pytest.raises(BoseHubbardError): H = bose_hubbard(2, 2, 1, 0.1, 0.2) H -= BosonOperator('5^ 5 5^') H += BosonOperator('5^ 5') extract_onsite_chemical(H)
def test_differing_onsite(self): """Test exception raised for differing coefficients""" with pytest.raises(BoseHubbardError): H = bose_hubbard(2, 2, 1, 0.1, 0.2) H -= BosonOperator('5^ 5 5^ 5') H += BosonOperator('5^ 5') extract_onsite_chemical(H)
def test_incorrect_ladders(self): """Test exception raised for wrong ladder operators""" with pytest.raises(BoseHubbardError): H = bose_hubbard(2, 2, 1, 0.1, 0.2) H -= BosonOperator('5^ 5^ 5^ 5^') H -= BosonOperator('5 5^ 5 5^') extract_onsite_chemical(H)
def test_differing_chemical_potential(self): """Test exception raised for differing coefficients""" self.logTestName() with self.assertRaises(BoseHubbardError): H = bose_hubbard(2, 2, 1, 0.1, 0.2) H -= BosonOperator('5^ 5') extract_onsite_chemical(H)
def test_too_many_terms(self): """Test exception raised for wrong number of terms""" with pytest.raises(BoseHubbardError): H = bose_hubbard(2, 2, 1, 0.1, 0.2) H -= BosonOperator('0^ 0^ 0^ 0^') extract_onsite_chemical(H) with pytest.raises(BoseHubbardError): H = bose_hubbard(2, 2, 1, 0.1, 0.2) H -= BosonOperator('5^ 5 5^ 5') extract_onsite_chemical(H)
def test_both(self): """Test case where there is non-zero mu and non-zero U""" self.logTestName() H = bose_hubbard(2, 2, 1, 0.1, 0.2) res = extract_onsite_chemical(H) expected = ([[0, 1, 2, 3], 0.1], [[0, 1, 2, 3], 0.2]) self.assertEqual(res, expected)
def test_both(self): """Test case where there is non-zero mu and non-zero U""" H = bose_hubbard(2, 2, 1, 0.1, 0.2) res = extract_onsite_chemical(H) expected = ([[0, 1, 2, 3], 0.1], [[0, 1, 2, 3], 0.2]) assert res == expected
def test_only_chemical_potential(self): """Test case where there is non-zero mu and zero U""" H = bose_hubbard(2, 2, 1, 0, 0.2) res = extract_onsite_chemical(H) expected = ([], [[0, 1, 2, 3], 0.2]) assert res == expected
def test_only_onsite(self): """Test case where there is zero mu and non-zero U""" H = bose_hubbard(2, 2, 1, 0.1, 0) res = extract_onsite_chemical(H) expected = ([[0, 1, 2, 3], 0.1], []) self.assertEqual(res, expected)