# Path: databench/utils.py
# def json_encoder_default(obj):
#     """Handle more data types than the default JSON encoder.
# 
#     Specifically, it treats a `set` and a `numpy.array` like a `list`.
# 
#     Example usage: ``json.dumps(obj, default=json_encoder_default)``
#     """
#     if np is not None and hasattr(obj, 'size') and hasattr(obj, 'dtype'):
#         if obj.size == 1:
#             if np.issubdtype(obj.dtype, np.integer):
#                 return int(obj)
#             elif np.issubdtype(obj.dtype, np.floating):
#                 return float(obj)
# 
#     if isinstance(obj, set):
#         return list(obj)
#     elif hasattr(obj, 'to_native'):
#         # DatastoreList, DatastoreDict
#         return obj.to_native()
#     elif hasattr(obj, 'tolist') and hasattr(obj, '__iter__'):
#         # for np.array
#         return obj.tolist()
# 
#     return obj


from databench.utils import json_encoder_default
import json
import unittest


class TestJsonEncoder(unittest.TestCase):
    def test_nan(self):
        data = json.dumps(float('NaN'), default=json_encoder_default)
        self.assertEqual(data, 'NaN')

    def test_inf(self):
        data = json.dumps(float('inf'), default=json_encoder_default)
        self.assertEqual(data, 'Infinity')

    def test_neg_inf(self):
        data = json.dumps(float('-inf'), default=json_encoder_default)
        self.assertEqual(data, '-Infinity')

    def test_list(self):
        data = json.dumps([1, float('inf')], default=json_encoder_default)
        self.assertEqual(data, '[1, Infinity]')

    def test_dict(self):
        data = json.loads(json.dumps({'one': 1, 'inf': float('inf')},
                                     default=json_encoder_default))
        self.assertEqual(data, {'one': 1, 'inf': float('inf')})

    def test_set(self):
        data = json.dumps({1, float('inf')}, default=json_encoder_default)
        self.assertEqual(data, '[1, Infinity]')

    def test_tuple(self):

# Path: databench/utils.py
# def json_encoder_default(obj):
#     """Handle more data types than the default JSON encoder.
# 
#     Specifically, it treats a `set` and a `numpy.array` like a `list`.
# 
#     Example usage: ``json.dumps(obj, default=json_encoder_default)``
#     """
#     if np is not None and hasattr(obj, 'size') and hasattr(obj, 'dtype'):
#         if obj.size == 1:
#             if np.issubdtype(obj.dtype, np.integer):
#                 return int(obj)
#             elif np.issubdtype(obj.dtype, np.floating):
#                 return float(obj)
# 
#     if isinstance(obj, set):
#         return list(obj)
#     elif hasattr(obj, 'to_native'):
#         # DatastoreList, DatastoreDict
#         return obj.to_native()
#     elif hasattr(obj, 'tolist') and hasattr(obj, '__iter__'):
#         # for np.array
#         return obj.tolist()
# 
#     return obj


# Path: databench/tests/test_json_encoder.py
from databench.utils import json_encoder_default
import json
import unittest



class TestJsonEncoder(unittest.TestCase):
    def test_nan(self):
        data = json.dumps(float('NaN'), default=json_encoder_default)
        self.assertEqual(data, 'NaN')

    def test_inf(self):
        data = json.dumps(float('inf'), default=json_encoder_default)
        self.assertEqual(data, 'Infinity')

    def test_neg_inf(self):
        data = json.dumps(float('-inf'), default=json_encoder_default)
        self.assertEqual(data, '-Infinity')

    def test_list(self):
        data = json.dumps([1, float('inf')], default=json_encoder_default)
        self.assertEqual(data, '[1, Infinity]')

    def test_dict(self):
        data = json.loads(json.dumps({'one': 1, 'inf': float('inf')},
                                     default=json_encoder_default))
        self.assertEqual(data, {'one': 1, 'inf': float('inf')})

    def test_set(self):
        data = json.dumps({1, float('inf')}, default=json_encoder_default)
        self.assertEqual(data, '[1, Infinity]')

    def test_tuple(self):

        data = json.dumps((1, float('inf')), default=json_encoder_default)