Example #1
0
File: tests.py Project: Landi29/P8
 def test_graph_edit_distance3(self):
     '''
     tests graph_edit_distance on tets that have somthing in common
     '''
     edges = [
         'M:1234,U:1,5.0\n', 'M:5678,U:1,3.5\n', 'M:3456,U:2,2.0\n',
         'M:5678,U:2,1.0\n', 'M:1234,U:3,4.5\n', 'M:5678,U:3,4.0\n'
     ]
     moviedict = {
         'M:1234': [
             '1234', 'Toy Story (1995)', '1995',
             ['Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy']
         ],
         'M:5678': [
             '5678', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ],
         'M:3456': [
             '3456', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ]
     }
     test_tets = build_tet.build_tets(edges, moviedict,
                                      Paths.USER_NODES_PATH)
     self.assertEqual(
         compare_tet.graph_edit_distance(test_tets['U:1'],
                                         test_tets['U:3']), 1.5)
Example #2
0
File: tests.py Project: Landi29/P8
 def test_manhatten_distance2(self):
     '''
     tests manhatten_distance on most distant tets
     '''
     edges = [
         'M:1234,U:1,5.0\n', 'M:5678,U:1,3.5\n', 'M:3456,U:2,2.0\n',
         'M:5678,U:2,1.0\n', 'M:1234,U:3,3.5\n', 'M:5678,U:3,4.0\n'
     ]
     moviedict = {
         'M:1234': [
             '1234', 'Toy Story (1995)', '1995',
             ['Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy']
         ],
         'M:5678': [
             '5678', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ],
         'M:3456': [
             '3456', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ]
     }
     test_tets = build_tet.build_tets(edges, moviedict,
                                      Paths.USER_NODES_PATH)
     self.assertEqual(
         compare_tet.manhatten_distance(test_tets['U:1'], test_tets['U:2']),
         2)
Example #3
0
File: tests.py Project: Landi29/P8
    def test_grouping(self):
        '''
        tests grouping by tets of users
        '''
        edges = [
            'M:1234,U:1,5.0\n', 'M:5678,U:1,3.5\n', 'M:3456,U:2,2.0\n',
            'M:5678,U:2,1.0\n', 'M:1234,U:3,3.5\n', 'M:5678,U:3,4.0\n'
        ]
        moviedict = {
            'M:1234': [
                '1234', 'Toy Story (1995)', '1995',
                ['Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy']
            ],
            'M:5678': [
                '5678', 'Jumanji (1995)', '1995',
                ['Adventure', 'Children', 'Fantasy']
            ],
            'M:3456': [
                '3456', 'Jumanji (1995)', '1995',
                ['Adventure', 'Children', 'Fantasy']
            ]
        }
        test_tets = build_tet.build_tets(edges, moviedict,
                                         Paths.USER_NODES_PATH)
        groups = build_tet.grouping(test_tets)

        for group in groups:
            self.assertIn(group, [
                'Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy',
                'nohigh'
            ])

        self.assertEqual(len(groups['Adventure']), 2)
        self.assertEqual(len(groups['nohigh']), 1)
Example #4
0
File: tests.py Project: Landi29/P8
 def test_save_load_tets(self):
     '''
     tests if safe and load does construct equivalent trees
     '''
     tets_path = pathlib.Path.cwd() / 'TET_test_save.csv'
     edges = [
         'M:1234,U:1,5.0\n', 'M:5678,U:1,3.5\n', 'M:3456,U:2,2.0\n',
         'M:5678,U:2,1.0\n', 'M:1234,U:3,3.5\n', 'M:5678,U:3,4.0\n'
     ]
     moviedict = {
         'M:1234': [
             '1234', 'Toy Story (1995)', '1995',
             ['Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy']
         ],
         'M:5678': [
             '5678', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ],
         'M:3456': [
             '3456', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ]
     }
     test_tets = build_tet.build_tets(edges, moviedict,
                                      Paths.USER_NODES_PATH)
     build_tet.save_tets(test_tets, tets_path)
     load_tets = build_tet.load_tets(tets_path)
     for ktet in test_tets:
         tet1 = test_tets[ktet]
         tet2 = load_tets[ktet]
         self.assertEqual(tet1.getroot(), tet2.getroot())
         self.assertEqual(len(tet1.getchildren()), len(tet2.getchildren()))
         self.assertEqual(tet1.tostring(), tet2.tostring())
