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

Do not use comparator implementation like y-x. #1

Closed
chabapok opened this issue Mar 1, 2016 · 1 comment
Closed

Do not use comparator implementation like y-x. #1

chabapok opened this issue Mar 1, 2016 · 1 comment

Comments

@chabapok
Copy link

chabapok commented Mar 1, 2016

Issue in _10_Object_Expressions

Comparator implementation like y-x is wrong, because it does not work for some values. See example:

    @Test fun testSort() {
        assertEquals(listOf(5, 2, 1), sort(listOf(2, 5, 1)))
    }

    @Test fun testSort2(){
//wrong, because y-x is fail
        assertEquals(listOf(Integer.MAX_VALUE, Integer.MIN_VALUE), sort(listOf(Integer.MAX_VALUE, Integer.MIN_VALUE)))
    }


    fun sort(list : List<Int>):List<Int> {
//change to y.compareTo(x)
        Collections.sort(list, {x:Int, y:Int -> y-x} )
        return list
    }

@vicboma1
Copy link
Owner

I am Sorry, I have not seen the notification.
My solution not pass her test, I checked it.
I go to correct now!
Thanks for your support!

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