<commit_before># -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from itertools import combinations
import operator
import random
import sys
import pytest

from pqdict import pqdict, minpq, maxpq, nlargest, nsmallest


sample_keys = ["A", "B", "C", "D", "<KEY>"]
sample_values = [5, 8, 7, 3, 9, 12, 1]
sample_items = list(zip(sample_keys, sample_values))


def generate_data(value_type, num_items=None):
    # shuffled set of two-letter keys
    if num_items is None:
        pairs = combinations("ABCDEFGHIJKLMNOP", 2)  # 120 keys
        keys = ["".join(pair) for pair in pairs]
        random.shuffle(keys)
        num_items = len(keys)
    else:
        pairs = combinations("ABCDEFGHIJKLMNOP", 2)
        keys = ["".join(next(pairs)) for _ in range(num_items)]
        random.shuffle(keys)
    # different kinds of values
    if value_type == "int":
        values = [random.randint(0, 100) for i in range(num_items)]
    elif value_type == "float":
        values = [random.random() for i in range(num_items)]
    elif value_type == "unique":
        values = list(range(num_items))
        random.shuffle(values)
    return list(zip(keys, values))


def _check_heap_invariant(pq):
    heap = pq._heap
    for pos, node in enumerate(heap):
        if pos:  # pos 0 has no parent
            parentpos = (pos - 1) >> 1
            assert heap[parentpos].value <= node.value


def _check_index(pq):
    # All heap entries are pointed to by the index (_position)
    n = len(pq._heap)
    nodes = pq._position.values()
    assert list(range(n)) == sorted(nodes)
    # All heap entries map back to the correct dictionary key
    for key in pq._position:
        node = pq._heap[pq._position[key]]
        assert key == node.key


# The next group of tests were originally in class TestNew


def test_constructor():
    # sequence of pairs
    pq0 = pqdict(
        [("A", 5), ("B", 8), ("C", 7), ("D", 3), ("E", 9), ("F", 12), ("G", 1)]
    )
    pq1 = pqdict(zip(["A", "B", "C", "D", "E", "F", "G"], [5, 8, 7, 3, 9, 12, 1]))
    # dictionary
    pq2 = pqdict({"A": 5, "B": 8, "C": 7, "D": 3, "E": 9, "F": 12, "G": 1})
    # keyword arguments
    pq3 = minpq(A=5, B=8, C=7, D=3, E=9, F=12, G=1)
    assert pq0 == pq1 == pq2 == pq3


def test_equality():
    # eq
    pq1 = pqdict(sample_items)
    pq2 = pqdict(sample_items)
    assert pq1 == pq2
    assert not pq1 != pq2
    # ne
    pq2[random.choice(sample_keys)] += 1
    assert not pq1 == pq2
    assert pq1 != pq2
    # pqdict == regular dict if they have same key/value pairs
    adict = dict(sample_items)
    assert pq1 == adict
    # TODO: FIX?
    # pqdicts evaluate as equal even if they have different
    # key functions and/or precedence functions
    pq3 = maxpq(sample_items)
    assert pq1 == pq3


def test_minpq():
    pq = minpq(A=5, B=8, C=7, D=3, E=9, F=12, G=1)
    assert list(pq.popvalues()), [1, 3, 5, 7, 8, 9, 12]<commit_msg>Update tests/test_pqdict.py<commit_after># -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from itertools import combinations
import operator
import random
import sys
import pytest

from pqdict import pqdict, minpq, maxpq, nlargest, nsmallest


sample_keys = ["A", "B", "C", "D", "E", "F", "G"]
sample_values = [5, 8, 7, 3, 9, 12, 1]
sample_items = list(zip(sample_keys, sample_values))


def generate_data(value_type, num_items=None):
    # shuffled set of two-letter keys
    if num_items is None:
        pairs = combinations("ABCDEFGHIJKLMNOP", 2)  # 120 keys
        keys = ["".join(pair) for pair in pairs]
        random.shuffle(keys)
        num_items = len(keys)
    else:
        pairs = combinations("ABCDEFGHIJKLMNOP", 2)
        keys = ["".join(next(pairs)) for _ in range(num_items)]
        random.shuffle(keys)
    # different kinds of values
    if value_type == "int":
        values = [random.randint(0, 100) for i in range(num_items)]
    elif value_type == "float":
        values = [random.random() for i in range(num_items)]
    elif value_type == "unique":
        values = list(range(num_items))
        random.shuffle(values)
    return list(zip(keys, values))


def _check_heap_invariant(pq):
    heap = pq._heap
    for pos, node in enumerate(heap):
        if pos:  # pos 0 has no parent
            parentpos = (pos - 1) >> 1
            assert heap[parentpos].value <= node.value


def _check_index(pq):
    # All heap entries are pointed to by the index (_position)
    n = len(pq._heap)
    nodes = pq._position.values()
    assert list(range(n)) == sorted(nodes)
    # All heap entries map back to the correct dictionary key
    for key in pq._position:
        node = pq._heap[pq._position[key]]
        assert key == node.key


# The next group of tests were originally in class TestNew


def test_constructor():
    # sequence of pairs
    pq0 = pqdict(
        [("A", 5), ("B", 8), ("C", 7), ("D", 3), ("E", 9), ("F", 12), ("G", 1)]
    )
    pq1 = pqdict(zip(["A", "B", "C", "D", "E", "F", "G"], [5, 8, 7, 3, 9, 12, 1]))
    # dictionary
    pq2 = pqdict({"A": 5, "B": 8, "C": 7, "D": 3, "E": 9, "F": 12, "G": 1})
    # keyword arguments
    pq3 = minpq(A=5, B=8, C=7, D=3, E=9, F=12, G=1)
    assert pq0 == pq1 == pq2 == pq3


def test_equality():
    # eq
    pq1 = pqdict(sample_items)
    pq2 = pqdict(sample_items)
    assert pq1 == pq2
    assert not pq1 != pq2
    # ne
    pq2[random.choice(sample_keys)] += 1
    assert not pq1 == pq2
    assert pq1 != pq2
    # pqdict == regular dict if they have same key/value pairs
    adict = dict(sample_items)
    assert pq1 == adict
    # TODO: FIX?
    # pqdicts evaluate as equal even if they have different
    # key functions and/or precedence functions
    pq3 = maxpq(sample_items)
    assert pq1 == pq3


def test_minpq():
    pq = minpq(A=5, B=8, C=7, D=3, E=9, F=12, G=1)
    assert list(pq.popvalues()) == [1, 3, 5, 7, 8, 9, 12]
{'fraction_non_alphanumeric': 0.14751023192360163, 'fraction_numerical': 0.03171896316507503, 'mean_word_length': 2.8459016393442624, 'pattern_counts': {'":': 20, '<': 6, '<?xml version=': 0, '>': 8, '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': '3669917', 'n_tokens_mistral': 2275, 'n_tokens_neox': 2105, 'n_words': 660}