-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
114 lines (93 loc) · 3.78 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Author: Mostafa Okasha ([email protected])
# Affiliation: CapitalOne - Technical Assessment
import unittest
from commentanalyzer import *
''' CommentAnalyzer Class tests
'''
class CommentAnalyzerTest(unittest.TestCase):
def test_1_file_extension(self):
"""Capability to detect valid file extensions
"""
filename = "gitig.nore.c++"
test_class = CommentAnalyzer(filename)
result = test_class.file_extension
self.assertEqual(result, "c++")
def test_2_file_extension(self):
"""
filename with
"""
filename = ".gitig.nore.c++"
test_class = CommentAnalyzer(filename)
result = test_class.file_extension
self.assertEqual(result, False)
def test_3_file_extension(self):
"""
Test CommentAnalyzer class's capability to detect valid file extensions
"""
filename = "LICENSE"
test_class = CommentAnalyzer(filename)
result = test_class.file_extension
self.assertEqual(result, False)
def test_4_file_extension(self):
"""
Test CommentAnalyzer class's capability to detect valid file extensions
"""
filename = "commentanalyzer.py"
test_class = CommentAnalyzer(filename)
result = test_class.file_extension
self.assertEqual(result, "py")
def test_1_loc_count(self):
"""
Test CommentAnalyzer class's capability to detect valid file extensions
"""
filename = "extensions.py"
test_class = CommentAnalyzer(filename)
test_class.analyze_code()
result = test_class.counter_dict["loc"]
self.assertEqual(result, 118)
def test_1_output(self):
"""
Test CommentAnalyzer class's capability to analyze comments
"""
filename = "tests/test_cases/test1.java"
test_class = CommentAnalyzer(filename)
test_class.analyze_code()
test_output = test_class.analysis_output('JSON')
actual_output = {'loc': 60, 'tot_comments': 28, 'single_comments': 6,
'block_comment_lines': 22, 'block_comments': 2, 'todos': 1}
self.assertEqual(test_output, actual_output)
def test_2_output(self):
"""
Test CommentAnalyzer class's capability to analyze comments
"""
filename = "tests/test_cases/test2.js"
test_class = CommentAnalyzer(filename)
test_class.analyze_code()
test_output = test_class.analysis_output('JSON')
actual_output = {'loc': 40, 'tot_comments': 23, 'single_comments': 5,
'block_comment_lines': 18, 'block_comments': 4, 'todos': 1}
self.assertEqual(test_output, actual_output)
def test_3_output(self):
"""
Test CommentAnalyzer class's capability to analyze comments
"""
filename = "tests/test_cases/test3.py"
test_class = CommentAnalyzer(filename)
test_class.analyze_code()
test_output = test_class.analysis_output('JSON')
actual_output = {'loc': 61, 'tot_comments': 19, 'single_comments': 9,
'block_comment_lines': 10, 'block_comments': 3, 'todos': 3}
self.assertEqual(test_output, actual_output)
def test_4_output(self):
"""
Test CommentAnalyzer class's capability to analyze comments
"""
filename = "tests/test_cases/test4.py"
test_class = CommentAnalyzer(filename)
test_class.analyze_code()
test_output = test_class.analysis_output('JSON')
actual_output = {'loc': 25, 'tot_comments': 13, 'single_comments': 6,
'block_comment_lines': 7, 'block_comments': 3, 'todos': 5}
self.assertEqual(test_output, actual_output)
if __name__ == '__main__':
unittest.main()