<commit_before>import s
import collections


def test_func():
    state = {'val': 0}
    @s.cached.func
    def fn():
        state['val'] += 1
        return state['val']
    assert state['val'] == 0
    fn()
    assert state['val'] == 1
    fn()
    assert state['val'] == 1


def test_clear():
    state = {'val': 0}
    @s.cached.func
    def fn():
        state['val'] += 1
        return state['val']
    assert fn() == 1
    assert fn() == 1
    fn.clear_cache()
    assert fn() == 2
    assert fn() == 2


def test_memoize():
    state = collections.Counter()
    @s.cached.memoize(2)
    def fn(arg):
        state[arg] += 1
        return arg
    assert fn('a') == 'a'
    assert fn('b') == 'b'
    assert state == {'a': 1, 'b': 1}
    assert fn('a') == 'a'
    assert fn('b') == 'b'
    assert state == {'a': 1, 'b': 1}
    assert fn._data == {(('a', ), ()): 'a', (('b',), ()): 'b'}
    assert fn('c') == 'c'
    assert fn._data == {(('b',), ()): 'b', (('c', ), ()): 'c', }<commit_msg>update tests for s.cached<commit_after>import s
import collections


def test_func():
    state = {'val': 0}
    @s.cached.func
    def fn():
        state['val'] += 1
    fn(), fn(), fn()
    assert state['val'] == 1


def test_clear_func():
    state = {'val': 0}
    @s.cached.func
    def fn():
        state['val'] += 1
    fn(), fn(), fn()
    assert state['val'] == 1
    fn.clear_cache()
    fn(), fn(), fn()
    assert state['val'] == 2


def test_memoize():
    state = collections.Counter()
    @s.cached.memoize(2)
    def fn(arg):
        state[arg] += 1
    fn('a'), fn('a'), fn('b'), fn('b')
    assert state == {'a': 1, 'b': 1}


def test_without_optional_args_memoize():
    state = collections.Counter()
    @s.cached.memoize
    def fn(arg):
        state[arg] += 1
    fn('a'), fn('a'), fn('b'), fn('b')
    assert state == {'a': 1, 'b': 1}


def test_lru_is_correct_memoize():
    state = collections.Counter()
    @s.cached.memoize(2)
    def fn(arg):
        state[arg] += 1
        return arg
    fn('a')
    assert list(getattr(fn, s.cached._attr).items()) == [((('a',), ()), 'a')]
    fn('b'),
    assert list(getattr(fn, s.cached._attr).items()) == [((('a',), ()), 'a'), ((('b',), ()), 'b')]
    fn('c')
    assert list(getattr(fn, s.cached._attr).items()) == [((('b',), ()), 'b'), ((('c',), ()), 'c')]
{'fraction_non_alphanumeric': 0.2486021505376344, 'fraction_numerical': 0.014193548387096775, 'mean_word_length': 2.5457317073170733, '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': '5410384', 'n_tokens_mistral': 901, 'n_tokens_neox': 860, 'n_words': 219}