Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #586

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 66 additions & 6 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,85 @@
from __future__ import annotations
from abc import ABC


class IntegerRange:
pass
def __init__(self, min_amount: int, max_amount: int) -> None:
self.min_amount = min_amount
self.max_amount = max_amount

def __get__(self, instance: any, owner: any) -> tuple:
return self.min_amount, self.max_amount

def __set__(self, instance: any, value: int) -> None:
if not isinstance(value, int):
raise TypeError("Only integers are allowed")
if value not in range(self.min_amount, self.max_amount + 1):
raise ValueError(
f"Value must be between "
f"{self.min_amount} and {self.max_amount}"
)
setattr(instance, self.name, value)

def __set_name__(self, owner: any, name: any) -> None:
self.name = name


class Visitor:
pass
def __init__(self,
name: str,
age: int,
weight: int,
height: int) -> None:
self.name = name
self.age = age
self.weight = weight
self.height = height


class SlideLimitationValidator(ABC):
pass
def __init__(self,
age_range: IntegerRange,
weight_range: IntegerRange,
height_range: IntegerRange) -> None:
self.age_range = age_range
self.weight_range = weight_range
self.height_range = height_range


class ChildrenSlideLimitationValidator(SlideLimitationValidator):
pass
def __init__(self) -> None:
super().__init__(
age_range=IntegerRange(4, 14),
weight_range=IntegerRange(20, 50),
height_range=IntegerRange(80, 120)
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
super().__init__(
age_range=IntegerRange(4, 14),
weight_range=IntegerRange(20, 50),
height_range=IntegerRange(80, 120)
)
age = IntegerRange(4, 14)
height = IntegerRange(80, 120)
weight = IntegerRange(20, 50)



class AdultSlideLimitationValidator(SlideLimitationValidator):
pass
def __init__(self) -> None:
super().__init__(
age_range=IntegerRange(14, 60),
weight_range=IntegerRange(50, 120),
height_range=IntegerRange(120, 220)
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __init__(self) -> None:
super().__init__(
age_range=IntegerRange(14, 60),
weight_range=IntegerRange(50, 120),
height_range=IntegerRange(120, 220)
)
age = IntegerRange(14, 60)
height = IntegerRange(120, 220)
weight = IntegerRange(50, 120)



class Slide:
pass
def __init__(self, name: str, limitation_class: type) -> None:
self.name = name
self.limitation_class = limitation_class()

def can_access(self, visitor: Visitor) -> bool:
try:
return (
self.limitation_class.age_range.min_amount
<= visitor.age <= self.limitation_class.age_range.max_amount
and self.limitation_class.weight_range.min_amount
<= visitor.weight
<= self.limitation_class.weight_range.max_amount
and self.limitation_class.height_range.min_amount
<= visitor.height
<= self.limitation_class.height_range.max_amount
)
except Exception as e:
print(e)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def can_access(self, visitor: Visitor) -> bool:
try:
return (
self.limitation_class.age_range.min_amount
<= visitor.age <= self.limitation_class.age_range.max_amount
and self.limitation_class.weight_range.min_amount
<= visitor.weight
<= self.limitation_class.weight_range.max_amount
and self.limitation_class.height_range.min_amount
<= visitor.height
<= self.limitation_class.height_range.max_amount
)
except Exception as e:
print(e)
def can_access(self, visitor: Visitor) -> bool:
try:
self.limitation_class(visitor.age, visitor.weight, visitor.height)
return True
except ValueError:
return False

Loading