Repository: matplotlib/matplotlib
File: lib/matplotlib/tests/test_ticker.py (Python)

Code before:
        fixed.set_params(nbins=7)
        assert fixed.nbins == 7


class TestIndexLocator:
    def test_set_params(self):
        """
        Create index locator with 3 base, 4 offset. and change it to something
        else. See if change was successful.
        Should not exception.
        """
        index = mticker.IndexLocator(base=3, offset=4)
        index.set_params(base=7, offset=7)
        assert index._base == 7
        assert index.offset == 7

    def test_tick_values_not_exceeding_vmax(self):
        """
        Test that tick_values does not return values greater than vmax.
        Regression test for issue #31086.
        """
        # Test case where offset=0 could cause vmax to be included incorrectly
        index = mticker.IndexLocator(base=1, offset=0)
        ticks = index.tick_values(0, 4)
        assert all(t <= 4 for t in ticks)
        np.testing.assert_array_equal(ticks, [0, 1, 2, 3, 4])

        # Test case with fractional offset
        index = mticker.IndexLocator(base=1, offset=0.5)
        ticks = index.tick_values(0, 4)
        assert all(t <= 4 for t in ticks)
        np.testing.assert_array_equal(ticks, [0.5, 1.5, 2.5, 3.5])

        # Test case with base > 1
        index = mticker.IndexLocator(base=2, offset=0)
        ticks = index.tick_values(0, 5)
        assert all(t <= 5 for t in ticks)
        np.testing.assert_array_equal(ticks, [0, 2, 4])


class TestSymmetricalLogLocator:
    def test_set_params(self):
        """
        Create symmetrical log locator with default subs =[1.0] numticks = 15,
        and change it to something else.
        See if change was successful.
        Should not exception.
        """
        sym = mticker.SymmetricalLogLocator(base=10, linthresh=1)
        sym.set_params(subs=[2.0], numticks=8)
        assert sym._subs == [2.0]

Review comment (bug):
```suggestion
        assert_array_equal(index.tick_values(0, 4), [0, 1, 2, 3, 4])
```
The t<4 seems specifically motivated by the bug. If anything, we'd need to 0 <= t <= 4. But OTOH, the comparison to the fixed numbers already covers that check. One could argue that the check makes the logic range constraint explicit. But with that argument, one could also argue to check that all numbers are integer, and that they are monotonically increasing, and ...
So I claim the direct comparison with the expected result is sufficient.

Note: `assert_array_equal` is imported at the top, so we can keep this more compact.

Same for the following two tests.

Code after:
        fixed.set_params(nbins=7)
        assert fixed.nbins == 7


class TestIndexLocator:
    def test_set_params(self):
        """
        Create index locator with 3 base, 4 offset. and change it to something
        else. See if change was successful.
        Should not exception.
        """
        index = mticker.IndexLocator(base=3, offset=4)
        index.set_params(base=7, offset=7)
        assert index._base == 7
        assert index.offset == 7

    def test_tick_values_not_exceeding_vmax(self):
        """
        Test that tick_values does not return values greater than vmax.
        """
        # Test case where offset=0 could cause vmax to be included incorrectly
        index = mticker.IndexLocator(base=1, offset=0)
        assert_array_equal(index.tick_values(0, 4), [0, 1, 2, 3, 4])

        # Test case with fractional offset
        index = mticker.IndexLocator(base=1, offset=0.5)
        assert_array_equal(index.tick_values(0, 4), [0.5, 1.5, 2.5, 3.5])

        # Test case with base > 1
        index = mticker.IndexLocator(base=2, offset=0)
        assert_array_equal(index.tick_values(0, 5), [0, 2, 4])


class TestSymmetricalLogLocator:
    def test_set_params(self):
        """
        Create symmetrical log locator with default subs =[1.0] numticks = 15,
        and change it to something else.
        See if change was successful.
        Should not exception.
        """
        sym = mticker.SymmetricalLogLocator(base=10, linthresh=1)
        sym.set_params(subs=[2.0], numticks=8)
        assert sym._subs == [2.0]
        assert sym.numticks == 8

    @pytest.mark.parametrize(
            'vmin, vmax, expected',
            [
                (0, 1, [0, 1]),
                (-1, 1, [-1, 0, 1]),