コード例 #1
0
    def test_ascii_sq_key_non_string(self):
        self.assertRaises(TypeError,
                          lambda: hash_functions.h_ascii_sq(int(4), 8))

        self.assertRaises(TypeError,
                          lambda: hash_functions.h_ascii_sq(float(4), 8))

        self.assertRaises(TypeError,
                          lambda: hash_functions.h_ascii_sq([5, 6], 8))

        self.assertRaises(TypeError,
                          lambda: hash_functions.h_ascii_sq(True, 8))
コード例 #2
0
    def test_ascii_sq_length_non_int(self):
        self.assertRaises(
            TypeError,
            lambda: hash_functions.h_ascii_sq('string', float(420.69)))

        self.assertRaises(
            TypeError, lambda: hash_functions.h_ascii_sq('string', 'string'))

        self.assertRaises(TypeError,
                          lambda: hash_functions.h_ascii_sq('string', True))

        self.assertRaises(TypeError,
                          lambda: hash_functions.h_ascii_sq('string', [9, 10]))
コード例 #3
0
 def test_ascii_sq(self):
     letters = string.ascii_lowercase + string.ascii_uppercase
     for i in range(100):
         sum_sq = 0
         test_length = rdm.randint(1, 100)
         test_key = ''
         for j in range(rdm.randint(1, 100)):
             letter = rdm.choice(letters)
             test_key += letter
         for k in range(len(test_key)):
             sum_sq += ord(test_key[k])**2
         r = sum_sq % test_length
         self.assertEqual(hash_functions.h_ascii_sq(test_key, test_length),
                          r)
コード例 #4
0
 def test_ascii_sq_null(self):
     self.assertRaises(TypeError, lambda: hash_functions.h_ascii_sq())
コード例 #5
0
 def test_ascii_sq_key_none(self):
     self.assertEqual(hash_functions.h_ascii_sq(None, 5), None)
コード例 #6
0
 def test_ascii_sq_N_none(self):
     self.assertEqual(hash_functions.h_ascii_sq('hello', None), None)
コード例 #7
0
 def test_ascii_sq_neg_table(self):
     self.assertEqual(hash_functions.h_ascii_sq('string', -42), None)
コード例 #8
0
 def test_ascii_sq_zero_table(self):
     self.assertEqual(hash_functions.h_ascii_sq('string', 0), None)