Example #1
0
def test_insertion_indices_p_none(mock_fn, sampler):
    """Test computing the distribution of insertion indices if p is None"""
    sampler.rolling_p = []
    sampler.insertion_indices = \
        np.random.randint(sampler.nlive, size=2 * sampler.nlive)

    NestedSampler.check_insertion_indices(sampler, rolling=True)

    assert len(sampler.rolling_p) == 0
Example #2
0
def test_insertion_indices_save(mock_fn, mock_save, filename, sampler):
    """Test saving the insertion indices"""
    sampler.output = './'
    sampler.insertion_indices = \
        np.random.randint(sampler.nlive, size=2 * sampler.nlive)

    NestedSampler.check_insertion_indices(sampler,
                                          rolling=False,
                                          filename=filename)

    if filename:
        mock_save.assert_called_once_with('./file.txt',
                                          sampler.insertion_indices,
                                          newline='\n',
                                          delimiter=' ')
Example #3
0
def test_insertion_indices(mock_fn, rolling, sampler):
    """Test computing the distribution of insertion indices"""
    sampler.rolling_p = []
    sampler.insertion_indices = \
        np.random.randint(sampler.nlive, size=2 * sampler.nlive)

    NestedSampler.check_insertion_indices(sampler, rolling=rolling)

    if rolling:
        assert len(sampler.rolling_p) == 1
        np.testing.assert_array_equal(
            mock_fn.call_args_list[0][0][0],
            sampler.insertion_indices[-sampler.nlive:])
    else:
        mock_fn.assert_called_once_with(sampler.insertion_indices,
                                        sampler.nlive)