/
Tests.py
100 lines (81 loc) · 2.87 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
#!/usr/bin/python
#------------------------------------------------------------------------------
#Jonathan Roberts, Nathaniel Nguyen, and John Ho
#Computer Science 497B
#Spring Quarter 2013
#Network Intrusion Project
#------------------------------------------------------------------------------
import unittest
from csv import reader
from Log import Log
from Main import parse_file
from Util import filter_by_type
#Place Tests in here
item_list = [] #Making this global so we only have to load it once
#and save 10 seconds from each test
#------------------------------------------------------------------------------
class TestParser(unittest.TestCase):
def setUp(self):
pass
#probably shouldn't put a parse_file in here because this will
#run for each test
def test_parser(self):
fname = "network_dataset.csv"
rows = 0
with open(fname, 'rb') as f:
dataFromFile = reader(f)
for row in dataFromFile:
rows += 1
self.assertEqual(rows, len(parse_file(fname)))
#------------------------------------------------------------------------------
class TestUtil(unittest.TestCase):
def setUp(self):
pass
def test_filter(self):
class_name = "back"
amount = 2203
self.assertEqual(amount, len(filter_by_type(item_list, class_name)))
#------------------------------------------------------------------------------
class TestAnalysis(unittest.TestCase):
def setUp(self):
pass
def test_average(self):
pass
def test_support(self):
pass
def test_confidence(self):
pass
#-------------------------------------------------------------------------------
class TestPoint(unittest.TestPoint):
def setUp(self):
pass
def test_creation(self):
pass
#-------------------------------------------------------------------------------
class TestCluster(unittest.TestCluster):
def setUp(self):
pass
def test_init(self):
pass
#-------------------------------------------------------------------------------
class TestKMeans(unittest.TestKMeans):
def setUp(self):
pass
def test_kmean(self):
pass
#------------------------------------------------------------------------------
def run_suite(suite):
tests = unittest.TestLoader().loadTestsFromTestCase(suite)
return unittest.TextTestRunner(verbosity=2).run(tests)
#------------------------------------------------------------------------------
if __name__ == '__main__':
result = run_suite(TestParser)
if !result.wasSuccessful():
print ""
print "Now loading data..."
item_list = parse_file("network_dataset.csv")
print "Data loaded"
print ""
run_suite(TestUtil)
print "Now testing Analysis..."
run_suite(TestAnalysis)