Skip to content

merge_sort stability #3399

Closed
Closed
@jesse99

Description

@jesse99

Don't see a unit test for that. Here is at least a basic test:

#[test]
fn test_merge_sort_stability()
{
    // not sure why we can't use just &
    pure fn ile(x: &@str, y: &@str) -> bool
    {
        unchecked            // to_lower is not pure...
        {
            let x = x.to_lower();
            let y = y.to_lower();
            x <= y
        }
    }

    let names1 = ~[@"joe bob", @"Joe Bob", @"Jack Brown", @"JOE Bob", @"Sally Mae", @"JOE BOB", @"Alex Andy"];
    let names2 = ~[@"Alex Andy", @"Jack Brown", @"joe bob", @"Joe Bob", @"JOE Bob", @"JOE BOB", @"Sally Mae"];
    let names3 = std::sort::merge_sort(ile, names1);
    assert names3 == names2;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions