Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Wizards."""
- class Wand:
- """Wand."""
- def __init__(self, wood_type, core):
- self.wood_type = wood_type
- self.core = core
- def set_wood_type(self, wood_type):
- self.wood_type = wood_type
- def set_core(self, core):
- self.core = core
- @staticmethod
- def check_wand(wand):
- if not isinstance(wand, Wand) or wand.wood_type is None or wand.core is None:
- raise MismatchError("The wand like that does not exist!")
- def __str__(self):
- return f"{self.wood_type}, {self.core}"
- class Wizard:
- """Wizard."""
- def __init__(self, name, wand=None):
- self.name = name
- self.wand = wand
- if wand is not None:
- Wand.check_wand(wand)
- def set_wand(self, wand):
- # FEILIB
- if wand is not None and Wand.check_wand(wand) is None:
- self.wand = wand
- else:
- raise MismatchError("The wand like that does not exist!")
- def get_wand(self):
- return self.wand
- def __str__(self):
- return self.name
- class School:
- """School."""
- schools = [
- "Hogwarts School of Witchcraft and Wizardry", "Durmstrang Institute",
- "Ilvermorny School of Witchcraft and Wizardry", "Castelobruxo",
- "Beauxbatons Academy of Magic"
- ]
- def __init__(self, name: str):
- self.name = name
- if name not in School.schools:
- raise MismatchError("There is no such school!")
- def add_wizard(self, wizard):
- # üks läbib, 2 feilib
- if isinstance(wizard, Wizard) and wizard.name is not None and wizard.wand is not None:
- return f"{wizard.name} is already studying in this school!"
- raise MismatchError("It's a filthy muggle!")
- def remove_wizard(self, wizard):
- # FEILIB
- pass
- def get_wizards(self):
- # FEILIB
- pass
- def get_wizard_by_wand(self, wand):
- # FEILIB
- if wand is None or wand.wood_type is None or wand.core is None:
- raise MismatchError("The wand like that does not exist!")
- def __str__(self):
- return self.name
- class MismatchError(Exception):
- def __init__(self, message):
- self.message = message
- if __name__ == '__main__':
- wand1 = Wand("Holly", "Phoenix feather")
- wand2 = Wand("Vine", "Dragon heartstring")
- bad_wand = Wand(None, "empty")
- assert str(wand1) == 'Holly, Phoenix feather'
- assert str(wand2) == 'Vine, Dragon heartstring'
- wizard1 = Wizard("Harry Potter")
- wizard2 = Wizard("Hermione Granger")
- assert str(wizard1) == 'Harry Potter'
- assert str(wizard2) == 'Hermione Granger'
- bad_wizard = Wizard(None, None)
- school = School("Hogwarts School of Witchcraft and Wizardry")
- assert str(school) == 'Hogwarts School of Witchcraft and Wizardry'
- assert wizard1.get_wand() is None
- wizard1.set_wand(wand1)
- assert str(wizard1.get_wand()) == 'Holly, Phoenix feather'
- # wizard1.set_wand(bad_wand) # --> MismatchError: The wand like that does not exist!
- assert school.add_wizard(wizard1) == 'Harry Potter started studying in Hogwarts School of Witchcraft and Wizardry.'
- assert school.get_wizards().__len__() == 1
- # school.add_wizard(wizard2) # --> MismatchError: It's a filthy muggle!
- # school.add(bad_wizard) # --> MismatchError: It's a filthy muggle!
- wizard2.set_wand(wand2)
- assert school.add_wizard(wizard2) == 'Hermione Granger started studying in Hogwarts School of Witchcraft and Wizardry.'
- assert school.get_wizards().__len__() == 2
- assert school.add_wizard(wizard1) == 'Harry Potter is already studying in this school!'
- assert str(school.get_wizard_by_wand(wand1)) == 'Harry Potter'
- assert str(school.get_wizard_by_wand(wand2)) == 'Hermione Granger'
- school.remove_wizard(wizard1)
- assert school.get_wizard_by_wand(wand1) is None
- School.schools.append("Example school")
- assert "Example school" in School.schools
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement