Exemplo n.º 1
0
 def _create_features(self):
     return [
         FeatureF(),
         FeatureF([1, 1], 1, 2, 1),
         FeatureD(),
         FeatureD([1, 1], 1, 2, 1),
     ]
Exemplo n.º 2
0
    def test_get_default_color(self):
        dflt_color = RGBColor()
        f = FeatureD()
        nt.assert_equal(f.color, dflt_color)

        c = RGBColor(5, 32, 10)
        f = FeatureD([1, 1], rgb_color=c)
        nt.assert_equal(f.color, c)
Exemplo n.º 3
0
    def test_get_default_location(self):
        f = FeatureD()
        np.testing.assert_almost_equal(f.location, [0, 0])

        expected = [12.3, 643]
        f = FeatureD(loc=expected)
        np.testing.assert_almost_equal(f.location, expected)
        # iterable form
        f = FeatureD(loc=(12.3, 643))
        np.testing.assert_almost_equal(f.location, expected)
Exemplo n.º 4
0
    def test_set_and_get_color(self):
        expected = RGBColor(4, 20, 0)

        f = FeatureD()
        f.color = expected
        nt.assert_equal(f.color, expected)

        f = FeatureF()
        f.color = expected
        nt.assert_equal(f.color, expected)
Exemplo n.º 5
0
    def test_set_and_get_angle(self):
        f = FeatureD()
        expected = random.random()
        f.angle = expected
        nt.assert_almost_equal(f.angle, expected, 16)

        f = FeatureF()
        expected = random.random()
        f.angle = expected
        nt.assert_almost_equal(f.angle, expected, 6)
Exemplo n.º 6
0
    def test_set_and_get_location(self):
        f = FeatureD()
        expected = [random.random(), random.random()]
        f.location = expected
        # making sure that we went through the setter, and not just setting the
        # exact value to the property
        np.testing.assert_array_almost_equal(f.location, expected, 16)

        f = FeatureF()
        expected = [random.random(), random.random()]
        f.location = expected
        np.testing.assert_array_almost_equal(f.location, expected, 6)
Exemplo n.º 7
0
    def test_clone(self):
        features = [
            FeatureD(),
            FeatureD([1, 1], 1, 2, 1),
            FeatureF(),
            FeatureF([1, 1], 1, 2, 1),
        ]
        for f in features:
            f_clone = f.clone()
            nt.ok_(f == f_clone)

            # Changing one doesn't reflect in the other
            f_clone.scale = f.scale + 1
            nt.ok_(f != f_clone)
Exemplo n.º 8
0
    def test_to_str(self):
        expected_loc = np.array([random.random(), random.random()])
        expected_color = RGBColor(50, 60, 70)
        features = [
            FeatureD(expected_loc, 1.5, 2.5, 1.7, expected_color),
            FeatureF(expected_loc, 1.5, 2.5, 1.7, expected_color),
        ]

        for f in features:
            s = str(f).split()

            # Notice 6 is used here, as that is the
            # default precision used for C++ stringstreams
            np.testing.assert_almost_equal(float(s[0]), expected_loc[0],
                                           6)  # loc[0]
            np.testing.assert_almost_equal(float(s[1]), expected_loc[1],
                                           6)  # loc[1]
            np.testing.assert_almost_equal(float(s[2]), 1.5)  # mag
            np.testing.assert_almost_equal(float(s[3]), 2.5)  # scale
            np.testing.assert_almost_equal(float(s[4]), 1.7)  # angle
            nt.assert_equals(int(s[5]), expected_color.r)  # color.r
            nt.assert_equals(int(s[6]), expected_color.g)  # color.g
            nt.assert_equals(int(s[7]), expected_color.b)  # color.b

        print("Non default feature representation:", features[0], sep="\n")
Exemplo n.º 9
0
    def test_set_and_get_covar(self):
        f = FeatureD()

        expected = [[1, 2], [3, 4]]
        c = Covar2d(expected)
        f.covariance = c
        np.testing.assert_array_almost_equal(f.covariance.matrix(), c.matrix(),
                                             16)

        # And for floats...
        f = FeatureF()

        c = Covar2f(expected)
        f.covariance = c
        np.testing.assert_array_almost_equal(f.covariance.matrix(), c.matrix(),
                                             6)
Exemplo n.º 10
0
    def test_to_str_default(self):
        features = [FeatureD(), FeatureF()]
        for f in features:
            s = str(f).split()

            nt.assert_equals(s[0], "0")  # loc[0]
            nt.assert_equals(s[1], "0")  # loc[1]
            nt.assert_equals(s[2], "0")  # mag
            nt.assert_equals(s[3], "1")  # scale
            nt.assert_equals(s[4], "0")  # angle
            nt.assert_equals(s[5], "255")  # color.r
            nt.assert_equals(s[6], "255")  # color.g
            nt.assert_equals(s[7], "255")  # color.b

        print("Default feature representation:", features[0], sep="\n")
