Commit 5a02c0fd authored by Evin Dunn's avatar Evin Dunn
Browse files

Added tests for edge.__eq__(), edge. __repr__(), edge.symmetry_check(),...

Added tests for edge.__eq__(), edge. __repr__(), edge.symmetry_check(), edge.masks, all uncovered control methods
parent 64009b67
Loading
Loading
Loading
Loading
+20 −0
Changes for autocnet/control/tests/test_control.py: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -75,3 +75,23 @@ class TestC(unittest.TestCase):
    def test_to_dataframe(self):
        self.C.to_dataframe()

    def test_point_repr(self):
        expected = 0
        p = control.Point(expected)
        self.assertEqual(str(expected), p.__repr__())

    def test_correspondence_repr(self):
        expected = 0
        c = control.Correspondence(expected, 1, 1)
        self.assertEqual(str(expected), c.__repr__())

    def test_correspondence_eq(self):
        expected = 0
        c = control.Correspondence(expected, 1, 1)
        self.assertTrue(c == expected)

    def test_correspondence_hash(self):
        expected = 200
        c = control.Correspondence(expected, 1, 1)
        self.assertEqual(hash(expected), hash(c))
+5 −5
Changes for autocnet/graph/edge.py: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -118,14 +118,14 @@ class Edge(dict, MutableMapping):
        pass

    def symmetry_check(self):
        if hasattr(self, 'matches'):
        if self.matches:
            mask = od.mirroring_test(self.matches)
            self.masks = ('symmetry', mask)
        else:
            raise AttributeError('No matches have been computed for this edge.')

    def ratio_check(self, clean_keys=[], **kwargs):
        if hasattr(self, 'matches'):
        if self.matches:
            matches, mask = self.clean(clean_keys)
            distance_mask = od.distance_ratio(matches, **kwargs)
            self.masks = ('ratio', distance_mask)
@@ -152,7 +152,7 @@ class Edge(dict, MutableMapping):
        autocnet.transformation.transformations.FundamentalMatrix

        """
        if not hasattr(self, 'matches'):
        if not self.matches:
            raise AttributeError('Matches have not been computed for this edge')
            return
        matches, mask = self.clean(clean_keys)
@@ -197,7 +197,7 @@ class Edge(dict, MutableMapping):
               Boolean array of the outliers
        """

        if hasattr(self, 'matches'):
        if self.matches:
            matches = self.matches
        else:
            raise AttributeError('Matches have not been computed for this edge')
@@ -321,7 +321,7 @@ class Edge(dict, MutableMapping):
                     of mask keys to be used to reduce the total size
                     of the matches dataframe.
        """
        if not hasattr(self, 'matches'):
        if not self.matches:
            raise AttributeError('This edge does not yet have any matches computed.')

        matches, mask = self.clean(clean_keys)
+76 −0
Changes for autocnet/graph/tests/test_edge.py: 76 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ from unittest.mock import Mock
from unittest.mock import MagicMock

import ogr
import numpy as np
import pandas as pd
from plio.io import io_gdal

@@ -45,6 +46,24 @@ class TestEdge(unittest.TestCase):
    def test_masks(self):
        self.assertIsInstance(self.edge.masks, pd.DataFrame)

        keypoint_matches = [[0, 0, 1, 4],
                            [0, 1, 1, 3],
                            [0, 2, 1, 2],
                            [0, 3, 1, 1],
                            [0, 4, 1, 0]]

        # Test masks returns properly
        matches_df = pd.DataFrame(data=keypoint_matches, columns=['source_image', 'source_idx',
                                                                  'destination_image', 'destination_idx'])
        e = edge.Edge()
        e.matches = matches_df
        expected = pd.DataFrame(True, columns=['symmetry'],
                                index=matches_df.index)
        self.assertTrue(e.masks.equals(expected))

    def test_masks_setter(self):
        e = edge.Edge()


    def test_compute_fundamental_matrix(self):
        with self.assertRaises(AttributeError):
@@ -321,3 +340,60 @@ class TestEdge(unittest.TestCase):
        # Check key error thrown when string arg != "source" or "destination"
        with self.assertRaises(KeyError):
            e.get_keypoints("string", clean_keys)

    def test_eq(self):
        edge1 = edge.Edge()
        edge2 = edge.Edge()
        edge3 = edge.Edge()

        # Test edges w/ different keys are not equal, ones with same keys are
        edge1.__dict__["key"] = 1
        edge2.__dict__["key"] = 1
        edge3.__dict__["not_key"] = 1

        self.assertTrue(edge1 == edge2)
        self.assertFalse(edge1 == edge3)

        # Test edges with same keys, but diff df values
        edge1.__dict__["key"] = pd.DataFrame({'x': (0, 1, 2, 3, 4)})
        edge2.__dict__["key"] = pd.DataFrame({'x': (0, 1, 2, 3, 4)})
        edge3.__dict__["key"] = pd.DataFrame({'x': (0, 1, 2, 3, 5)})

        self.assertTrue(edge1 == edge2)
        self.assertFalse(edge1 == edge3)

        # Test edges with same keys, but diff np array vals
        # edge.__eq__ calls ndarray.all(), which checks that
        # all values in an array eval to true
        edge1.__dict__["key"] = np.array([True, True, True], dtype=np.bool)
        edge2.__dict__["key"] = np.array([True, True, True], dtype=np.bool)
        edge3.__dict__["key"] = np.array([True, True, False], dtype=np.bool)

        self.assertTrue(edge1 == edge2)
        self.assertFalse(edge1 == edge3)

    def test_repr(self):
        src = node.Node()
        dst = node.Node()
        masks = pd.DataFrame()

        e = edge.Edge()
        e.source = src
        e.destination = dst

        expected = """
        Source Image Index: {}
        Destination Image Index: {}
        Available Masks: {}
        """.format(src, dst, masks)

        self.assertEqual(expected, e.__repr__())

    def test_symmetry_check(self):
        # Matches is init to None
        e = edge.Edge()
        e.source = node.Node()
        e.destination = node.Node()
        # If there are no matches, should raise attrib err
        with (self.assertRaises(AttributeError)):
            e.symmetry_check()