Defined the Randomable protocol in the library target.

This commit is contained in:
Javier Cicchelli 2025-02-22 00:53:22 +01:00
parent 17426f264a
commit c5fc608c23
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,7 @@
protocol Randomable: CaseIterable {
// MARK: Functions
static func random() -> Self
}

View File

@ -0,0 +1,32 @@
import Testing
@testable import ColibriLibrary
struct RandomableTest {
@Test func random() {
// GIVEN
let allCases = TestRandomable.allCases
// WHEN
let random = TestRandomable.random()
// THEN
#expect(allCases.contains(random))
}
}
// MARK: - Enumerations
enum TestRandomable: Randomable {
case someCase
case someOtherCase
// MARK: Functions
static func random() -> TestRandomable {
.allCases.randomElement() ?? .someCase
}
}