<commit_before>import unittest

from functional.chain import seq, FunctionalSequence, _wrap


class TestChain(unittest.TestCase):
    def assertType(self, s):
        self.assertTrue(isinstance(s, FunctionalSequence))

    def assertNotType(self, s):
        self.assertFalse(isinstance(s, FunctionalSequence))

    def test_base_sequence(self):
        l = []
        self.assertType(seq(l))
        self.assertNotType(seq(l).sequence)
        self.assertType(seq(seq(l)))
        self.assertNotType(seq(seq(l)).sequence)

    def test_eq(self):
        l = [1, 2, 3]
        self.assertEqual(seq(l), seq(l))

    def test_ne(self):
        a = [1, 2, 3]
        b = [1]
        self.assertNotEqual(seq(a), seq(b))

    def test_repr(self):
        l = [1, 2, 3]
        self.assertEqual(repr(l), repr(seq(l)))

    def test_str(self):
        l = [1, 2, 3]
        self.assertEqual(str(l), str(seq(l)))

    def test_len(self):
        l = [1, 2, 3]
        s = seq(l)
        self.assertEqual(len(l), len(s))
        self.assertEqual(len(l), s.size())
        self.assertEqual(len(l), s.len())

    def test_count(self):
        l = seq([-1, -1, 1, 1, 1])
        self.assertEqual(l.count(lambda x: x > 0), 3)
        self.assertEqual(l.count(lambda x: x < 0), 2)

    def test_getitem(self):
        l = [1, 2, [3, 4, 5]]
        s = seq(l)
        self.assertEqual(s[1], 2)
        self.assertEqual(s[2], [3, 4, 5])
        self.assertType(s[2])
        self.assertEqual(s[1:], [2, [3, 4, 5]])
        self.assertTrue(s[1:])
        l = [{1, 2}, {2, 3}, {4, 5}]
        s = seq(l)
        self.assertIsInstance(s[0], set)
        self.assertEqual(s[0], l[0])

    def test_setitem(self):
        l = [1, 2, 3, 4, [5, 6, 7]]
        s = seq(l)
        s[1:3] = 8, 9
        expect = [1, 8, 9, 4, [5, 6, 7]]
        self.assertEqual(s, expect)

    def test_delitem(self):
        l = [1, 2, 3, 4, [5, 6, 7]]
        s = seq(l)
        del s[1]
        expected = [1, 3, 4, [5, 6, 7]]
        self.assertEqual(s, expected)

    def test_iter(self):
        l = list(enumerate(seq([1, 2, 3])))
        e = list(enumerate([1, 2, 3]))
        self.assertEqual(l, e)
        l = seq([1, 2, 3])
        e = [1, 2, 3]
        result = []
        for n in l:
            result.append(n)
        self.assertEqual(result, e)
        self.assertType(l)

    def test_contains(self):
        string = "abcdef"
        s = seq(string)
        self.assertTrue("c" in s)

    def test_add(self):
        l0 = seq([1, 2, 3])
        l1 = seq([4, 5, 6])
        l2 = [4, 5, 6]
        expect = [1, 2, 3, 4, 5, 6]
        self.assertEqual(l0 + l1, expect)
        self.assertEqual(l0 + l2, expect)

    def test_head(self):
        l = seq([1, 2, 3])
        self.assertEqual(l.head(), 1)
        l = seq([[1, 2], 3, 4])
        self.assertEqual(l.head(), [1, 2])
        self.assertType(l.head())
        l = seq([])
        with self.assertRaises(IndexError):
            l.head()

    def test_first(self):
        l = seq([1, 2, 3])
        self.assertEqual(l.first(), 1)
        l = seq([[1, 2], 3, 4])
        self.assertEqual(l.first(), [1, 2])
        self.assertType(l.first())
        l = seq([])
        with self.assertRaises(IndexError):
            l.head()

    def test_head_option(self):
        l = seq([1, 2, 3])
        self.assertEqual(l.head_option(), 1)
        l = seq([[1, 2], 3, 4])
        self.assertEqual(l.head_option(), [1, 2])
        self.assertType(l.head_option())
        l = seq([])
        self.assertIsNone(l.head_option())

    def test_last(self):
        l = seq([1, 2, 3])
        self.assertEqual(l.last(), 3)
        l = seq([1, 2, [3, 4]])
        self.assertEqual(l.last(), [3, 4])
        self.assertType(l.last())

    def test_init(self):
        l = seq([1, 2, 3, 4])
        expect = [1, 2, 3]
        self.assertSequenceEqual(l.init(), expect)

    def test_tail(self):
        l = seq([1, 2, 3, 4])
        expect = [2, 3, 4]
        self.assertSequenceEqual(l.tail(), expect)

    def test_inits(self):
        l = seq([1, 2, 3])
        expect = [[1, 2, 3], [1, 2], [1], []]
        self.assertSequenceEqual(l.inits(), expect)
        self.assertEquals(l.inits().map(lambda s: s.sum()), [6, 3, 1, 0])

    def test_tails(self):
        l = seq([1, 2, 3])
        expect = [[1, 2, 3], [2, 3], [3], []]
        self.assertSequenceEqual(l.tails(), expect)
        self.assertEquals(l.tails().map(lambda s: s.sum()), [6, 5, 3, 0])

    def test_drop(self):
        l = [1, 2, 3, 4, 5, 6]
        expect = [5, 6]
        result = seq(l).drop(4)
        self.assertEqual(result, expect)
        self.assertTrue(result)

    def test_drop_while(self):
        l = [1, 2, 3, 4, 5, 6, 7, 8]
        f = lambda x: x < 4
        expect = [4, 5, 6, 7, 8]
        result = seq(l).drop_while(f)
        self.assertEqual(expect, result)
        self.assertType(result)

    def test_take(self):
        l = [1, 2, 3, 4, 5, 6]
        expect = [1, 2, 3, 4]
        result = seq(l).take(4)
        self.assertEqual(result, expect)
        self.assertTrue(result)

    def test_take_while(self):
        l = [1, 2, 3, 4, 5, 6, 7, 8]
        f = lambda x: x < 4
        expect = [1, 2, 3]
        result = seq(l).take_while(f)
        self.assertEqual(expect, result)
        self.assertType(result)
