Exemplo n.º 1
0
 def setUp(self):
     self.data = [
         {"age": 10, "uuid": "id1"},
         {"age": 20, "uuid": "id2"},
         {"age": 30, "uuid": "id3"}
     ]
     self.searcher = SearchEngine(self.data)
Exemplo n.º 2
0
class DataSearchBestFit(TestCase):
    def setUp(self):
        self.data = [
            {"age": 10, "uuid": "id1"},
            {"age": 20, "uuid": "id2"},
            {"age": 30, "uuid": "id3"},
            {"age": 40, "uuid": "id4"},
            {"age": 50, "uuid": "id5"}
        ]
        self.searcher = SearchEngine(self.data)

    def test_search_function(self):
        result = self.searcher.bestfit(data=self.data)
        ages = [i['age'] for i in result]
        self.assertEqual(ages[0],30)
        self.assertTrue(ages[1] == 20 or ages[1] == 40)
        self.assertEqual(ages[-1],50)

    def test_search_order(self):
        result = self.searcher.search(min=0,max=60)
        ages = [i['age'] for i in result]
        self.assertEqual(ages[0],30)
        self.assertTrue(ages[1] == 20 or ages[1] == 40)
        self.assertEqual(ages[-1],50)
Exemplo n.º 3
0
class DataSearch(TestCase):
    def setUp(self):
        self.data = [
            {"age": 10, "uuid": "id1"},
            {"age": 20, "uuid": "id2"},
            {"age": 30, "uuid": "id3"}
        ]
        self.searcher = SearchEngine(self.data)

    def test_simple_search(self):
        result = self.searcher.search(max=11)
        self.assertEqual(len(result), 1)

    def test_simple_search_results(self):
        result = self.searcher.search(max=11)
        result = result[0]
        self.assertEqual(result['age'], 10)

    def test_simple_search_results_multiple_results(self):
        result = self.searcher.search(max=21)
        self.assertEqual(len(result), 2)

    def test_simple_search_no_params_results_shows_all(self):
        result = self.searcher.search()
        self.assertEqual(len(result), 3)

    def test_max_age_search_has_correct_ids(self):
        result = self.searcher.search(max=21)
        ids = [i['uuid'] for i in result]
        self.assertTrue('id1' in ids)
        self.assertTrue('id2' in ids)
        self.assertTrue('id3' not in ids)

    def test_max_and_min_search_count(self):
        result = self.searcher.search(max=21, min=11)
        self.assertEqual(len(result), 1)

    def test_max_and_min_search_id(self):
        result = self.searcher.search(max=21, min=11)
        self.assertEqual(result[0]['uuid'], 'id2')