Repository: numpy/numpy
File: numpy/_core/tests/test_numeric.py (Python)

Code before:
            e = np.array([True] * 256, dtype=bool)[7::]
            e[i] = False
            assert_(not np.all(e))
            assert_array_equal(e, ~d)
        # big array test for blocked libc loops
        for i in list(range(9, 6000, 507)) + [7764, 90021, -10]:
            d = np.array([False] * 100043, dtype=bool)
            d[i] = True
            assert_(np.any(d), msg=f"{i!r}")
            e = np.array([True] * 100043, dtype=bool)
            e[i] = False
            assert_(not np.all(e), msg=f"{i!r}")

    def test_logical_not_abs(self):
        t, f, o, nm, im = self._create_arrays()
        assert_array_equal(~t, f)
        assert_array_equal(np.abs(~t), f)
        assert_array_equal(np.abs(~f), t)
        assert_array_equal(np.abs(f), f)
        assert_array_equal(~np.abs(f), t)
        assert_array_equal(~np.abs(t), f)
        assert_array_equal(np.abs(~nm), im)
        np.logical_not(t, out=o)
        assert_array_equal(o, f)
        np.abs(t, out=o)
        assert_array_equal(o, t)

    def test_logical_and_or_xor(self):
        t, f, o, nm, im = self._create_arrays()
        assert_array_equal(t | t, t)
        assert_array_equal(f | f, f)
        assert_array_equal(t | f, t)
        assert_array_equal(f | t, t)
        np.logical_or(t, t, out=o)
        assert_array_equal(o, t)
        assert_array_equal(t & t, t)
        assert_array_equal(f & f, f)
        assert_array_equal(t & f, f)
        assert_array_equal(f & t, f)
        np.logical_and(t, t, out=o)
        assert_array_equal(o, t)
        assert_array_equal(t ^ t, f)
        assert_array_equal(f ^ f, f)
        assert_array_equal(t ^ f, t)
        assert_array_equal(f ^ t, t)
        np.logical_xor(t, t, out=o)
        assert_array_equal(o, f)

        assert_array_equal(nm & t, nm)
        assert_array_equal(im & f, False)
        assert_array_equal(nm & True, nm)

Review comment (suggestion):
here as well as in many other tests, there are repeated checks with slightly different data

i think that more standard way would be to use fixtures:

```
@pytest.mark.parametrize("op,a,b,expected", [
    (lambda x, y: x | y, t, t, t),
    (lambda x, y: x | y, f, f, f),
    (lambda x, y: x | y, t, f, t),
    # ...
])
```

Code after:
            e = np.array([True] * 256, dtype=bool)[7::]
            e[i] = False
            assert_(not np.all(e))
            assert_array_equal(e, ~d)
        # big array test for blocked libc loops
        for i in list(range(9, 6000, 507)) + [7764, 90021, -10]:
            d = np.array([False] * 100043, dtype=bool)
            d[i] = True
            assert_(np.any(d), msg=f"{i!r}")
            e = np.array([True] * 100043, dtype=bool)
            e[i] = False
            assert_(not np.all(e), msg=f"{i!r}")

    def test_logical_not_abs(self):
        t, f, o, nm, im = self._create_bool_arrays()
        assert_array_equal(~t, f)
        assert_array_equal(np.abs(~t), f)
        assert_array_equal(np.abs(~f), t)
        assert_array_equal(np.abs(f), f)
        assert_array_equal(~np.abs(f), t)
        assert_array_equal(~np.abs(t), f)
        assert_array_equal(np.abs(~nm), im)
        np.logical_not(t, out=o)
        assert_array_equal(o, f)
        np.abs(t, out=o)
        assert_array_equal(o, t)

    def test_logical_and_or_xor(self):
        t, f, o, nm, im = self._create_bool_arrays()
        assert_array_equal(t | t, t)
        assert_array_equal(f | f, f)
        assert_array_equal(t | f, t)
        assert_array_equal(f | t, t)
        np.logical_or(t, t, out=o)
        assert_array_equal(o, t)
        assert_array_equal(t & t, t)
        assert_array_equal(f & f, f)
        assert_array_equal(t & f, f)
        assert_array_equal(f & t, f)
        np.logical_and(t, t, out=o)
        assert_array_equal(o, t)
        assert_array_equal(t ^ t, f)
        assert_array_equal(f ^ f, f)
        assert_array_equal(t ^ f, t)
        assert_array_equal(f ^ t, t)
        np.logical_xor(t, t, out=o)
        assert_array_equal(o, f)

        assert_array_equal(nm & t, nm)
        assert_array_equal(im & f, False)
        assert_array_equal(nm & True, nm)