<commit_msg>fixed some deprecation warnings on using assertEquals instead of assertEqual<commit_after>import unittest

from functional.chain import seq, FunctionalSequence, _wrap


class TestChain(unittest.TestCase):
    def assertType(self, s):
        self.assertTrue(isinstance(s, FunctionalSequence))

    def assertNotType(self, s):
        self.assertFalse(isinstance(s, FunctionalSequence))

    def test_base_sequence(self):
        l = []
        self.assertType(seq(l))
        self.assertNotType(seq(l).sequence)
        self.assertType(seq(seq(l)))
        self.assertNotType(seq(seq(l)).sequence)

    def test_eq(self):
        l = [1, 2, 3]
        self.assertEqual(seq(l), seq(l))

    def test_ne(self):
        a = [1, 2, 3]
        b = [1]
        self.assertNotEqual(seq(a), seq(b))

    def test_repr(self):
        l = [1, 2, 3]
        self.assertEqual(repr(l), repr(seq(l)))

    def test_str(self):
        l = [1, 2, 3]
        self.assertEqual(str(l), str(seq(l)))

    def test_len(self):
        l = [1, 2, 3]
        s = seq(l)
        self.assertEqual(len(l), len(s))
        self.assertEqual(len(l), s.size())
        self.assertEqual(len(l), s.len())

    def test_count(self):
        l = seq([-1, -1, 1, 1, 1])
        self.assertEqual(l.count(lambda x: x > 0), 3)
        self.assertEqual(l.count(lambda x: x < 0), 2)

    def test_getitem(self):
        l = [1, 2, [3, 4, 5]]
        s = seq(l)
        self.assertEqual(s[1], 2)
        self.assertEqual(s[2], [3, 4, 5])
        self.assertType(s[2])
        self.assertEqual(s[1:], [2, [3, 4, 5]])
        self.assertTrue(s[1:])
        l = [{1, 2}, {2, 3}, {4, 5}]
        s = seq(l)
        self.assertIsInstance(s[0], set)
        self.assertEqual(s[0], l[0])

    def test_setitem(self):
        l = [1, 2, 3, 4, [5, 6, 7]]
        s = seq(l)
        s[1:3] = 8, 9
        expect = [1, 8, 9, 4, [5, 6, 7]]
        self.assertEqual(s, expect)

    def test_delitem(self):
        l = [1, 2, 3, 4, [5, 6, 7]]
        s = seq(l)
        del s[1]
        expected = [1, 3, 4, [5, 6, 7]]
        self.assertEqual(s, expected)

    def test_iter(self):
        l = list(enumerate(seq([1, 2, 3])))
        e = list(enumerate([1, 2, 3]))
        self.assertEqual(l, e)
        l = seq([1, 2, 3])
        e = [1, 2, 3]
        result = []
        for n in l:
            result.append(n)
        self.assertEqual(result, e)
        self.assertType(l)

    def test_contains(self):
        string = "abcdef"
        s = seq(string)
        self.assertTrue("c" in s)

    def test_add(self):
        l0 = seq([1, 2, 3])
        l1 = seq([4, 5, 6])
        l2 = [4, 5, 6]
        expect = [1, 2, 3, 4, 5, 6]
        self.assertEqual(l0 + l1, expect)
        self.assertEqual(l0 + l2, expect)

    def test_head(self):
        l = seq([1, 2, 3])
        self.assertEqual(l.head(), 1)
        l = seq([[1, 2], 3, 4])
        self.assertEqual(l.head(), [1, 2])
        self.assertType(l.head())
        l = seq([])
        with self.assertRaises(IndexError):
            l.head()

    def test_first(self):
        l = seq([1, 2, 3])
        self.assertEqual(l.first(), 1)
        l = seq([[1, 2], 3, 4])
        self.assertEqual(l.first(), [1, 2])
        self.assertType(l.first())
        l = seq([])
        with self.assertRaises(IndexError):
            l.head()

    def test_head_option(self):
        l = seq([1, 2, 3])
        self.assertEqual(l.head_option(), 1)
        l = seq([[1, 2], 3, 4])
        self.assertEqual(l.head_option(), [1, 2])
        self.assertType(l.head_option())
        l = seq([])
        self.assertIsNone(l.head_option())

    def test_last(self):
        l = seq([1, 2, 3])
        self.assertEqual(l.last(), 3)
        l = seq([1, 2, [3, 4]])
        self.assertEqual(l.last(), [3, 4])
        self.assertType(l.last())

    def test_init(self):
        l = seq([1, 2, 3, 4])
        expect = [1, 2, 3]
        self.assertSequenceEqual(l.init(), expect)

    def test_tail(self):
        l = seq([1, 2, 3, 4])
        expect = [2, 3, 4]
        self.assertSequenceEqual(l.tail(), expect)

    def test_inits(self):
        l = seq([1, 2, 3])
        expect = [[1, 2, 3], [1, 2], [1], []]
        self.assertSequenceEqual(l.inits(), expect)
        self.assertEqual(l.inits().map(lambda s: s.sum()), [6, 3, 1, 0])

    def test_tails(self):
        l = seq([1, 2, 3])
        expect = [[1, 2, 3], [2, 3], [3], []]
        self.assertSequenceEqual(l.tails(), expect)
        self.assertEqual(l.tails().map(lambda s: s.sum()), [6, 5, 3, 0])

    def test_drop(self):
        l = [1, 2, 3, 4, 5, 6]
        expect = [5, 6]
        result = seq(l).drop(4)
        self.assertEqual(result, expect)
        self.assertTrue(result)

    def test_drop_while(self):
        l = [1, 2, 3, 4, 5, 6, 7, 8]
        f = lambda x: x < 4
        expect = [4, 5, 6, 7, 8]
        result = seq(l).drop_while(f)
        self.assertEqual(expect, result)
        self.assertType(result)

    def test_take(self):
        l = [1, 2, 3, 4, 5, 6]
        expect = [1, 2, 3, 4]
        result = seq(l).take(4)
        self.assertEqual(result, expect)
        self.assertTrue(result)

    def test_take_while(self):
        l = [1, 2, 3, 4, 5, 6, 7, 8]
        f = lambda x: x < 4
        expect = [1, 2, 3]
        result = seq(l).take_while(f)
        self.assertEqual(expect, result)
        self.assertType(result)

{'fraction_non_alphanumeric': 0.17758315475635889, 'fraction_numerical': 0.045467250535730926, 'mean_word_length': 1.929585152838428, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4405175', 'n_tokens_mistral': 4293, 'n_tokens_neox': 3927, 'n_words': 971}