source: orange/Orange/testing/unit/tests/test_mds.py @ 10655:a228b55811a4

Revision 10655:a228b55811a4, 1.1 KB checked in by markotoplak, 2 years ago (diff)

Moved testing from utils into testing.

Line 
1from Orange.testing import testing
2from Orange.testing.testing import test_on_data, datasets_driven
3
4try:
5    import unittest2 as unittest
6except:
7    import unittest
8from Orange.projection import mds
9from Orange.distance import distance_matrix, Euclidean
10
11@datasets_driven
12class TestMDS(unittest.TestCase):
13
14    @test_on_data
15    def test_mds_on(self, data):
16        matrix = distance_matrix(data, Euclidean)
17        self.__mds_test_helper(matrix, proj_dim=1)
18        self.__mds_test_helper(matrix, proj_dim=2)
19        self.__mds_test_helper(matrix, proj_dim=3)
20
21    def __mds_test_helper(self, matrix, proj_dim):
22        proj = mds.MDS(matrix, dim=proj_dim)
23        proj.torgerson()
24        proj.smacof_step()
25        proj.run(100)
26        proj.smacof_step()
27        self.assertEquals(len(proj.points), matrix.dim)
28        self.assertTrue(all(len(p) == proj_dim for p in proj.points))
29        self.assertEquals(matrix, proj.distances,
30                        "The input distance matrix was changed in place")
31        self.assertEquals(matrix.dim, proj.projected_distances.dim)
32
33
34
35if __name__ == "__main__":
36    unittest.main()
Note: See TracBrowser for help on using the repository browser.