Skip to content

Commit

Permalink
Merge pull request #517 from iKostanOrg/kyu3
Browse files Browse the repository at this point in the history
Merge pull request #516 from iKostanOrg/master
  • Loading branch information
ikostan authored Nov 5, 2024
2 parents eb521f1 + 4ed546f commit 90927a7
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 42 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/flake8_kyu3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: Flake8 for kyu3

on:
push:
branches:
- 'kyu3'

permissions:
contents: read
pull-requests: read

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.x"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
# This is the version of the action for setting up Python,
# not the Python version.
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# You can test your matrix by printing the current
# Python version
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
pip install flake8
- name: Check to make sure that the module is in your Python path
run: |
echo $PYTHONPATH
- name: Lint with flake8
# yamllint disable rule:line-length
# stop the build if there are Python syntax errors or undefined names
# exit-zero treats all errors as warnings.
# The GitHub editor is 127 chars wide
run: |
flake8 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics ./kyu_3
flake8 --count --max-complexity=10 --max-line-length=127 --benchmark --show-source --statistics ./kyu_3
# yamllint enable rule:line-length
2 changes: 0 additions & 2 deletions kyu_3/line_safari_is_that_a_line/test_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# ALGORITHMS STRINGS

import unittest
import pytest
import allure
from utils.log_func import print_log
from kyu_3.line_safari_is_that_a_line.walker_class import Walker
Expand All @@ -25,7 +24,6 @@
@allure.link(
url='https://www.codewars.com/kata/59c5d0b0a25c8c99ca000237',
name='Source/Kata')
@pytest.mark.skip(reason="The solution is not ready")
# pylint: enable-msg=R0801
class WalkerClassTestCase(unittest.TestCase):
"""
Expand Down
101 changes: 61 additions & 40 deletions kyu_3/line_safari_is_that_a_line/walker_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Walker:
"""
Walker class: make moves, check directions, etc...
"""

def __init__(self, grid: list):
# print('__init__')
self.__grid: list = grid
self.__is_start: bool = True
self.__position: dict = self.__get_start_point()
Expand All @@ -21,32 +21,27 @@ def __set_initial_direction(self) -> dict:
'left': False,
'right': False,
'up': False,
'down': False,
}
'down': False}

# coordinates
row: int = self.__position['row']
col: int = self.__position['col']

# up
if row - 1 >= 0:
if self.__grid[row - 1][col] in 'X|+':
direction['up'] = True
if row - 1 >= 0 and self.__grid[row - 1][col] in 'X|+':
direction['up'] = True

# down
if row + 1 < len(self.__grid):
if self.__grid[row + 1][col] in 'X|+':
direction['down'] = True
if row + 1 < len(self.__grid) and self.__grid[row + 1][col] in 'X|+':
direction['down'] = True

# left
if col - 1 >= 0:
if self.__grid[row][col - 1] in 'X+-':
direction['left'] = True
if col - 1 >= 0 and self.__grid[row][col - 1] in 'X+-':
direction['left'] = True

# right
if col + 1 < len(self.__grid[row]):
if self.__grid[row][col + 1] in 'X+-':
direction['right'] = True
if col + 1 < len(self.__grid[row]) and self.__grid[row][col + 1] in 'X+-':
direction['right'] = True

print(f"\nINITIAL DIRECTION: {direction}")
return direction
Expand Down Expand Up @@ -148,46 +143,72 @@ def __reset_direction(self) -> None:
for key in self.__direction:
self.__direction[key] = False

def __set_direction(self) -> None:
def position_plus(self, previous_position) -> None:
"""
Update directions based on current
position and previous direction
:return: None
Process cells if current position is +
:param previous_position:
:return:
"""
prev_row = self.__position['prev_row']
prev_col = self.__position['prev_col']
previous_position = self.__grid[prev_row][prev_col]

# reset all directions
self.__reset_direction()
print(f'prev: {previous_position}, pos: {self.position}')

if self.position == '+' and (previous_position in ('-', 'X')):
if self.position == '+' and previous_position in '-X':
self.__direction['up'] = self.__test_up()
self.__direction['down'] = self.__test_down()
elif self.position == '+' and previous_position == '|':

if self.position == '+' and previous_position == '|':
self.__direction['left'] = self.__test_left()
self.__direction['right'] = self.__test_right()
elif self.position == '+' and previous_position == '+':
if self.__position['col'] == self.__position['prev_col']:
self.__direction['left'] = self.__test_left()
self.__direction['right'] = self.__test_right()
elif self.__position['row'] == self.__position['prev_row']:
self.__direction['up'] = self.__test_up()
self.__direction['down'] = self.__test_down()
elif ((self.position == '-' and (previous_position in ('-', 'X')))
or (self.position == '-' and previous_position == '+')):

if self.position == previous_position == '+' and \
self.__position['col'] == self.__position['prev_col']:
self.__direction['left, '] = self.__test_left()
self.__direction['right'] = self.__test_right()

if self.position == previous_position == '+' and \
self.__position['row'] == self.__position['prev_row']:
self.__direction['up'] = self.__test_up()
self.__direction['down'] = self.__test_down()

def position_minus(self, previous_position) -> None:
"""
Process cells if current position is -
:param previous_position:
:return:
"""
if self.position == '-' and previous_position in '-X+':
if self.__position['col'] < self.__position['prev_col']:
self.__direction['left'] = self.__test_left()
elif self.__position['col'] > self.__position['prev_col']:
self.__direction['right'] = self.__test_right()
elif ((self.position == '|' and (previous_position in ('|', 'X')))
or (self.position == '|' and previous_position == '+')):

def position_pipe(self, previous_position) -> None:
"""
Process cells if current position is |
:param previous_position:
:return:
"""
if self.position == '|' and previous_position in '|X+':
if self.__position['row'] < self.__position['prev_row']:
self.__direction['up'] = self.__test_up()
elif self.__position['row'] > self.__position['prev_row']:
self.__direction['down'] = self.__test_down()

def __set_direction(self) -> None:
"""
Update directions based on current
position and previous direction
:return: None
"""
prev_row = self.__position['prev_row']
prev_col = self.__position['prev_col']
previous_position = self.__grid[prev_row][prev_col]

# reset all directions
self.__reset_direction()
print(f'prev: {previous_position}, pos: {self.position}')

self.position_plus(previous_position)
self.position_minus(previous_position)
self.position_pipe(previous_position)

def __test_up(self) -> bool:
row: int = self.__position['row']
col: int = self.__position['col']
Expand Down

0 comments on commit 90927a7

Please sign in to comment.