docstr: Test that measurements of hamiltonian/ sparse hamiltonian/ hermitians work correctly.
docstr_tok: ["Test","that","measurements","of","hamiltonian\/","sparse","hamiltonian\/","hermitians","work","correctly","."]
code: def test_hamiltonian_expval(self, obs, expected):
      """Test that measurements of hamiltonian/ sparse hamiltonian/ hermitians work correctly."""
      # Create RX(0.123)|0> state
      state = np.array([np.cos(0.123 / 2), -1j * np.sin(0.123 / 2)])
      res = measure(qml.expval(obs), state)
      assert np.allclose(res, expected)
  
imports: import pytest
  import numpy
  from scipy.sparse import csr_matrix
  import pennylane
  from pennylane.devices.qubit import simulate
  from pennylane.devices.qubit.measure import measure, state_diagonalizing_gates, csr_dot_products, full_dot_products, get_measurement_function, sum_of_terms_method
label_desc: Use image node_id 2 for calling the TestMeasurements obj's underlying member method code with example usage: obj.test_hamiltonian_expval(obs, expected) without return types