コード例 #1
0
ファイル: test_list.py プロジェクト: spacedentist/pyimmutable
 def test_count(self):
     il = ImmutableList([3, "two", 1, 3, "two", 3, 2])
     self.assertEqual(il.count(0), 0)
     self.assertEqual(il.count(1), 1)
     self.assertEqual(il.count("two"), 2)
     self.assertEqual(il.count(3), 3)
     self.assertEqual(il.count(3.0), 0)
コード例 #2
0
    def test_strict_equality(self):
        """
        pyimmutable has stricter equality requirements than usual.
        """

        l1 = ImmutableList([1, 2, 3])
        l2 = ImmutableList([1, 2, 3.0])

        self.assertFalse(l1 is l2)
        self.assertNotEqual(l1, l2)

        self.assertEqual(l1.count(3), 1)
        self.assertEqual(l1.count(3.0), 0)
        self.assertEqual(l2.count(3), 0)
        self.assertEqual(l2.count(3.0), 1)

        self.assertEqual(l1.index(3), 2)
        self.assertEqual(l2.index(3.0), 2)

        with self.assertRaises(ValueError):
            l1.index(3.0)

        with self.assertRaises(ValueError):
            l2.index(3)