def test_extensions_entropy_jsp(self): actual = extensions_entropy(self.ds) jsp_e = -(2 / 6) * get_log(2 / 6) - (2 / 4) * get_log( 2 / 4) - (1 / 4) * get_log(1 / 4) self.assertEqual(jsp_e, actual.get('dev1').get('.jsp'), 'test_extensions_entropy_jsp')
def test_extensions_entropy_py(self): actual = extensions_entropy(self.ds) py_e = -(1 / 2) * get_log(1 / 2) - (1 / 7) * get_log( 1 / 7) - (1 / 4) * get_log(1 / 4) self.assertEqual(py_e, actual.get('dev2').get('.py'), 'test_extensions_entropy_py')
def test_extensions_entropy_php(self): actual = extensions_entropy(self.ds) php_e = -(1 / 6) * get_log(1 / 6) - (1 / 4) * get_log( 1 / 4) - (1 / 2) * get_log(1 / 2) self.assertEqual(php_e, actual.get('dev1').get('.php'), 'test_extensions_entropy_php')
def test_extensions_entropy_java(self): actual = extensions_entropy(self.ds) java_e = -(1 / 2) * get_log(1 / 2) - (1 / 4) * get_log( 1 / 4) - (1 / 4) * get_log(1 / 4) - (1) * get_log(1) self.assertEqual(java_e, actual.get('dev1').get('.java'), 'test_extensions_entropy_java')
def test_ext_ranges(self): ext = extensions_entropy(self.ds) data = {'good': ext} actual = get_ext_ranges(data) self.assertEqual(actual['good'].get(0), 0, 'test_ext_ranges limit: 0') self.assertEqual(actual['good'].get(1), 3, 'test_ext_ranges limit: 1') self.assertEqual(actual['good'].get(2), 4, 'test_ext_ranges limit: 2') self.assertEqual(actual['good'].get(5), 0, 'test_ext_ranges limit: 5')
def test_extension_distribution(self): ext = extensions_entropy(self.ds) java_e = -(1 / 2) * get_log(1 / 2) - (1 / 4) * get_log( 1 / 4) - (1 / 4) * get_log(1 / 4) - (1) * get_log(1) data = {'good': ext} actual = extension_distribution(data) self.assertEqual(actual['good'][1], ['dev1 .java', java_e], 'test_extension_distribution')
def test_get_popular(self): ext = extensions_entropy(self.ds_extended) data = {'good': ext} two = get_popular(data, 2) one = get_popular(data, 1) self.assertTrue('.java' in one[0], 'test_get_popular for one popular extension') self.assertEqual(len(two), 2, 'test_get_popular for four popular extensions') self.assertTrue('.java' in two[0], 'test_get_popular for four popular extensions: .java') self.assertTrue('.py' in two[1], 'test_get_popular for four popular extensions: .py')
def test_get_extremes_avg(self): ext = extensions_entropy(self.ds_extended) data = {'good': ext, 'bad': ext} extremes, avgs = get_extremes_avg(data) jsp_e = -(2 / 6) * get_log(2 / 6) - (2 / 4) * get_log( 2 / 4) - (1 / 4) * get_log(1 / 4) self.assertEqual(len(extremes['good']), 0, 'test_get_extremes_avg list of min should be empty') self.assertEqual(avgs['good']['.jsp'][1], set(['dev1']), 'test_get_extremes_avg avg developers .jsp') self.assertEqual(avgs['good']['.java'][1], set(['dev1', 'dev3', 'dev4']), 'test_get_extremes_avg avg developers .jsp') self.assertEqual(avgs['good']['.jsp'][0], jsp_e, 'test_get_extremes_avg avg entropy sum .jsp') self.assertEqual(avgs['good']['.jsp'][2], jsp_e, 'test_get_extremes_avg avg entropy avg .jsp')
def test_extension_distribution_count(self): ext = extensions_entropy(self.ds) data = {'good': ext} actual = extension_distribution(data) self.assertEqual(len(actual['good']), 7, 'test_extension_distribution_count')
def test_average_ext_number(self): ext = extensions_entropy(self.ds) data = {'good': ext} actual = average_ext_number(data) self.assertEqual(actual['good'], 3.5, 'test_average_ext_number')