#This file was originally generated by PyScripter's unitest wizard

import unittest
import knn_module
from random import randrange

class TestGlobalFunctions(unittest.TestCase):


    def createusm(self,usernames):
        usm = {}
        for u1 in usernames:
            usm[u1] = {}
            i = 0
            for u2 in usernames:
                i = i +1
                if u1==u2:
                    usm[u1][u2] = 0
                    continue
                usm[u1][u2] = i

        return usm

    def setUp(self):
        usernames = ['John','Paul','Lin','Coo','Sin','Dub','May','June','Xin','Shin']
        self.usm_list = []
        for i in range(3):
            self.usm_list.append(self.createusm(usernames))

        pass

    def tearDown(self):
        pass

    def testknn(self):
        knearest = knn_module.knn(self.usm_list[0],'John',k=5)
        knearest = [x[0] for x in knearest]
        self.assertEqual(knearest,['Paul','Lin','Coo','Sin','Dub'])
        pass

    def testmulti_source_knn(self):
        knearest = knn_module.multi_source_knn('John',self.usm_list[0],self.usm_list[1],self.usm_list[2],k=5)
        knearest = [x[0] for x in knearest]
        self.assertCountEqual(knearest,['Paul','Lin','Coo','Sin','Dub'])
        pass

if __name__ == '__main__':
    unittest.main()
