<commit_before>import unittest

import cupy
from cupy.core import flags
from cupy import testing


class TestFlags(unittest.TestCase):

    def setUp(self):
        self.flags = flags.Flags(1, 2, 3)

    def test_c_contiguous(self):
        self.assertEqual(1, self.flags['C_CONTIGUOUS'])

    def test_f_contiguous(self):
        self.assertEqual(2, self.flags['F_CONTIGUOUS'])

    def test_owndata(self):
        self.assertEqual(3, self.flags['OWNDATA'])

    def test_key_error(self):
        with self.assertRaises(KeyError):
            self.flags['unknown key']

    def test_repr(self):
        self.assertEqual('''  C_CONTIGUOUS : 1
  F_CONTIGUOUS : 2
  OWNDATA : 3''', repr(self.flags))

    def test_fnc(self):
        a_1d_c = testing.shaped_random((4, ), cupy)
        a_2d_c = testing.shaped_random((4, 4), cupy)
        a_2d_f = cupy.asfortranarray(testing.shaped_random((4, 4), cupy))
        a_2d_noncontig = testing.shaped_random((4, 8), cupy)[:, ::2]
        assert a_1d_c.flags.fnc is False
        assert a_2d_c.flags.fnc is False
        assert a_2d_f.flags.fnc is True
        assert a_2d_noncontig.flags.fnc is False

    def test_forc(self):
        a_1d_c = testing.shaped_random((4, ), cupy)
        a_2d_c = testing.shaped_random((4, 4), cupy)
        a_2d_f = cupy.asfortranarray(testing.shaped_random((4, 4), cupy))
        a_2d_noncontig = testing.shaped_random((4, 8), cupy)[:, ::2]
        assert a_1d_c.flags.forc is True
        assert a_2d_c.flags.forc is True
        assert a_2d_f.flags.forc is True
        assert a_2d_noncontig.flags.forc is False<commit_msg>update testing for Flags: compare to numpy<commit_after>import unittest

from cupy.core import flags
from cupy import testing


class TestFlags(unittest.TestCase):

    def setUp(self):
        self.flags = flags.Flags(1, 2, 3)

    def test_c_contiguous(self):
        self.assertEqual(1, self.flags['C_CONTIGUOUS'])

    def test_f_contiguous(self):
        self.assertEqual(2, self.flags['F_CONTIGUOUS'])

    def test_owndata(self):
        self.assertEqual(3, self.flags['OWNDATA'])

    def test_key_error(self):
        with self.assertRaises(KeyError):
            self.flags['unknown key']

    def test_repr(self):
        self.assertEqual('''  C_CONTIGUOUS : 1
  F_CONTIGUOUS : 2
  OWNDATA : 3''', repr(self.flags))


@testing.parameterize(
    *testing.product({
        'order': ['C', 'F', 'non-contiguous'],
        'shape': [(8, ), (4, 8)],
    })
)
class TestContiguityFlags(unittest.TestCase):

    def setUp(self):
        self.flags = None

    def init_flags(self, xp):
        if self.order == 'non-contiguous':
            a = xp.empty(self.shape)[::2]
        else:
            a = xp.empty(self.shape, order=self.order)
        self.flags = a.flags

    @testing.numpy_cupy_equal()
    def test_fnc(self, xp):
        self.init_flags(xp)
        return self.flags.fnc

    @testing.numpy_cupy_equal()
    def test_forc(self, xp):
        self.init_flags(xp)
        return self.flags.forc

    @testing.numpy_cupy_equal()
    def test_f_contiguous(self, xp):
        self.init_flags(xp)
        return self.flags.f_contiguous

    @testing.numpy_cupy_equal()
    def test_c_contiguous(self, xp):
        self.init_flags(xp)
        return self.flags.c_contiguous
{'fraction_non_alphanumeric': 0.12355447352404139, 'fraction_numerical': 0.016433353621424222, 'mean_word_length': 2.8176538908246225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6601732', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1183, 'n_words': 225}