import unittest
from nose.tools import eq_, assert_not_equal
from helix.models.coordinate import Coordinate
from helix.models.subarray import Subarray


class SubarrayTest(unittest.TestCase):
    def setUp(self):
        self.subject = Subarray(
            subarray_number=1,
            origin=Coordinate(0, 1),
            required_seismic_anchors=1,
            start_row=1,
            size=144,
            weight=16322,
            column_count=2,
            row_count=4,
            column_counted_geometrically=True,
            row_counted_geometrically=True
        )

    def test_equality_identity(self):
        eq_(self.subject, self.subject)

    def test_equality_property(self):
        same_subarray = Subarray(
            subarray_number=1,
            origin=Coordinate(0, 1),
            required_seismic_anchors=1,
            start_row=1,
            size=144,
            weight=16322,
            column_count=2,
            row_count=4,
            column_counted_geometrically=True,
            row_counted_geometrically=True
        )
        eq_(self.subject, same_subarray)

    def test_equality_subobject(self):
        a = Subarray(
            subarray_number=1,
            origin=Coordinate(0, 1),
            required_seismic_anchors=1,
        )

        b = Subarray(
            subarray_number=1,
            origin=Coordinate(0, 1),
            required_seismic_anchors=1,
        )

        eq_(a, b)

        assert_not_equal(self.subject, a)

    def test_is_subset(self):
        a = Subarray(
            subarray_number=1,
            origin=Coordinate(0, 1),
            required_seismic_anchors=1,
        )

        b = Subarray(
            subarray_number=2,
            origin=Coordinate(0, 1),
            required_seismic_anchors=1,
        )
        assert a.is_subset(self.subject)

        assert not b.is_subset(self.subject)

    def test_repr(self):
        expected = '{' \
            '"column_count": 2, ' \
            '"column_counted_geometrically": true, ' \
            '"origin": {"rotation": 0.0, "x": 0, "y": 1}, ' \
            '"required_seismic_anchors": 1, ' \
            '"row_count": 4, ' \
            '"row_counted_geometrically": true, ' \
            '"size": 144, ' \
            '"start_row": 1, ' \
            '"subarray_number": 1, ' \
            '"weight": 16322' \
            '}'

        eq_(str(self.subject), expected)
