python类__lt__()的实例源码

test_richcmp.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_misbehavin(self):
        class Misb:
            def __lt__(self_, other): return 0
            def __gt__(self_, other): return 0
            def __eq__(self_, other): return 0
            def __le__(self_, other): self.fail("This shouldn't happen")
            def __ge__(self_, other): self.fail("This shouldn't happen")
            def __ne__(self_, other): self.fail("This shouldn't happen")
        a = Misb()
        b = Misb()
        self.assertEqual(a<b, 0)
        self.assertEqual(a==b, 0)
        self.assertEqual(a>b, 0)
test_richcmp.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_goodentry(self):
        # This test exercises the final call to PyObject_RichCompare()
        # in Objects/listobject.c::list_richcompare()
        class Good:
            def __lt__(self, other):
                return True

        x = [Good()]
        y = [Good()]

        for op in opmap["lt"]:
            self.assertIs(op(x, y), True)
test_richcmp.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __lt__(self, other):
        return self.x < other
test_richcmp.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __lt__(self, other):
        return Vector([a < b for a, b in zip(self.data, self.__cast(other))])
test_richcmp.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_misbehavin(self):
        class Misb:
            def __lt__(self_, other): return 0
            def __gt__(self_, other): return 0
            def __eq__(self_, other): return 0
            def __le__(self_, other): self.fail("This shouldn't happen")
            def __ge__(self_, other): self.fail("This shouldn't happen")
            def __ne__(self_, other): self.fail("This shouldn't happen")
            def __cmp__(self_, other): raise RuntimeError, "expected"
        a = Misb()
        b = Misb()
        self.assertEqual(a<b, 0)
        self.assertEqual(a==b, 0)
        self.assertEqual(a>b, 0)
        self.assertRaises(RuntimeError, cmp, a, b)
test_richcmp.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_goodentry(self):
        # This test exercises the final call to PyObject_RichCompare()
        # in Objects/listobject.c::list_richcompare()
        class Good:
            def __lt__(self, other):
                return True

        x = [Good()]
        y = [Good()]

        for op in opmap["lt"]:
            self.assertIs(op(x, y), True)
testutils.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def assert_array_less(x, y, err_msg='', verbose=True):
    """
    Checks that x is smaller than y elementwise.

    """
    assert_array_compare(operator.__lt__, x, y,
                         err_msg=err_msg, verbose=verbose,
                         header='Arrays are not less-ordered')
testutils.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def assert_array_less(x, y, err_msg='', verbose=True):
    """
    Checks that x is smaller than y elementwise.

    """
    assert_array_compare(operator.__lt__, x, y,
                         err_msg=err_msg, verbose=verbose,
                         header='Arrays are not less-ordered')
test_richcmp.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __lt__(self, other):
        return self.x < other
test_richcmp.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __lt__(self, other):
        return Vector([a < b for a, b in zip(self.data, self.__cast(other))])
test_richcmp.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def test_misbehavin(self):
        class Misb:
            def __lt__(self_, other): return 0
            def __gt__(self_, other): return 0
            def __eq__(self_, other): return 0
            def __le__(self_, other): self.fail("This shouldn't happen")
            def __ge__(self_, other): self.fail("This shouldn't happen")
            def __ne__(self_, other): self.fail("This shouldn't happen")
        a = Misb()
        b = Misb()
        self.assertEqual(a<b, 0)
        self.assertEqual(a==b, 0)
        self.assertEqual(a>b, 0)
test_richcmp.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_goodentry(self):
        # This test exercises the final call to PyObject_RichCompare()
        # in Objects/listobject.c::list_richcompare()
        class Good:
            def __lt__(self, other):
                return True

        x = [Good()]
        y = [Good()]

        for op in opmap["lt"]:
            self.assertIs(op(x, y), True)
lessThan.py 文件源码 项目:enterprise-fibonacci 作者: surrsurus 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def lessThan(typeA, typeB):
    if operator.__lt__(typeA.number.getNum(), typeB.number.getNum()):
        return True
    else:
        return False
obj.py 文件源码 项目:rvmi-rekall 作者: fireeye 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __lt__(self, other):
        return self.__comparator__(other, operator.__lt__)
test_arithmetic.py 文件源码 项目:py-flags 作者: pasztorpisti 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_lt(self):
        self._test_incompatible_types_fail(operator.__lt__)

        self.assertFalse(no_flags < no_flags)
        self.assertTrue(no_flags < all_flags)
        self.assertTrue(no_flags < f0)
        self.assertTrue(no_flags < f1)
        self.assertTrue(no_flags < f2)
        self.assertTrue(no_flags < f01)
        self.assertTrue(no_flags < f02)
        self.assertTrue(no_flags < f12)

        self.assertFalse(f0 < no_flags)
        self.assertTrue(f0 < all_flags)
        self.assertFalse(f0 < f0)
        self.assertFalse(f0 < f1)
        self.assertFalse(f0 < f2)
        self.assertTrue(f0 < f01)
        self.assertTrue(f0 < f02)
        self.assertFalse(f0 < f12)

        self.assertFalse(f01 < no_flags)
        self.assertTrue(f01 < all_flags)
        self.assertFalse(f01 < f0)
        self.assertFalse(f01 < f1)
        self.assertFalse(f01 < f2)
        self.assertFalse(f01 < f01)
        self.assertFalse(f01 < f02)
        self.assertFalse(f01 < f12)

        self.assertTrue(no_flags < all_flags)
        self.assertFalse(all_flags < all_flags)
        self.assertTrue(f0 < all_flags)
        self.assertTrue(f1 < all_flags)
        self.assertTrue(f2 < all_flags)
        self.assertTrue(f01 < all_flags)
        self.assertTrue(f02 < all_flags)
        self.assertTrue(f12 < all_flags)
testutils.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def assert_array_less(x, y, err_msg='', verbose=True):
    """
    Checks that x is smaller than y elementwise.

    """
    assert_array_compare(operator.__lt__, x, y,
                         err_msg=err_msg, verbose=verbose,
                         header='Arrays are not less-ordered')


问题


面经


文章

微信
公众号

扫码关注公众号