Пример #1
0
    def test_sort_and_pick_output(self):
        """test sort and pick function to see if outputs are lists, and that the last value of the list is not conv or clean 
        in the wrong bucket, test the length of the lists."""
        path = os.path.dirname(__file__)
        path_test = os.path.join(path, 'Arranged_Data', 'test_dataset.csv')
        test = pd.read_csv(path_test)
        prec = test.iloc[3, 1]
        ts = test.iloc[3, 2]
        tw = test.iloc[3, 3]
        ws = test.iloc[3, 4]
        vote = ease.rf(prec, ts, tw, ws)
        avg_cap = ease.avg_capacity(vote)
        possible_type = ease.possible_type(avg_cap)
        conv, clean = ease.clean_or_conv(possible_type)
        output_conv = ease.sort_and_pick(conv)
        output_clean = ease.sort_and_pick(clean)

        # test the type of output
        self.assertIsInstance(output_conv, list)
        self.assertIsInstance(output_clean, list)
        # test if output clean energy is in output convetional list
        conventional_list = ['Coal', 'NG', 'Petro']
        self.assertNotIn(output_clean[-1], conventional_list)
        # test the length of output
        self.assertEqual(len(output_conv), 3)
        self.assertEqual(len(output_clean), 3)
Пример #2
0
 def test_avg_cap_output(self):
     """test avg_cap function type, and also the length fo the final output contains a length of 6."""
     path = os.path.dirname(__file__)
     path = os.path.join(path, 'Arranged_Data', 'average_plant_capacity.csv')
     average_plant_capacity = pd.read_csv(path)
     path = os.path.dirname(__file__)
     path_test = os.path.join(path, 'Arranged_Data', 'test_dataset.csv')
     test = pd.read_csv(path_test)
     prec = test.iloc[0, 1]
     ts = test.iloc[0, 2]
     tw = test.iloc[0, 3]
     ws = test.iloc[0, 4]
     vote = ease.rf(prec, ts, tw, ws)
     output = ease.avg_capacity(vote)
     # test the type of output dataset
     self.assertIsInstance(output, list)
     # test the length of output dataset
     self.assertEqual(len(output), 6)
Пример #3
0
    def test_suggest_output(self):
        """test suggest function, to see if all works as expected."""
        path = os.path.dirname(__file__)
        path_test = os.path.join(path, 'Arranged_Data', 'test_dataset.csv')
        test = pd.read_csv(path_test)
        prec = test.iloc[0, 1]
        ts = test.iloc[0, 2]
        tw = test.iloc[0, 3]
        ws = test.iloc[0, 4]
        capacity = 5000
        vote = ease.rf(prec, ts, tw, ws)
        avg_cap = ease.avg_capacity(vote)
        possible_type_list = ease.possible_type(avg_cap)
        conventional, clean = ease.clean_or_conv(possible_type_list)
        conventional = ease.sort_and_pick(conventional)
        clean = ease.sort_and_pick(clean)

        source_co2 = {'Coal': 2133, 'Petro': 1700, 'NG': 1220}
        # test whether conventional type in source dictionary
        self.assertIn(conventional[-1], source_co2.keys())
Пример #4
0
    def test_clean_or_conv(self):
        """test clean_or_conv function, such that the input is alist, output is a list, and the second index [2] from the clean 
        list is a string."""
        path = os.path.dirname(__file__)
        path_test = os.path.join(path, 'Arranged_Data', 'test_dataset.csv')
        test = pd.read_csv(path_test)
        prec = test.iloc[22, 1]
        ts = test.iloc[22, 2]
        tw = test.iloc[22, 3]
        ws = test.iloc[22, 4]
        vote = ease.rf(prec, ts, tw, ws)
        avg_capacity = ease.avg_capacity(vote)
        possible_type = ease.possible_type(avg_capacity)
        conv, clean = ease.clean_or_conv(possible_type)

        # test the type of input
        self.assertIsInstance(possible_type, list)
        # test the type of output
        self.assertIsInstance(conv, list)
        self.assertIsInstance(clean, list)
        # test the element type inside of clean list
        for i in range(len(clean)):
            self.assertIsInstance(clean[i][2], str)
Пример #5
0
    def test_possible_type_output(self):
        """test possible_type function, first passed in the first 4 values of the training dataset, output type is tested
        to ensure is a list.
        
        Also test if the correct source is enlisted into the right bucket, as well as the final output list length."""
        path = os.path.dirname(__file__)
        path = os.path.join(path, 'Arranged_Data', 'average_plant_capacity.csv')
        average_plant_capacity = pd.read_csv(path)
        path = os.path.dirname(__file__)
        path_test = os.path.join(path, 'Arranged_Data', 'test_dataset.csv')
        test = pd.read_csv(path_test)
        prec = test.iloc[0, 1]
        ts = test.iloc[0, 2]
        tw = test.iloc[0, 3]
        ws = test.iloc[0, 4]
        vote = ease.rf(prec, ts, tw, ws)
        avg_cap_list = ease.avg_capacity(vote)
        output = ease.possible_type(avg_cap_list)

        # test the type of output dataset
        self.assertIsInstance(output, list)

        # calculate how many conventional energy resource have been filtered
        type_list = []
        for i in range(len(ease.possible_type(avg_cap_list))):
            type = ease.possible_type(avg_cap_list)[i][-1]
            type_list.append(type)
            conventional_ = ['Coal', 'NG', 'Petro']
        filtered = []
        for i in conventional_:
            if i in type_list:
                pass
            else:
                filtered.append(i)

        # test if all the clean resources have been filtered out
        self.assertLess(len(filtered), 3)