コード例 #1
0
    def test_dictionary_order_invariant(self):
        """Test the expected hash is the same for different dict ordering."""

        hash_input1 = {"one": 1, "two": 2}
        hash_input2 = {"two": 2, "one": 1}
        result1 = generate_hash(hash_input1)
        result2 = generate_hash(hash_input2)
        self.assertEqual(result1, result2)
コード例 #2
0
    def test_equivalent_input_gives_equivalent_hash(self):
        """Test that creating a hash twice using the same input results in the
        same hash being generated."""

        cube = set_up_variable_cube(np.ones((3, 3)).astype(np.float32))
        hash_input = cube.coord("latitude")
        result1 = generate_hash(hash_input)
        result2 = generate_hash(hash_input)
        self.assertEqual(result1, result2)
コード例 #3
0
    def test_numpy_array_type_variant(self):
        """Test the expected hash is different if the numpy array type is
        different."""

        hash_input32 = np.array([np.sqrt(2.0)], dtype=np.float32)
        hash_input64 = np.array([np.sqrt(2.0)], dtype=np.float64)
        result32 = generate_hash(hash_input32)
        result64 = generate_hash(hash_input64)
        self.assertNotEqual(result32, result64)
コード例 #4
0
    def test_cube_input(self):
        """Test the expected hash is returned when input is a cube."""

        hash_input = set_up_variable_cube(np.ones((3, 3)).astype(np.float32))
        result = generate_hash(hash_input)
        expected = "4d82994200559c90234b0186bccc59b9b9d6436284f29bab9a15dc97172d1fb8"
        self.assertIsInstance(result, str)
        self.assertEqual(result, expected)
コード例 #5
0
    def test_dictionary_input(self):
        """Test the expected hash is returned when input is a dictionary."""

        hash_input = {"one": 1, "two": 2}
        result = generate_hash(hash_input)
        expected = "c261139b6339f880f4f75a3bf5a08f7c2d6f208e2720760f362e4464735e3845"
        self.assertIsInstance(result, str)
        self.assertEqual(result, expected)
コード例 #6
0
    def test_numeric_input(self):
        """Test the expected hash is returned when input is a numeric type."""

        hash_input = 1000
        result = generate_hash(hash_input)
        expected = "40510175845988f13f6162ed8526f0b09f73384467fa855e1e79b44a56562a58"
        self.assertIsInstance(result, str)
        self.assertEqual(result, expected)
コード例 #7
0
    def test_string_input(self):
        """Test the expected hash is returned when input is a string type."""

        hash_input = "this is a test string"
        result = generate_hash(hash_input)
        expected = "7a5a4f1716b08d290d5782da904cc076315376889e9bf641ae527889704fd314"
        self.assertIsInstance(result, str)
        self.assertEqual(result, expected)
コード例 #8
0
    def test_coordinate_input(self):
        """Test the expected hash is returned when input is a cube
        coordinate."""

        cube = set_up_variable_cube(np.ones((3, 3)).astype(np.float32))
        hash_input = cube.coord("latitude")
        result = generate_hash(hash_input)
        expected = "ee6a057f5eeef0e94a853cfa98f3c22b121dda31ada3378ce9466e48d06f9887"
        self.assertIsInstance(result, str)
        self.assertEqual(result, expected)
コード例 #9
0
    def test_coordinate_input(self):
        """Test the expected hash is returned when input is a cube
        coordinate."""

        cube = set_up_variable_cube(np.ones((3, 3)).astype(np.float32))
        hash_input = cube.coord("latitude")
        result = generate_hash(hash_input)
        expected = "62267c5827656790244ef2f26b708a1be5dcb491e4ae36b9db9b47c2aaaadf7e"
        self.assertIsInstance(result, str)
        self.assertEqual(result, expected)