# Path: veidt/metrics.py
# def get(identifier):
#     if isinstance(identifier, dict):
#         config = {'class_name': identifier['class_name'], 'config': identifier['config']}
#         return deserialize(config)
#     elif isinstance(identifier, str):
#         return deserialize(identifier)
#     elif callable(identifier):
#         return identifier
#     else:
#         raise ValueError('Could not interpret '
#                          'metric function identifier:', identifier)
# 
# def serialize(metric):
#     return serialize_veidt_object(metric)
# 
# def deserialize(config):
#     return deserialize_veidt_object(config,
#                                     module_objects=globals(),
#                                     printable_module_name='metric function')


import unittest
import numpy as np
import os
from veidt.metrics import get, serialize, deserialize
class TestMetrics(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.x1 = np.array([1, 2, 3])
        cls.x2 = np.array([4, 5, 6])
        cls.x3 = np.array([1, 1, 1])
        cls.x4 = np.array([1, 2, 3])

    def test_mae(self):
        mae = get('mae')
        self.assertEqual(mae(self.x1, self.x2), 3)
        self.assertAlmostEqual(mae(self.x3, self.x4), 1)

    def test_mse(self):
        mse = get('mse')
        self.assertEqual(mse(self.x1, self.x2), 9)
        self.assertAlmostEqual(mse(self.x3, self.x4), 5. / 3)

    def test_binary_accuracy(self):
        binary_accuracy = get('binary_accuracy')
        self.assertAlmostEqual(binary_accuracy([0, 1, 0], [1, 1, 1]), 1./3)

        self.assertAlmostEqual(get({"class_name": "binary_accuracy",
                                    "config": {"y_true": [0, 1, 0],
                                               "y_pred": [1, 1, 1]}}), 1/3)
        self.assertEqual(get(test_func)(), 1)
        with self.assertRaises(ValueError) as context:
            get({"class_name":'not existing', "config": "not existing"})

    def test_deserialization(self):

# Path: veidt/metrics.py
# def get(identifier):
#     if isinstance(identifier, dict):
#         config = {'class_name': identifier['class_name'], 'config': identifier['config']}
#         return deserialize(config)
#     elif isinstance(identifier, str):
#         return deserialize(identifier)
#     elif callable(identifier):
#         return identifier
#     else:
#         raise ValueError('Could not interpret '
#                          'metric function identifier:', identifier)
# 
# def serialize(metric):
#     return serialize_veidt_object(metric)
# 
# def deserialize(config):
#     return deserialize_veidt_object(config,
#                                     module_objects=globals(),
#                                     printable_module_name='metric function')


# Path: veidt/tests/test_metrics.py
import unittest
import numpy as np
import os
from veidt.metrics import get, serialize, deserialize

class TestMetrics(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.x1 = np.array([1, 2, 3])
        cls.x2 = np.array([4, 5, 6])
        cls.x3 = np.array([1, 1, 1])
        cls.x4 = np.array([1, 2, 3])

    def test_mae(self):
        mae = get('mae')
        self.assertEqual(mae(self.x1, self.x2), 3)
        self.assertAlmostEqual(mae(self.x3, self.x4), 1)

    def test_mse(self):
        mse = get('mse')
        self.assertEqual(mse(self.x1, self.x2), 9)
        self.assertAlmostEqual(mse(self.x3, self.x4), 5. / 3)

    def test_binary_accuracy(self):
        binary_accuracy = get('binary_accuracy')
        self.assertAlmostEqual(binary_accuracy([0, 1, 0], [1, 1, 1]), 1./3)

        self.assertAlmostEqual(get({"class_name": "binary_accuracy",
                                    "config": {"y_true": [0, 1, 0],
                                               "y_pred": [1, 1, 1]}}), 1/3)
        self.assertEqual(get(test_func)(), 1)
        with self.assertRaises(ValueError) as context:
            get({"class_name":'not existing', "config": "not existing"})

    def test_deserialization(self):

        mae = deserialize("mae")