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

Boolean logic and method name mismatch. #121

Closed
sandymac opened this issue Dec 11, 2015 · 1 comment
Closed

Boolean logic and method name mismatch. #121

sandymac opened this issue Dec 11, 2015 · 1 comment

Comments

@sandymac
Copy link
Contributor

I think the logic in NATTypeDetection.twoOutOfThreeSame is likely backwards. The method name and code logic don't match.

The method's current form, below, has or (||) boolean operations meaning if any one pair matches, the method returns true.

    private static boolean twoOutOfThreeSame(int i1, int i2, int i3, int k1, int k2, int k3) {
        if (i1 == k1 || i2 == k2) {
            return true;
        }
        if (i1 == k1 || i3 == k3) {
            return true;
        }
        if (i2 == k2 || i3 == k3) {
            return true;
        }
        return false;
    }

Replacing the ors (||) with ands (&&) will have the behavior described by the method name. Alternatively the version below has the same behavior with one line.

    private static boolean twoOutOfThreeSame(int i1, int i2, int i3, int k1, int k2, int k3) {
        return (i1 == k1 && i2 == k2) || (i1 == k1 && i3 == k3) || (i2 == k2 && i3 == k3);
    }
@tbocek
Copy link
Member

tbocek commented Jan 5, 2016

You are right, this logic is flawed, thanks for the info!

@tbocek tbocek closed this as completed Jan 5, 2016
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

No branches or pull requests

2 participants