【问题标题】:AssertEqual Doesnt Throw an Error even if Values are Different即使值不同,AssertEqual 也不会引发错误
【发布时间】:2018-11-04 21:51:04
【问题描述】:

我在 Python 中有这段代码

import unittest



class AES_TEST(unittest.TestCase):


    def test_encryption(self):
        print('Encryption : ')
        plaintext = 0x3243f6a8885a308d313198a2e0370734
        encrypted = 75960790320075369159181001580855561010
        print(encrypted)
        print('0x3925841d02dc09fbdc118597196a0b32')

        self.assertEqual(encrypted, 0x3925841d02dc09fbdc118597196a0b32)

    def test_decryption(self):
        print('Decryption : ')
        ciphertext = 0x3925841d02dc09fbdc118597196a0b32
        decrypted = self.AES.decrypt(ciphertext)
        decrypted = 66814286504060421741230023322616923956
        print(decrypted)
        print('0x3243f6a8885a308d313198a2e0370734')


        self.assertEqual(decrypted, 0x3243f6a8885a308d313198a2e0370734)

if __name__ == '__main__':
    unittest.main()

为什么它不抛出错误?为什么 encrypted 变量等于 0x3925841d02dc09fbdc118597196a0b32 ,而实际上它们具有不同的值?在decryption 变量中也观察到相同的行为。

【问题讨论】:

  • 这些数字是相等的,但只是以十六进制值(前缀为0x)和十进制值(无前缀)的方式表示。 0xa == 10

标签: python numbers hex decimal assertion


【解决方案1】:

他们是平等的。

数字前面的 0x 表示以 16 为基数(十六进制)。如果您使用calculator0x3925841d02dc09fbdc118597196a0b32 转换为十进制格式,您将看到它与该代码块中分配给它的值相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-29
    • 2012-10-19
    • 1970-01-01
    相关资源
    最近更新 更多