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

Refactoring suggestins #1

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Refactoring suggestins #1

wants to merge 9 commits into from

Conversation

frip
Copy link

@frip frip commented Apr 21, 2024

My first shot at a github pull-request.
More may follow...

@Orasund
Copy link
Owner

Orasund commented Apr 21, 2024

Hi, by removing test.sh you have broken the CI pipeline.

The reason for having a generic test.sh is so that the CI pipeline can be language independed. I intend to do more languages besides python

@Orasund
Copy link
Owner

Orasund commented Apr 21, 2024

Hi, please rebase. I've moved the CI code into a ci.sh file.

As far as i can tell adding pyproject.toml broke the CI because now pytest is not included in the requirements.txt

@frip
Copy link
Author

frip commented Apr 21, 2024

Sorry, didn't see your answer in time!
But I found something interesting (I think) in diff_files.py L77ff: did you know, that your get_node() is called with y=-1? (What I am doing here is not stricktly refactoring, because I'm not returning the first element in the line...)

def get_node(p: Position) -> Node:
result = nodes.get_node(p)
if result is None:
return Node(Position(0, 0), 0)
Copy link
Author

@frip frip Apr 21, 2024

Choose a reason for hiding this comment

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

This here is my "tricky" fix for p.y=-1. It occurs in the "standard-test-case"!

Copy link
Owner

@Orasund Orasund Apr 22, 2024

Choose a reason for hiding this comment

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

I'm a bit puzzled. This is only possible if len(nodes.nodes[0] - 1) = -1 or next_pos.y = -1.

The first case occurs if the second file is empty. Second case occurs if I forgot a guard inside compute_node. In particular, this would mean that the cast is not current.

next_pos = candidate2
length = node2.length
else:
next_pos = candidate1
Copy link
Owner

Choose a reason for hiding this comment

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

In order for next_pos.y = -1 we would need to enter this branch with node1 is None (as there is a guard inside get_node). However, if node1 is None, then either branch 1 or 2 will be entered depending on node1 is None.

So im not seeing what should be wrong here.

@frip
Copy link
Author

frip commented Apr 22, 2024 via email

@Orasund
Copy link
Owner

Orasund commented Apr 22, 2024

Thanks a lot. I found the missing guard:

def compute_node(i1: int, i2: int) -> Node:
        next_pos: tuple[int, int] | None
        length: int

        if l1[i1] == l2[i2]:
            if i1 >= 0 and i2 >= 0:
                next_pos = (i1 - 1, i2 - 1)
                length = nodes[next_pos[0]][next_pos[1]].length + 1
            else:
                # this else branch was missing
                next_pos = None
                length = 0

@frip
Copy link
Author

frip commented Apr 23, 2024

I tried adding your guard in the hope that I could then reduce the second closure get_node() to the (new) Matrix-method, but it didn't work... :-(

@Orasund
Copy link
Owner

Orasund commented Apr 23, 2024

Oh! bad luck :/

Hope it's no a dealbreaker. Sadly, I don't have the time to look more into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants