# Path: covest/data.py
# class InvalidFormatException(Exception):
#     def __init__(self, fname):
#         self.fname = fname
# 
#     def __str__(self):
#         return 'Unable to parse %s. Unsupported format.' % self.fname
# 
# def load_histogram(fname):
#     hist = dict()
#     meta = dict()
#     with open(fname, 'r') as f:
#         for line in f:
#             if line[0] == '#':
#                 try:
#                     k, v = line[1:].strip().split(':')
#                     meta[k] = v
#                 except IndexError:
#                     pass
#             else:
#                 try:
#                     l = line.split()
#                     i = int(l[0])
#                     cnt = int(l[1])
#                     hist[i] = cnt
#                 except (ValueError, KeyError):
#                     raise InvalidFormatException(fname)
#     return hist, meta
# 
# def save_histogram(hist, fname, meta=None):
#     with open(fname, 'w') as f:
#         if meta:
#             for k, v in meta.items():
#                 f.write('#{}:{}\n'.format(k, v))
#         for k, v in hist.items():
#             f.write('%d %d\n' % (k, v))


import os
import tempfile
import unittest
    import sys
from covest.data import InvalidFormatException, load_histogram, save_histogram
from pathlib import Path
            13: 5,
            14: 9,
            15: 1,
        }

        hist, meta = load_histogram(str(self.folder / 'simulated_c10_e0.05_r100_k21.hist'))
        self.assertDictEqual(hist, true_histogram)

    def test_load_sparse_histogram(self):
        true_histogram = {
            1: 5311035,
            2: 310620,
            3: 223796,
            4: 150045,
            6: 37443,
            7: 14628,
            8: 5075,
            12: 22,
            13: 5,
            15: 1,
        }

        hist, meta = load_histogram(str(self.folder / 'simulated_c10_e0.05_r100_k21_sparse.hist'))
        self.assertDictEqual(hist, true_histogram)

    def test_load_nonexisting_file(self):
        with self.assertRaises(FileNotFoundError):
            load_histogram('nonexisting_histogram.hist')

    def test_load_invalid_histogram(self):

# Path: covest/data.py
# class InvalidFormatException(Exception):
#     def __init__(self, fname):
#         self.fname = fname
# 
#     def __str__(self):
#         return 'Unable to parse %s. Unsupported format.' % self.fname
# 
# def load_histogram(fname):
#     hist = dict()
#     meta = dict()
#     with open(fname, 'r') as f:
#         for line in f:
#             if line[0] == '#':
#                 try:
#                     k, v = line[1:].strip().split(':')
#                     meta[k] = v
#                 except IndexError:
#                     pass
#             else:
#                 try:
#                     l = line.split()
#                     i = int(l[0])
#                     cnt = int(l[1])
#                     hist[i] = cnt
#                 except (ValueError, KeyError):
#                     raise InvalidFormatException(fname)
#     return hist, meta
# 
# def save_histogram(hist, fname, meta=None):
#     with open(fname, 'w') as f:
#         if meta:
#             for k, v in meta.items():
#                 f.write('#{}:{}\n'.format(k, v))
#         for k, v in hist.items():
#             f.write('%d %d\n' % (k, v))


# Path: tests/test_data_manipulation.py
import os
import tempfile
import unittest
    import sys
from covest.data import InvalidFormatException, load_histogram, save_histogram
from pathlib import Path

            13: 5,
            14: 9,
            15: 1,
        }

        hist, meta = load_histogram(str(self.folder / 'simulated_c10_e0.05_r100_k21.hist'))
        self.assertDictEqual(hist, true_histogram)

    def test_load_sparse_histogram(self):
        true_histogram = {
            1: 5311035,
            2: 310620,
            3: 223796,
            4: 150045,
            6: 37443,
            7: 14628,
            8: 5075,
            12: 22,
            13: 5,
            15: 1,
        }

        hist, meta = load_histogram(str(self.folder / 'simulated_c10_e0.05_r100_k21_sparse.hist'))
        self.assertDictEqual(hist, true_histogram)

    def test_load_nonexisting_file(self):
        with self.assertRaises(FileNotFoundError):
            load_histogram('nonexisting_histogram.hist')

    def test_load_invalid_histogram(self):

        with self.assertRaises(InvalidFormatException):