Commit fd9b529a authored by kberry's avatar kberry
Browse files

cleaned up and added test

parent 7e2c2567
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
import unittest
import pandas as pd
import numpy as np

from .. import utils

class TestUtils(unittest.TestCase):
    def setUp(self):
        pass

    def test_slopes(self):
        x1 = pd.DataFrame({'x': np.arange(1, 11),
                           'y': np.arange(1, 11)})
        x2 = pd.DataFrame({'x': np.arange(6, 16),
                           'y': np.arange(11, 21)})

        slope = utils.calculate_slope(x1, x2)
        self.assertEqual(slope.slope[0], 2)
+8 −20
Original line number Diff line number Diff line
@@ -36,34 +36,22 @@ def file_search(searchdir,searchstring):
    filelist=np.array(filelist)
    return filelist    

# TODO: FIXME
def calculate_slope(x1, x2, y1, y2):
    """

    Parameters
    ----------
    x1
    x2
    y1
    y2

    Returns
    -------

    """
    return (x2-x1)/(y2-y1)

def calculate_slope(x1, x2):
    """
    Calculates the 2-dimensional slope between the points in two dataframes each containing two columns ['x', 'y']
    The slope is calculated from x1 to x2.

    Parameters
    ----------
    x1
    x2
    x1 : dataframe
         Each row is a point with columns ['x', 'y']
    x2 : dataframe
        Each row is a point with columns ['x', 'y']

    Returns
    -------

    : dataframe
      A dataframe with the slope between x1 and x2 for each row.
    """
    slopes = (x2.y.values - x1.y.values)/(x2.x.values-x1.x.values)
    return pd.DataFrame(slopes, columns=['slope'])
+0 −10
Original line number Diff line number Diff line
@@ -64,16 +64,6 @@ class TestFundamentalMatrix(unittest.TestCase):

        self.assertIsInstance(F.error, pd.DataFrame)

        # TODO: FIXME

        df1 = pd.DataFrame(fp, columns=['x', 'y'])
        df2 = pd.DataFrame(tp.T[:, :2], columns=['x', 'y'])
        slopes = utils.calculate_slope(df1, df2)

        F.refine(arr=slopes)

        self.assertTrue(False)

        # This should raise an error.
        F.refine()
        self.assertIsInstance(F.error, pd.DataFrame)
+0 −1
Original line number Diff line number Diff line
@@ -227,7 +227,6 @@ class FundamentalMatrix(TransformationMatrix):

        # Update the current state
        self[:] = fmatrix
    #    self.mask[self.mask == True] = mask
        self.mask = mask

        # Update the action stack
+824 −69

File changed.

Preview size limit exceeded, changes collapsed.