<commit_before>import unittest
from pyinform import entropyrate
from math import isnan
import numpy

class EntropyRateHistoryTooLong(unittest.TestCase):

    def testHistoryTooLongBase2(self):
        series = numpy.random.randint(2,size = 30)
        with self.assertRaises(ValueError):
            entropyrate(series,26,2)

    def testHistoryTooLongBase3(self):
        series = numpy.random.randint(3,size = 30)
        with self.assertRaises(ValueError):
            entropyrate(series,16,3)

    def testHistoryTooLongBase4(self):
        series = numpy.random.randint(4,size = 30)
        with self.assertRaises(ValueError):
            entropyrate(series,13,4)

class TimeSeriesTooShort(unittest.TestCase):

    def testTimeSeriesTooShort(self):
        series = [1,0,1,0]
        with self.assertRaises(ValueError):
            entropyrate(series,4,2)


class EntropyRateEncodingError(unittest.TestCase):

    def testIncorrectBase(self):
        with self.assertRaises(ValueError):
            entropyrate([2,1,0,0,1,0,0,1],3,2)


class TestEntropyRate(unittest.TestCase):

    def testBase2(self):
        self.assertAlmostEqual(0.000000, entropyrate([1,1,0,0,1,0,0,1], 2, 2), places=6)
        self.assertAlmostEqual(0.000000, entropyrate([1,0,0,0,0,0,0,0,0], 2, 2), places=6)
        self.assertAlmostEqual(0.679270, entropyrate([0,0,1,1,1,1,0,0,0], 2, 2), places=6)
        self.assertAlmostEqual(0.515663, entropyrate([1,0,0,0,0,0,0,1,1], 2, 2), places=6)
        self.assertAlmostEqual(0.463587, entropyrate([0,0,0,0,0,1,1,0,0], 2, 2), places=6)
        self.assertAlmostEqual(0.463587, entropyrate([0,0,0,0,1,1,0,0,0], 2, 2), places=6)
        self.assertAlmostEqual(0.679270, entropyrate([1,1,1,0,0,0,0,1,1], 2, 2), places=6)
        self.assertAlmostEqual(0.679270, entropyrate([0,0,0,1,1,1,1,0,0], 2, 2), places=6)
        self.assertAlmostEqual(0.515663, entropyrate([0,0,0,0,0,0,1,1,0], 2, 2), places=6)

    def testBase4(self):
        self.assertAlmostEqual(0.285714, entropyrate([3,3,3,2,1,0,0,0,1], 2, 4), places=6)
        self.assertAlmostEqual(0.196778, entropyrate([2,2,3,3,3,3,2,1,0], 2, 4), places=6)
        self.assertAlmostEqual(0.257831, entropyrate([2,2,2,2,2,2,1,1,1], 2, 4), places=6)

class TestEntropyRateEnsemble(unittest.TestCase):

    def testBase2(self):
        self.assertAlmostEqual(0.610249, entropyrate([
            [1,0,0,0,0,0,0,0,0],
            [0,0,1,1,1,1,0,0,0],
            [1,0,0,0,0,0,0,1,1],
            [1,0,0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1,0,0],
            [0,0,0,0,1,1,0,0,0],
            [1,1,1,0,0,0,0,1,1],
            [0,0,0,1,1,1,1,0,0],
            [0,0,0,0,0,0,1,1,0]], 2, 2), places=6)

    def testBase4(self):
        self.assertAlmostEqual(0.272234, entropyrate([
            [3,3,3,2,1,0,0,0,1],
            [2,2,3,3,3,3,2,1,0],
            [0,0,0,0,1,1,0,0,0],
            [1,1,0,0,0,1,1,2,2]], 2, 4), places=6)


if __name__ == "__main__":
    unittest.main()
<commit_msg>Renamed TimeSeriesTooShort function as EntropyRateTimeSeriesTooShort to avoid potential name degeneracy.<commit_after>import unittest
from pyinform import entropyrate
from math import isnan
import numpy

