diff --git a/Library/Sources/Internal/Protocols/Randomable.swift b/Library/Sources/Internal/Protocols/Randomable.swift new file mode 100644 index 0000000..5b2f5c5 --- /dev/null +++ b/Library/Sources/Internal/Protocols/Randomable.swift @@ -0,0 +1,7 @@ +protocol Randomable: CaseIterable { + + // MARK: Functions + + static func random() -> Self + +} diff --git a/Test/Sources/Cases/Internal/Protocols/RandomableTests.swift b/Test/Sources/Cases/Internal/Protocols/RandomableTests.swift new file mode 100644 index 0000000..07912c5 --- /dev/null +++ b/Test/Sources/Cases/Internal/Protocols/RandomableTests.swift @@ -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 + } + +}