예제 #1
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)
예제 #2
0
    def test_dictionary_order_variant(self):
        """Test the expected hash is different if the dictionary order is
        different."""

        hash_input1 = {'one': 1, 'two': 2}
        hash_input2 = {'two': 2, 'one': 1}
        result1 = generate_hash(hash_input1)
        result2 = generate_hash(hash_input2)
        self.assertNotEqual(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.)], dtype=np.float32)
        hash_input64 = np.array([np.sqrt(2.)], 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 = "ad664992debed0bdf8f20804e4164691"
        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 = "4735f4a74dd17d27b383de504a87e324"
        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 = "d017763f19ef64f920c43fc57413d171"
        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 = "8e502f6a5b4a2e0f226649210895cebc"
        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 = "8c8846a4be49f7aab487353d9ecf623c"
        self.assertIsInstance(result, str)
        self.assertEqual(result, expected)