Exemple #1
0
 def test_high_photon(self):
     """Test if function raises a ``ValueError`` if ``photon_number`` is so high that it
     cannot correspond to a sample given the constraints of ``max_count_per_mode`` and
     ``modes``"""
     with pytest.raises(ValueError,
                        match="No valid samples can be generated."):
         similarity.event_to_sample(5, 1, 4)
Exemple #2
0
 def test_sample_max_count_deterministic(self, photon_num, count,
                                         monkeypatch):
     """Test if function correctly stops adding photons to modes who have reached their
     maximum count. This test ensures that the maximum count is exceeded in each case by
     setting ``photon_num > count`` and monkeypatching the random choice to always pick the
     first element of a list. This should cause the first mode to fill up with ``count``
     photons."""
     modes_dim = 10
     with monkeypatch.context() as m:
         m.setattr("numpy.random.choice", lambda x: x[0])
         samp = similarity.event_to_sample(photon_num, count, modes_dim)
     assert samp[0] == count
Exemple #3
0
 def test_sample_max_count(self, photon_num, modes_dim, count):
     """Test if function returns a sample that has maximum element not exceeding ``count``."""
     samp = similarity.event_to_sample(photon_num, count, modes_dim)
     assert max(samp) <= count
Exemple #4
0
 def test_sample_sum(self, photon_num, modes_dim, count):
     """Test if function returns a sample that has the correct number of photons."""
     samp = similarity.event_to_sample(photon_num, count, modes_dim)
     assert sum(samp) == photon_num
Exemple #5
0
 def test_sample_length(self, photon_num, modes_dim, count):
     """Test if function returns a sample that is of correct length ``modes_dim``."""
     samp = similarity.event_to_sample(photon_num, count, modes_dim)
     assert len(samp) == modes_dim
Exemple #6
0
 def test_low_count(self):
     """Test if function raises a ``ValueError`` if ``max_count_per_mode`` is negative."""
     with pytest.raises(ValueError, match="Maximum number of photons"):
         similarity.event_to_sample(2, -1, 5)