From 34d7a55d1adcb404a6c48d5643fe7263d930db51 Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Fri, 15 Jan 2021 20:15:52 -0300 Subject: [PATCH] [NFC] Using precondition instead of assert in calls that do not allow negative values --- Sources/Algorithms/Combinations.swift | 2 +- Sources/Algorithms/Permutations.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Algorithms/Combinations.swift b/Sources/Algorithms/Combinations.swift index 643feada..07c19913 100644 --- a/Sources/Algorithms/Combinations.swift +++ b/Sources/Algorithms/Combinations.swift @@ -286,7 +286,7 @@ extension Collection { /// accesses the `count` of the base collection. @inlinable public func combinations(ofCount k: Int) -> Combinations { - assert(k >= 0, "Can't have combinations with a negative number of elements.") + precondition(k >= 0, "Can't have combinations with a negative number of elements.") return Combinations(self, k: k) } } diff --git a/Sources/Algorithms/Permutations.swift b/Sources/Algorithms/Permutations.swift index 6a548f9b..937f63cb 100644 --- a/Sources/Algorithms/Permutations.swift +++ b/Sources/Algorithms/Permutations.swift @@ -242,7 +242,7 @@ extension Collection { /// /// - Complexity: O(1) public func permutations(ofCount k: Int? = nil) -> Permutations { - assert( + precondition( k ?? 0 >= 0, "Can't have permutations with a negative number of elements.") return Permutations(self, k: k)