From 7c2298e06df83de46bef0e1b7255cf9e32ca2624 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Fri, 14 Sep 2018 17:21:53 -0500 Subject: Rebuilding Lenovo. Checking in the code.--- .../tests/covering_segmentsTest.py | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 AlgoDesignAndTechniqueEdxPython/tests/covering_segmentsTest.py (limited to 'AlgoDesignAndTechniqueEdxPython/tests') diff --git a/AlgoDesignAndTechniqueEdxPython/tests/covering_segmentsTest.py b/AlgoDesignAndTechniqueEdxPython/tests/covering_segmentsTest.py new file mode 100644 index 0000000..2d61601 --- /dev/null +++ b/AlgoDesignAndTechniqueEdxPython/tests/covering_segmentsTest.py @@ -0,0 +1,56 @@ +''' +Created on Sep 9, 2018 + +@author: haidong +''' +import unittest + +from collections import namedtuple + +from sources.covering_segment import getSortedListOfSegs, getOptimalPoints + +Segment = namedtuple('Segment', 'start end') + +class Test(unittest.TestCase): + + + def testNameSegment(self): + s1 = Segment(1,2) + self.assertEqual(s1.start, 1) + self.assertEqual(s1.end, 2) + + def testGetSortedListOfSegs1(self): + s1 = Segment(3,4) + s2 = Segment(1,2) + segList = [s1, s2] + self.assertEqual(getSortedListOfSegs(segList), [s2, s1]) + + def testGetSortedListOfSegs2(self): + s1 = Segment(3,8) + s2 = Segment(3,5) + segList = [s1, s2] + self.assertEqual(getSortedListOfSegs(segList), [s2, s1]) + + def testGetOptimalPoints(self): + s1 = Segment(1,3) + s2 = Segment(2,5) + s3 = Segment(3,6) + segList = [s1, s2, s3] + segList.sort() + result = getOptimalPoints(segList) + self.assertEqual(len(result), 1) + + def testGetOptimalPoints1(self): + s1 = Segment(4,7) + s2 = Segment(1,3) + s3 = Segment(2,5) + s4 = Segment(5,6) + segList = [s1, s2, s3, s4] + segList.sort() + result = getOptimalPoints(segList) + self.assertEqual(len(result), 2) + + +if __name__ == "__main__": + #import sys;sys.argv = ['', 'Test.testName'] + unittest.main() \ No newline at end of file -- cgit v1.2.3