summaryrefslogtreecommitdiff
path: root/AlgoDesignAndTechniqueEdxPython/tests/majority_elementTest.py
diff options
context:
space:
mode:
Diffstat (limited to 'AlgoDesignAndTechniqueEdxPython/tests/majority_elementTest.py')
-rw-r--r--AlgoDesignAndTechniqueEdxPython/tests/majority_elementTest.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/AlgoDesignAndTechniqueEdxPython/tests/majority_elementTest.py b/AlgoDesignAndTechniqueEdxPython/tests/majority_elementTest.py
new file mode 100644
index 0000000..b886710
--- /dev/null
+++ b/AlgoDesignAndTechniqueEdxPython/tests/majority_elementTest.py
@@ -0,0 +1,44 @@
+'''
+Created on Oct 31, 2018
+
+@author: haidong
+'''
+import unittest
+
+from sources.majority_element import getMajorityElement
+
+class Test(unittest.TestCase):
+
+
+ def testGetMajorityElement1(self):
+ a = [1,1]
+ self.assertEqual(1, getMajorityElement(a, 0, len(a)-1))
+
+ def testGetMajorityElement2(self):
+ a = [1,2]
+ self.assertEqual(-1, getMajorityElement(a, 0, len(a)-1))
+
+ def testGetMajorityElement3(self):
+ a = [1,2,1]
+ self.assertEqual(1, getMajorityElement(a, 0, len(a)-1))
+
+ def testGetMajorityElement4(self):
+ a = [1,2,2]
+ self.assertEqual(2, getMajorityElement(a, 0, len(a)-1))
+
+ def testGetMajorityElement5(self):
+ a = [1]
+ self.assertEqual(1, getMajorityElement(a, 0, len(a)-1))
+
+ def testGetMajorityElement6(self):
+ a = [1, 2, 2, 2]
+ self.assertEqual(2, getMajorityElement(a, 0, len(a)-1))
+
+ def testGetMajorityElement7(self):
+ a = [2, 3, 9, 2, 2]
+ self.assertEqual(2, getMajorityElement(a, 0, len(a)-1))
+
+
+if __name__ == "__main__":
+ #import sys;sys.argv = ['', 'Test.testName']
+ unittest.main() \ No newline at end of file