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

Code before:
        """
        Create fixed locator with 5 nbins, and change it to something else.
        See if change was successful.
        Should not exception.
        """
        fixed = mticker.FixedLocator(range(0, 24), nbins=5)
        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.

Review comment (suggestion):
```suggestion
```
We don't need to reference (clutter) issues in code. This would also not be there if we had written the correct logic and test in the first place. Via git blame and Github, you can always reconstruct the PR and associated issue if needed.

Code after:
        """
        Create fixed locator with 5 nbins, and change it to something else.
        See if change was successful.
        Should not exception.
        """
        fixed = mticker.FixedLocator(range(0, 24), nbins=5)
        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