class EntropyRateHistoryTooLong(unittest.TestCase):

    def testHistoryTooLongBase2(self):
        series = numpy.random.randint(2,size = 30)
        with self.assertRaises(ValueError):
            entropyrate(series,26,2)

    def testHistoryTooLongBase3(self):
        series = numpy.random.randint(3,size = 30)
        with self.assertRaises(ValueError):
            entropyrate(series,16,3)

    def testHistoryTooLongBase4(self):
        series = numpy.random.randint(4,size = 30)
        with self.assertRaises(ValueError):
            entropyrate(series,13,4)

class EntropyRateTimeSeriesTooShort(unittest.TestCase):

    def testTimeSeriesTooShort(self):
        series = [1,0,1,0]
        with self.assertRaises(ValueError):
            entropyrate(series,4,2)


class EntropyRateEncodingError(unittest.TestCase):

    def testIncorrectBase(self):
        with self.assertRaises(ValueError):
            entropyrate([2,1,0,0,1,0,0,1],3,2)


class TestEntropyRate(unittest.TestCase):

    def testBase2(self):
        self.assertAlmostEqual(0.000000, entropyrate([1,1,0,0,1,0,0,1], 2, 2), places=6)
        self.assertAlmostEqual(0.000000, entropyrate([1,0,0,0,0,0,0,0,0], 2, 2), places=6)
        self.assertAlmostEqual(0.679270, entropyrate([0,0,1,1,1,1,0,0,0], 2, 2), places=6)
        self.assertAlmostEqual(0.515663, entropyrate([1,0,0,0,0,0,0,1,1], 2, 2), places=6)
        self.assertAlmostEqual(0.463587, entropyrate([0,0,0,0,0,1,1,0,0], 2, 2), places=6)
        self.assertAlmostEqual(0.463587, entropyrate([0,0,0,0,1,1,0,0,0], 2, 2), places=6)
        self.assertAlmostEqual(0.679270, entropyrate([1,1,1,0,0,0,0,1,1], 2, 2), places=6)
        self.assertAlmostEqual(0.679270, entropyrate([0,0,0,1,1,1,1,0,0], 2, 2), places=6)
        self.assertAlmostEqual(0.515663, entropyrate([0,0,0,0,0,0,1,1,0], 2, 2), places=6)

    def testBase4(self):
        self.assertAlmostEqual(0.285714, entropyrate([3,3,3,2,1,0,0,0,1], 2, 4), places=6)
        self.assertAlmostEqual(0.196778, entropyrate([2,2,3,3,3,3,2,1,0], 2, 4), places=6)
        self.assertAlmostEqual(0.257831, entropyrate([2,2,2,2,2,2,1,1,1], 2, 4), places=6)

class TestEntropyRateEnsemble(unittest.TestCase):

    def testBase2(self):
        self.assertAlmostEqual(0.610249, entropyrate([
            [1,0,0,0,0,0,0,0,0],
            [0,0,1,1,1,1,0,0,0],
            [1,0,0,0,0,0,0,1,1],
            [1,0,0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1,0,0],
            [0,0,0,0,1,1,0,0,0],
            [1,1,1,0,0,0,0,1,1],
            [0,0,0,1,1,1,1,0,0],
            [0,0,0,0,0,0,1,1,0]], 2, 2), places=6)

    def testBase4(self):
        self.assertAlmostEqual(0.272234, entropyrate([
            [3,3,3,2,1,0,0,0,1],
            [2,2,3,3,3,3,2,1,0],
            [0,0,0,0,1,1,0,0,0],
            [1,1,0,0,0,1,1,2,2]], 2, 4), places=6)


if __name__ == "__main__":
    unittest.main()

{'fraction_non_alphanumeric': 0.18325041459369817, 'fraction_numerical': 0.13432835820895522, 'mean_word_length': 3.5041075429424944, 'pattern_counts': {'":': 2, '<': 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': '5798303', 'n_tokens_mistral': 2795, 'n_tokens_neox': 2490, 'n_words': 315}