def test_all_blank_features_yield_non_zero_but_equal_normalized_values(
        norm_order, expected_value):

    intensity_table = intensity_table_factory()

    # zero-out all the values in the IntensityTable
    intensity_table.values = np.zeros(4).reshape(1, 2, 2)
    normed_intensities, norms = Codebook._normalize_features(
        intensity_table, norm_order)

    # todo norms here are zero, which seems like the right answer!
    assert norms == 0

    assert np.all(normed_intensities == expected_value)
def test_normalize_intensities(norm_order, expected_size):
    """
    Create a slightly less simple IntensityTable with one "on" tile per feature,
    we can again calculate the expected value of the norms. Verify
    that the output of the functions correspond to these expectations.
    """
    intensity_table = intensity_table_factory()
    normed_intensities, norms = Codebook._normalize_features(
        intensity_table, norm_order)

    assert np.all(norms == expected_size)

    # each feature should still have only two non-zero values
    assert np.all(
        normed_intensities.groupby(Features.AXIS).apply(
            lambda x: np.sum(x != 0)) == 2)

    # each non-zero value should be equal to 1 / expected_size of the norm.
    assert np.all(normed_intensities == intensity_table / norms)
def test_normalize_codes(norm_order, expected_size):
    """
    Create a simple codebook with two features, each with two "on" sites. For these simple cases,
    we can easily calculate the expected value of the norms. (2-norm: sqrt 2, 1-norm: 2), Verify
    that the output of the functions correspond to these expectations.
    """
    codebook = codebook_factory()
    normed_codebook, norms = Codebook._normalize_features(codebook, norm_order)
    assert np.all(norms == expected_size)

    # each code should still have only two non-zero values
    assert np.all(
        normed_codebook.groupby(Features.TARGET).apply(
            lambda x: np.sum(x != 0)) == 2)

    # each non-zero value should be equal to 1 / expected_size of the norm. There are two non-zero
    # values and so the sum of the code should be (1 / expected_size) * 2
    assert np.all(
        normed_codebook.sum((Axes.CH.value,
                             Axes.ROUND.value)) == (1 / expected_size) * 2)