<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_gitcoach
----------------------------------

Tests for `gitcoach` module.
"""

from nose.tools import eq_
from gitcoach import learn


def test_find_correlations():
    input = [
        ['f1', 'f2', 'f3', 'f4'],
        ['f2', 'f3', 'f4'],
        ['f2', 'f4'],
        ['f2', 'f6'],
        ['f4', 'f6'],
    ]
    result = learn.find_correlations(input)
    expected_result = {
        ('f1', 'f2'): 1,
        ('f1', 'f3'): 1,
        ('f1', 'f4'): 1,
        ('f2', 'f3'): 2,
        ('f3', 'f4'): 2,
        ('f2', 'f4'): 3,
        ('f2', 'f6'): 1,
        ('f4', 'f6'): 1,
    }
    eq_(result, expected_result)


def test_find_counts():
    input = [
        ['f1', 'f2', 'f3', 'f4'],
        ['f2', 'f3', 'f4'],
        ['f2', 'f4'],
        ['f2', 'f6'],
        ['f4', 'f6'],
    ]
    expected_result = {
        'f1': 1,
        'f2': 4,
        'f3': 2,
        'f4': 4,
        'f6': 2,
    }
    result = learn.find_counts(input)
    eq_(result, expected_result)<commit_msg>Add tests for coaching code<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_gitcoach
----------------------------------

Tests for `gitcoach` module.
"""

from nose.tools import eq_
from gitcoach import learn, coach


def test_find_correlations():
    input = [
        ['f1', 'f2', 'f3', 'f4'],
        ['f2', 'f3', 'f4'],
        ['f2', 'f4'],
        ['f2', 'f6'],
        ['f4', 'f6'],
    ]
    result = learn.find_correlations(input)
    expected_result = {
        ('f1', 'f2'): 1,
        ('f1', 'f3'): 1,
        ('f1', 'f4'): 1,
        ('f2', 'f3'): 2,
        ('f3', 'f4'): 2,
        ('f2', 'f4'): 3,
        ('f2', 'f6'): 1,
        ('f4', 'f6'): 1,
    }
    eq_(result, expected_result)


def test_find_counts():
    input = [
        ['f1', 'f2', 'f3', 'f4'],
        ['f2', 'f3', 'f4'],
        ['f2', 'f4'],
        ['f2', 'f6'],
        ['f4', 'f6'],
    ]
    expected_result = {
        'f1': 1,
        'f2': 4,
        'f3': 2,
        'f4': 4,
        'f6': 2,
    }
    result = learn.find_counts(input)
    eq_(result, expected_result)


def test_find_relevant_correlations():
    cors = {('f1', 'f2'): 1, ('f2', 'f3'): 2}
    expected_result = {
        'f1': 0.25, 'f3': 0.5,
    }
    result = coach.find_relevant_correlations(cors, 'f2', 4)
    eq_(result, expected_result)


def test_filter_threshold():
    cors = {'f1': 0.2, 'f2': 0.3, 'f3': 0.7, 'f4': 0.95}
    expected_result = {
        'f4': 0.95,
    }
    result = coach.filter_threshold(cors, 0.9)
    eq_(result, expected_result)


def test_filter_threshold_equal():
    '''Ensure filter_threshold doesn't reject correlations when they are
    on the threshold.'''
    cors = {'f1': 0.2, 'f2': 0.3, 'f3': 0.7, 'f4': 0.95}
    expected_result = {
        'f4': 0.95,
    }
    result = coach.filter_threshold(cors, 0.95)
    eq_(result, expected_result)


def test_filter_threshold_lots():
    cors = {'f1': 0.2, 'f2': 0.3, 'f3': 0.7, 'f4': 0.95}
    expected_result = {
        'f2': 0.3, 'f3': 0.7, 'f4': 0.95
    }
    result = coach.filter_threshold(cors, 0.21)
    eq_(result, expected_result)
{'fraction_non_alphanumeric': 0.23857548061771194, 'fraction_numerical': 0.06366214938543965, 'mean_word_length': 1.9746954076850984, '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': '6164273', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1279, 'n_words': 282}