Skip to content

.ShouldBeUnique() runs in O(n!) time #602

@JakenVeina

Description

@JakenVeina

Had a test the other day upon ~500,000 record dataset (I've since refactored this), but attempting to use .ShouldBeUnique() upon this dataset resulted in a test that never completed (not in the amount of time I was willing to wait, anyway.

The offending code can be seen here.

private static List<object> GetDuplicates<T>(IEnumerable<T> items)
{
    var list = new List<object>();
    var duplicates = new List<object>();

    foreach (object o1 in items)
    {
        duplicates.AddRange(list.Where(o2 => o1 != null && o1.Equals(o2)));
        list.Add(o1);
    }

    return duplicates;
}

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