-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #602 from iKostanOrg/kyu6
Merge pull request #601 from iKostanOrg/master
- Loading branch information
Showing
9 changed files
with
225 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
kyu\_6.find\_the\_in\_between\_point.module package | ||
=================================================== | ||
|
||
Subpackages | ||
----------- | ||
|
||
.. toctree:: | ||
:maxdepth: 4 | ||
|
||
kyu_6.find_the_in_between_point.readme | ||
kyu_6.find_the_in_between_point |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
README | ||
====== | ||
|
||
.. include:: ../../kyu_6/find_the_in_between_point/README.md | ||
:parser: myst_parser.sphinx_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
kyu\_6.find\_the\_in\_between\_point package | ||
============================================ | ||
|
||
Submodules | ||
---------- | ||
|
||
kyu\_6.find\_the\_in\_between\_point.solution module | ||
---------------------------------------------------- | ||
|
||
.. automodule:: kyu_6.find_the_in_between_point.solution | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
:private-members: | ||
|
||
kyu\_6.find\_the\_in\_between\_point.test\_middle\_point module | ||
--------------------------------------------------------------- | ||
|
||
.. automodule:: kyu_6.find_the_in_between_point.test_middle_point | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
:private-members: | ||
|
||
Module contents | ||
--------------- | ||
|
||
.. automodule:: kyu_6.find_the_in_between_point | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
:private-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Find the in-between point | ||
|
||
## Description | ||
|
||
For this kata, you are given three points `(x1,y1,z1), (x2,y2,z2), | ||
and (x3,y3,z3)` that lie on a straight line in 3-dimensional space. | ||
You have to figure out which point lies in between the other two. | ||
|
||
Your function should return `1, 2, or 3` to indicate which point is | ||
the in-between one. | ||
|
||
[Source](https://www.codewars.com/kata/58a672d6426bf38be4000057) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Find the in-between point.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
Solution for -> Find the in-between point. | ||
Created by Egor Kostan. | ||
GitHub: https://github.com/ikostan | ||
""" | ||
|
||
import math | ||
|
||
|
||
def middle_point(*args) -> int: | ||
""" | ||
Return 1, 2, or 3 to indicate which point is the in-between one. | ||
:param args: 3 sets of 3D coordinates. | ||
:return: int, middle point. | ||
""" | ||
# Set 3D coordinates | ||
a: tuple = args[0][:3] | ||
b: tuple = args[0][3:6] | ||
c: tuple = args[0][6:] | ||
|
||
# Calculate distances | ||
a_b: float = distance_between_two_points(a, b) | ||
a_c: float = distance_between_two_points(a, c) | ||
b_c: float = distance_between_two_points(b, c) | ||
|
||
if a_c < b_c and a_b < b_c: | ||
return 1 | ||
|
||
return 2 if a_b < a_c and b_c < a_c else 3 | ||
|
||
|
||
def distance_between_two_points(a: tuple, b: tuple) -> float: | ||
""" | ||
Return distance between two points on a 3D coordinate. | ||
:param a: tuple | ||
:param b: tuple | ||
:return: float | ||
""" | ||
return math.sqrt((b[2] - a[2]) ** 2 + (b[1] - a[1]) ** 2 + (b[0] - a[0]) ** 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
Solution for -> Find the in-between point. | ||
Created by Egor Kostan. | ||
GitHub: https://github.com/ikostan | ||
""" | ||
|
||
# FUNDAMENTALS GEOMETRY MATHEMATICS ALGORITHMS | ||
|
||
import unittest | ||
import allure | ||
from parameterized import parameterized | ||
from utils.log_func import print_log | ||
from kyu_6.find_the_in_between_point.solution import middle_point | ||
|
||
|
||
# pylint: disable-msg=R0801 | ||
@allure.epic('6 kyu') | ||
@allure.parent_suite('Novice') | ||
@allure.suite("Fundamentals") | ||
@allure.sub_suite("Unit Tests") | ||
@allure.feature("Algorithms") | ||
@allure.story('Find the in-between point') | ||
@allure.tag('FUNDAMENTALS', | ||
'GEOMETRY', | ||
'MATHEMATICS', | ||
'ALGORITHMS') | ||
@allure.link( | ||
url='https://www.codewars.com/kata/58a672d6426bf38be4000057', | ||
name='Source/Kata') | ||
# pylint: enable-msg=R0801 | ||
class MiddlePointTestCase(unittest.TestCase): | ||
"""Test 'middle_point' function.""" | ||
|
||
@parameterized.expand([ | ||
((1, 2, 3, 4, 5, 6, 7, 8, 9), 2, | ||
"Wrong point!"), | ||
((0, 2, 0, 6, -2, 8, 3, 0, 4), 3, | ||
"Wrong point!"), | ||
((0.25, 0.50, 0.75, 3.25, -0.50, -0.25, 1.00, 0.25, 0.50), 3, | ||
"Wrong point!"), | ||
((1, 0, 4, 5, 0, 6, -7, 0, 0), 1, | ||
"Wrong point!"), | ||
((-1, 0, 2, -2, 4, -1, -3, 8, -4), 2, | ||
"Wrong point!")]) | ||
def test_middle_point(self, coords, expected, err): | ||
""" | ||
Test 'middle_point' function with various test data. | ||
:param coords: | ||
:param expected: | ||
:param err: | ||
:return: | ||
""" | ||
# pylint: disable-msg=R0801 | ||
allure.dynamic.title("Testing 'middle_point' function") | ||
allure.dynamic.severity(allure.severity_level.NORMAL) | ||
allure.dynamic.description_html( | ||
'<h3>Codewars badge:</h3>' | ||
'<img src="https://www.codewars.com/users/myFirstCode' | ||
'/badges/large">' | ||
'<h3>Test Description:</h3>' | ||
"<p>" | ||
"Given three points that lie on a straight line in " | ||
"3-dimensional space:" | ||
"- (x1,y1,z1)<br>" | ||
"- (x2,y2,z2)<br>" | ||
"- (x3,y3,z3)" | ||
"</p>" | ||
"<p>" | ||
"Function should return 1, 2, or 3 to indicate which " | ||
"point is the in-between one." | ||
"</p>") | ||
# pylint: enable-msg=R0801 | ||
result = middle_point(coords) | ||
with allure.step(f"Enter test data: {coords} " | ||
f"and verify the expected output: {expected}."): | ||
print_log(coords=coords, expected=expected, result=result, err=err) | ||
self.assertEqual(expected, result) |