Skip to content

Commit

Permalink
Merge pull request #602 from iKostanOrg/kyu6
Browse files Browse the repository at this point in the history
Merge pull request #601 from iKostanOrg/master
  • Loading branch information
ikostan authored Dec 31, 2024
2 parents a795878 + 11620d1 commit a159ea7
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 41 deletions.
11 changes: 11 additions & 0 deletions docs/kyu_6/kyu_6.find_the_in_between_point.module.rst
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
5 changes: 5 additions & 0 deletions docs/kyu_6/kyu_6.find_the_in_between_point.readme.rst
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_
32 changes: 32 additions & 0 deletions docs/kyu_6/kyu_6.find_the_in_between_point.rst
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:
1 change: 1 addition & 0 deletions docs/kyu_6/kyu_6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Subpackages
kyu_6.duplicate_encoder.module
kyu_6.easy_diagonal.module
kyu_6.encrypt_this.module
kyu_6.find_the_in_between_point.module
kyu_6.find_the_odd_int.module
kyu_6.first_character_that_repeats.module
kyu_6.format_string_of_names.module
Expand Down
83 changes: 42 additions & 41 deletions kyu_6/README.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions kyu_6/find_the_in_between_point/README.md
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)
1 change: 1 addition & 0 deletions kyu_6/find_the_in_between_point/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Find the in-between point."""
42 changes: 42 additions & 0 deletions kyu_6/find_the_in_between_point/solution.py
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)
79 changes: 79 additions & 0 deletions kyu_6/find_the_in_between_point/test_middle_point.py
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)

0 comments on commit a159ea7

Please sign in to comment.