-
Notifications
You must be signed in to change notification settings - Fork 0
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
Addding homework_04 #111
base: main
Are you sure you want to change the base?
Addding homework_04 #111
Changes from 3 commits
540d603
2ebb38d
d5d9fcc
8ed2fc0
aa77d4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# pylint: disable=invalid-name | ||
#pylint: disable=R0903 | ||
#pylint: disable=C0303 | ||
#pylint: disable=C0103 | ||
#pylint: disable=R0911 | ||
#pylint: disable=C1001 | ||
""" | ||
This module has Point and Circle classes | ||
The Circle class has function for finding | ||
the position between two cicles | ||
""" | ||
|
||
import enum | ||
import math | ||
|
||
class RelativePosition(enum.Enum): | ||
""" | ||
This class is Enum | ||
It is used for the class Circle | ||
""" | ||
NO_COMMON_POINTS = 0 | ||
TOUCHING = 1 | ||
INTERSECTING = 2 | ||
#TOUCHING_INTERNALLY = 3 | ||
SAME = 3 | ||
|
||
class Point: | ||
""" | ||
This class is point | ||
Point is used for coordinated system. | ||
""" | ||
def __init__(self, x, y): | ||
""" | ||
Initializes the instance and | ||
assures that the arguments are right | ||
""" | ||
assert isinstance(x, float) | ||
assert isinstance(y, float) | ||
self.x = x | ||
self.y = y | ||
|
||
def line(self, point): | ||
""" | ||
Find the length of the line | ||
""" | ||
assert isinstance(point, Point) | ||
result = round(math.sqrt(math.pow(point.x - self.x, 2) + math.pow(point.y - self.y, 2)), 5) | ||
return result | ||
|
||
class Circle: | ||
""" | ||
Circle is point in coordinated system with radius | ||
""" | ||
def __init__(self, point, r): | ||
""" | ||
Initializes the instance and | ||
assures that the arguments are right | ||
""" | ||
assert isinstance(point, Point) | ||
assert isinstance(r, float) | ||
assert round(r, 5) > 0 | ||
self.point = point | ||
self.r = r | ||
|
||
def find_relative_position(self, circle): | ||
""" | ||
Finds the position between this circle and the given | ||
""" | ||
assert isinstance(circle, Circle) | ||
|
||
#common center | ||
if self.point.x == circle.point.x and self.point.y == circle.point.y: | ||
return RelativePosition.SAME | ||
|
||
AB = self.point.line(circle.point) # >=0 | ||
radius = round(self.r + circle.r, 5) | ||
#no common points | ||
if AB > radius: | ||
return RelativePosition.NO_COMMON_POINTS | ||
#touching | ||
if AB == radius: | ||
return RelativePosition.TOUCHING | ||
|
||
radius_sub = self.r - circle.r | ||
if radius_sub < 0: | ||
radius_sub = -radius_sub | ||
|
||
#same | ||
if radius_sub == 0 and AB == 0: | ||
return RelativePosition.SAME | ||
|
||
#intersect | ||
if radius_sub < AB and AB < radius: | ||
return RelativePosition.INTERSECTING | ||
|
||
#touching internally | ||
if AB == radius_sub: | ||
return RelativePosition.TOUCHING | ||
|
||
# same | ||
if AB < radius_sub: | ||
return RelativePosition.SAME | ||
return None |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Pylint | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- homework_04/05_viktoriya_vasileva/** | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- homework_04/05_viktoriya_vasileva/** | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9"] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Analysing the code with pylint | ||
run: | | ||
cd homework_04 | ||
cd 05_viktoriya_vasileva | ||
pylint circles.py | ||
pylint test_circles.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file needs to be in .github/workflows so the checks actually run. That way github does not recognise the yaml file as a workflow so it does not run neither on push nor pull request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You also do not have a "run" which runs the tests. You need to add that as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1
Comment on lines
+30
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After this you need another section for running the unit tests. For your case, this is:
I will just comment without accepting or returning the request, try to fix these problems, if you want help, ask. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
""" | ||
Tests for class Circle | ||
""" | ||
|
||
from circles import Point, Circle, RelativePosition | ||
|
||
|
||
def test_outside_circles(): | ||
""" | ||
Tests for circles with no common points | ||
""" | ||
circle_a = Circle(Point(1.0, 1.0), 1.0) | ||
circle_b = Circle(Point(10.0, 10.0), 2.0) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.NO_COMMON_POINTS | ||
|
||
circle_a = Circle(Point(1.0, 1.0), 1.0) | ||
circle_b = Circle(Point(10.0, 1.0), 7.0) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.NO_COMMON_POINTS | ||
|
||
circle_a = Circle(Point(1.0, 1.0), 1.0) | ||
circle_b = Circle(Point(10.0, 1.0), 7.99999) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.NO_COMMON_POINTS | ||
|
||
|
||
|
||
def test_touching_circles(): | ||
""" | ||
Tests for circles touching | ||
""" | ||
circle_a = Circle(Point(1.0, 1.0), 1.0) | ||
circle_b = Circle(Point(1.0, 3.0), 1.0) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.TOUCHING | ||
|
||
circle_a = Circle(Point(2.3, 1.0), 1.0) | ||
circle_b = Circle(Point(2.3, 9.0), 7.0) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.TOUCHING | ||
|
||
circle_a = Circle(Point(1.0, 1.0), 1.0) | ||
circle_b = Circle(Point(10.0, 1.0), 7.999999) #rounding | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.TOUCHING | ||
|
||
circle_a = Circle(Point(2.0, 0.0), 1.0) | ||
circle_b = Circle(Point(0.0, 0.0), 3.0) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.TOUCHING | ||
|
||
|
||
def test_intersecting_circles(): | ||
""" | ||
Tests for circles which are intersecting | ||
""" | ||
circle_a = Circle(Point(0.0, 0.0), 1.0) | ||
circle_b = Circle(Point(0.0, 3.0), 3.0) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.INTERSECTING | ||
|
||
circle_a = Circle(Point(2.3, 1.0), 1.0) | ||
circle_b = Circle(Point(2.3, 9.87745), 9.0) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.INTERSECTING | ||
|
||
circle_a = Circle(Point(1.0, 1.0), 1.0) | ||
circle_b = Circle(Point(0.0, 0.0), 1.5) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.INTERSECTING | ||
|
||
|
||
|
||
|
||
def test_same_circles(): | ||
""" | ||
Tests for circles which are the same or are in one another | ||
""" | ||
circle_a = Circle(Point(0.0, 0.0), 1.0) | ||
circle_b = Circle(Point(0.0, 0.0), 3.0) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.SAME | ||
|
||
circle_a = Circle(Point(1.0, 2.0), 1.0) | ||
circle_b = Circle(Point(1.0, 3.0), 5.0) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.SAME | ||
|
||
circle_a = Circle(Point(2.0, 1.0), 10.0) | ||
circle_b = Circle(Point(6.0, 1.0), 1.0) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.SAME | ||
|
||
circle_a = Circle(Point(1.0, 10.0), 100.0) | ||
circle_b = Circle(Point(0.0, 20.0), 1.5) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.SAME | ||
|
||
circle_a = Circle(Point(9.0, 10.0), 100.0) | ||
circle_b = Circle(Point(0.0, 25.0), 1.5) | ||
assert circle_a.find_relative_position(circle_b) == RelativePosition.SAME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convention here should be: Homework 04 - xx Firstname Lastname
Furthermore, this file should be in the folder .github/workflows.