Commits

AJ R  committed 4f4e5d2

Added unit test for rich comparison operators, test_SavReader_operators.py

  • Participants
  • Parent commits e7219a5

Comments (0)

Files changed (1)

File savReaderWriter/unit_tests/test_SavReader_operators.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+##############################################################################
+## Rich comparison operators
+##############################################################################
+
+import unittest
+import sys
+from savReaderWriter import *
+
+class test_SavReader_typical_use(unittest.TestCase):
+    """Rich comparison operators"""
+
+    def setUp(self):
+        savFileName = "../savReaderWriter/test_data/german.sav"
+        self.data = SavReader(savFileName)
+
+    def test_rich_comp_eq(self):
+        """=="""
+        self.assertFalse(self.data == 3)
+        self.assertFalse(self.data == 2)
+        self.assertTrue(self.data == 1) 
+
+    def test_rich_comp_ge(self):
+        """>="""
+        self.assertFalse(self.data >= 3)
+        self.assertFalse(self.data >= 2)
+        self.assertTrue(self.data >= 1)
+
+    def test_rich_comp_le(self):
+        """<="""
+        self.assertTrue(self.data <= 3)
+        self.assertTrue(self.data <= 2)
+        self.assertTrue(self.data <= 1)
+
+    def test_rich_comp_gt(self):
+        """>"""
+        self.assertFalse(self.data > 3)
+        self.assertFalse(self.data > 2)
+        self.assertFalse(self.data > 1)
+    
+    def test_rich_comp_lt(self):
+        """<"""
+        self.assertTrue(self.data < 3)
+        self.assertTrue(self.data < 2)
+        self.assertFalse(self.data < 1)
+
+    def test_cmp_SavReader(self):
+        """Comparing objects of class SavReader"""
+        self.assertTrue(self.data == self.data)
+        self.assertFalse(self.data > self.data)
+        self.assertFalse(self.data < self.data)
+
+    @unittest.skipIf(sys.version_info[0] > 2, "cmp not available in Python3")
+    def test_cmp(self):
+        self.assertEquals(cmp(self.data, 0), 1)
+        self.assertEquals(cmp(self.data, 1), 0)
+        self.assertEquals(cmp(self.data, 2), -1)
+        self.assertEquals(cmp(self.data, self.data), 0) 
+
+    def tearDown(self):
+        self.data.close()
+
+if __name__ == "__main__":
+    unittest.main()