Exemplo n.º 11
0
    def test_copy_constructor(self):
        double_def = FeatureD()
        double_nondef = FeatureD([1, 1], 1, 2, 1)

        float_def = FeatureF()
        float_nondef = FeatureF([1, 1], 1, 2, 1)

        nt.ok_(FeatureD(double_def) == double_def)
        nt.ok_(FeatureD(double_nondef) == double_nondef)
        nt.ok_(FeatureF(double_def) != double_def)
        nt.ok_(FeatureF(double_nondef) != double_nondef)

        nt.ok_(FeatureF(float_def) == float_def)
        nt.ok_(FeatureF(float_nondef) == float_nondef)
        nt.ok_(FeatureD(float_def) != float_def)
        nt.ok_(FeatureD(float_nondef) != float_nondef)
Exemplo n.º 12
0
    def test_get_default_mag(self):
        f = FeatureD()
        nt.assert_equal(f.magnitude, 0)

        f = FeatureD([1, 1], mag=1.1)
        nt.assert_equal(f.magnitude, 1.1)
Exemplo n.º 13
0
    def test_get_default_scale(self):
        f = FeatureD()
        nt.assert_equal(f.scale, 1)

        f = FeatureD([1, 1], scale=2.1)
        nt.assert_equal(f.scale, 2.1)
Exemplo n.º 14
0
    def test_comparisons(self):
        nt.assert_false(FeatureD() == FeatureF())

        ctors = [FeatureD, FeatureF]
        for ctor in ctors:
            f1, f2 = ctor(), ctor()
            self.comparison_helper(f1, f2, True, True)

            # location
            f2.location = f1.location + 1
            self.comparison_helper(f1, f2)
            f2.location = f1.location
            self.comparison_helper(f1, f2, True, True)

            # magnitude
            f2.magnitude = f1.magnitude + 1
            self.comparison_helper(f1, f2)
            f2.magnitude = f1.magnitude
            self.comparison_helper(f1, f2, True, True)

            # scale
            f2.scale = f1.scale + 1
            self.comparison_helper(f1, f2)
            f2.scale = f1.scale
            self.comparison_helper(f1, f2, True, True)

            # angle
            f2.angle = f1.angle + 1
            self.comparison_helper(f1, f2, eq_except_angle=True)
            f2.angle = f1.angle
            self.comparison_helper(f1, f2, True, True)

            # covariance
            f2.covariance[0, 0] = f1.covariance[0, 0] + 1
            self.comparison_helper(f1, f2)
            f2.covariance[0, 0] = f1.covariance[0, 0]
            self.comparison_helper(f1, f2, True, True)

            # color
            f2.color = RGBColor(r=f1.color.r + 1)
            self.comparison_helper(f1, f2)
            f2.color = f1.color
            self.comparison_helper(f1, f2, True, True)

            # Try many at once
            f2.location = f1.location + 1
            self.comparison_helper(f1, f2)

            f2.magnitude = f1.magnitude + 1
            self.comparison_helper(f1, f2)

            f2.scale = f1.scale + 1
            self.comparison_helper(f1, f2)

            f2.angle = f1.angle + 1
            self.comparison_helper(f1, f2)

            f2.covariance[0, 0] = f1.covariance[0, 0] + 1
            self.comparison_helper(f1, f2)

            f2.color = RGBColor(r=f1.color.r + 1)
            self.comparison_helper(f1, f2)
Exemplo n.º 15
0
    def test_get_typename(self):
        f = FeatureD()
        nt.assert_equal(f.type_name, "d")

        f = FeatureF()
        nt.assert_equal(f.type_name, "f")
Exemplo n.º 16
0
    def test_new(self):
        f1 = FeatureF([1, 1], 1, 2, 1)
        f2 = FeatureF()

        f3 = FeatureD([1, 1], 1, 2, 1)
        f4 = FeatureD()
Exemplo n.º 17
0
    def test_get_default_angle(self):
        f = FeatureD()
        nt.assert_equal(f.angle, 0)

        f = FeatureD([1, 1], angle=1.1)
        nt.assert_equal(f.angle, 1.1)
Exemplo n.º 18
0
 def test_overriden_features(self):
     nt.assert_equals(ConcreteFeatureSet().features(), [FeatureD([1, 2], 3, 4, 5)])
Exemplo n.º 19
0
 def test_get_default_covar(self):
     dflt_covar = Covar2d()
     f = FeatureD()
     np.testing.assert_array_equal(f.covariance.matrix(),
                                   dflt_covar.matrix())
Exemplo n.º 20
0
 def features(self):
     return [FeatureD([1, 2], 3, 4, 5)]