Esempio n. 1
0
    def test1_load_data(self):
        pokemon = load_data(random_csv_file)

        # We should have a list
        self.assertIsInstance(pokemon, list)

        # The elements of the list should be dictionaries
        for element in pokemon:
            self.assertIsInstance(element, dict)

        # We should load exactly 20 pokemon
        self.assertEqual(len(pokemon), 20)

        for row in pokemon:
            self.assertTrue(
                all(k not in ['Legendary', 'Generation'] for k in row))

        # Check row 13 to make sure it contains what we expect
        row = pokemon[13]
        expected_row = {
            '#': 14,
            'Name': 'name_14',
            'Type 1': 'type_a_14',
            'Type 2': '',
            'Total': 687,
            'HP': 191,
            'Attack': 2,
            'Defense': 181,
            'Sp. Atk': 12,
            'Sp. Def': 108,
            'Speed': 193
        }

        # Check that expected_row is contained in row
        for k, v in expected_row.items():
            self.assertIn(k, row)
            self.assertIsInstance(row[k], type(v))
            self.assertEqual(row[k], v)

        # Check that row contains no extra keys
        for k in row:
            self.assertIn(k, expected_row)
Esempio n. 2
0
def get_x_y_pairs(csv_file):
    '''
	Take in a csv file name and return a list of (x, y) pairs corresponding to
	the csv file's pokemon
	'''
    return [calculate_x_y(stats) for stats in load_data(csv_file)]