# Path: lantern/analysis/frequency.py
# def frequency_analyze(text, n=1):
# def frequency_to_probability(frequency_map, decorator=lambda f: f):
# def index_of_coincidence(*texts):
# def _calculate_index_of_coincidence(frequency_map, length):
# def chi_squared(source_frequency, target_frequency):
# def _calculate_chi_squared(source_freq, target_prob, source_len):
# def _load_ngram(name):
# ENGLISH_IC = _calculate_index_of_coincidence(english.unigrams, sum(english.unigrams.values()))


import pytest
from lantern.analysis import frequency


def test_frequency_analyze_bigram():
    """Testing frequency analyze works for ngram = 2"""
    assert frequency.frequency_analyze("abb", 2) == {'ab': 1, 'bb': 1}


def test_frequency_analyze_empty_string():
    """Testing empty string can be frequency analyzed"""
    assert frequency.frequency_analyze("") == {}


def test_frequency_to_probability():
    """Testing frequency map is converted to probability distribution succesfully"""
    frequency_map = {'a': 1, 'b': 2}
    assert frequency.frequency_to_probability(frequency_map) == {'a': 1.0 / 3, 'b': 2.0 / 3}


def test_frequency_to_probability_empty():
    """Testing empty frequency_map is converted to empty probability distribution"""
    assert frequency.frequency_to_probability({}) == {}


def test_index_of_coincidence():
    """Testing index of coincidence for a piece of text"""
    assert frequency.index_of_coincidence("aabbc") == 0.2


def test_index_of_coincidence_multiple_texts():
    """Testing index of coincidence with multiple texts"""

# Path: lantern/analysis/frequency.py
# def frequency_analyze(text, n=1):
# def frequency_to_probability(frequency_map, decorator=lambda f: f):
# def index_of_coincidence(*texts):
# def _calculate_index_of_coincidence(frequency_map, length):
# def chi_squared(source_frequency, target_frequency):
# def _calculate_chi_squared(source_freq, target_prob, source_len):
# def _load_ngram(name):
# ENGLISH_IC = _calculate_index_of_coincidence(english.unigrams, sum(english.unigrams.values()))


# Path: tests/analysis/test_frequency.py
import pytest
from lantern.analysis import frequency



def test_frequency_analyze_bigram():
    """Testing frequency analyze works for ngram = 2"""
    assert frequency.frequency_analyze("abb", 2) == {'ab': 1, 'bb': 1}


def test_frequency_analyze_empty_string():
    """Testing empty string can be frequency analyzed"""
    assert frequency.frequency_analyze("") == {}


def test_frequency_to_probability():
    """Testing frequency map is converted to probability distribution succesfully"""
    frequency_map = {'a': 1, 'b': 2}
    assert frequency.frequency_to_probability(frequency_map) == {'a': 1.0 / 3, 'b': 2.0 / 3}


def test_frequency_to_probability_empty():
    """Testing empty frequency_map is converted to empty probability distribution"""
    assert frequency.frequency_to_probability({}) == {}


def test_index_of_coincidence():
    """Testing index of coincidence for a piece of text"""
    assert frequency.index_of_coincidence("aabbc") == 0.2


def test_index_of_coincidence_multiple_texts():
    """Testing index of coincidence with multiple texts"""

    assert frequency.index_of_coincidence("aabbc", "abbcc") == 0.2