import json
import os
import unittest

import mock
import numpy as np
import pandas as pd
from ddt import ddt, unpack, data

from .. import io
from .. import models

from . import FIXTURES_DIR


class TestCase(unittest.TestCase):

    def get_fixture_data(self, fname):
        path = os.path.join(FIXTURES_DIR, fname)
        with open(path) as f:
            return json.load(f)


@ddt
class TestBinWM(TestCase):

    model_data_fixtures = {
        'Minimal Example': 'case__minimal_example.json',
        'Motorcycle Helmet': 'case__motorcycle_helmet.json',
        'Simple Aircraft': 'case__simple_aircraft.json'
    }

    def setup_binary_weighting_matrix(self, key):
        fixture_fname = self.model_data_fixtures[key]
        data = self.get_fixture_data(fixture_fname)
        bwm = models.BinWM(*data['requirements'])
        bwm._matrix = np.array(data['binary_matrix'])
        bwm.label = "My Requirements"
        return bwm

    def test_score__motorcycle_helmet(self):
        bwm = self.setup_binary_weighting_matrix('Motorcycle Helmet')

        np.testing.assert_allclose(
            bwm.score,
            np.array([0.095, 0.286, 0.143,  0.143, 0.143, 0.19]),
            atol=0.01
        )

    def test_score__simple_aircraft(self):
        bwm = self.setup_binary_weighting_matrix('Simple Aircraft')

        np.testing.assert_allclose(