Example #5
0
File: tests.py Project: Landi29/P8
 def test_knn3(self):
     '''
     test knn lowered filter
     '''
     edges = [
         'M:1234,U:1,5.0\n', 'M:5678,U:1,3.5\n', 'M:3456,U:2,2.0\n',
         'M:5678,U:2,1.0\n', 'M:1234,U:3,4.5\n', 'M:5678,U:3,4.0\n'
     ]
     moviedict = {
         'M:1234': [
             '1234', 'Toy Story (1995)', '1995',
             ['Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy']
         ],
         'M:5678': [
             '5678', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ],
         'M:3456': [
             '3456', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ]
     }
     userdatabase = {
         'U:1': {
             'M:1234': 4.25
         },
         'U:2': {
             'M:3456': 2.0,
             'M:5678': 1.0
         },
         'U:3': {
             'M:1234': 4.5,
             'M:5678': 4.0
         }
     }
     test_tets = build_tet.build_tets(edges, moviedict,
                                      Paths.USER_NODES_PATH)
     preds = compare_tet.knn(test_tets['U:1'],
                             list(test_tets.values()),
                             user_database=userdatabase,
                             filterv=3)
     self.assertEqual(preds, [('M:5678', 3.8928571428571423),
                              ('M:3456', 4.75)])
Example #6
0
File: tests.py Project: Landi29/P8
 def test_pred1(self):
     '''
     test pred one film not seen by user no filter
     '''
     edges = [
         'M:1234,U:1,5.0\n', 'M:5678,U:1,3.5\n', 'M:3456,U:2,2.0\n',
         'M:5678,U:2,1.0\n', 'M:1234,U:3,4.5\n', 'M:5678,U:3,4.0\n'
     ]
     moviedict = {
         'M:1234': [
             '1234', 'Toy Story (1995)', '1995',
             ['Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy']
         ],
         'M:5678': [
             '5678', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ],
         'M:3456': [
             '3456', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ]
     }
     userdatabase = {
         'U:1': {
             'M:1234': 5.0,
             'M:5678': 3.5
         },
         'U:2': {
             'M:3456': 2.0,
             'M:5678': 1.0
         },
         'U:3': {
             'M:1234': 4.5,
             'M:5678': 4.0
         }
     }
     test_tets = build_tet.build_tets(edges, moviedict,
                                      Paths.USER_NODES_PATH)
     best = [[test_tets['U:2'], 54], [test_tets['U:3'], 67]]
     self.assertEqual(
         compare_tet.pred(test_tets['U:1'], best, userdatabase),
         [('M:3456', 4.75)])
Example #7
0
File: tests.py Project: Landi29/P8
 def test_build_tets(self):
     '''
     tests the constructions of TETs
     '''
     edges = [
         'M:1234,U:1,5.0\n', 'M:5678,U:1,3.5\n', 'M:1234,U:2,2.0\n',
         'M:5678,U:2,3.0\n', 'M:1234,U:3,3.5\n', 'M:5678,U:3,4.0\n'
     ]
     moviedict = {
         'M:1234': [
             '1234', 'Toy Story (1995)', '1995',
             ['Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy']
         ],
         'M:5678': [
             '5678', 'Jumanji (1995)', '1995',
             ['Adventure', 'Children', 'Fantasy']
         ]
     }
     test_tets = build_tet.build_tets(edges, moviedict,
                                      Paths.USER_NODES_PATH)
     self.assertEqual(len(test_tets), 3)
     for tetid in test_tets:
         self.assertIsInstance(test_tets[tetid], tet.TET)