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

Sorting is not stable enough #23

Open
schemacs opened this issue Jul 24, 2021 · 0 comments
Open

Sorting is not stable enough #23

schemacs opened this issue Jul 24, 2021 · 0 comments

Comments

@schemacs
Copy link

Request6ProgressKtTest.testProgress failed with this:

Wrong intermediate result after 3200: expected:<[User(login=user-2, contributions=50), User(login=user-1, contributions=50)]> but was:<[User(login=user-1, contributions=50), User(login=user-2, contributions=50)]>
Expected :[User(login=user-2, contributions=50), User(login=user-1, contributions=50)]
Actual   :[User(login=user-1, contributions=50), User(login=user-2, contributions=50)]

.sortedByDescending { it.contributions }
(in the solution branch) should be updated to

        .sortedWith(compareByDescending<User> { it.contributions }
            .thenByDescending { it.login })

This is my solution for Request6Progress.kt:

suspend fun loadContributorsProgress(
    service: GitHubService,
    req: RequestData,
    updateResults: suspend (List<User>, completed: Boolean) -> Unit
) {
    val repos = service
        .getOrgRepos(req.org)
        .also { logRepos(req, it) }
        .body() ?: listOf()

    var allUsers = emptyList<User>()
    repos.forEachIndexed { index, repo ->
        val users = service
            .getRepoContributors(req.org, repo.name)
            .also { logUsers(repo, it) }
            .bodyList()
        allUsers += users
        // allUsers = (allUsers + users).aggregate() // uncomment this line to make the test happy
        updateResults(allUsers.aggregate(), index == repos.lastIndex)
    }
}
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

1 participant