Skip to content

Instantly share code, notes, and snippets.

View vikingosegundo's full-sized avatar

Manuel Meyer vikingosegundo

  • Groningen, Netherlands
View GitHub Profile
--- Stack<String>: 3 elements ---
"three"
"two"
"one"
+++++++++++++++++++++++++++++++++
struct Stack<T>: CustomStringConvertible {
init(_ s:_Stack<T>) { stack = s }
init( ) { self.init(createStack()) }
func push(_ el: T ) { stack.push(el) }
func pop ( ) -> T? { stack.pop() }
func peek( ) -> T? { stack.peek() }
var description: String { stack.string() }
private let stack: _Stack<T>
}
let s:_Stack<String> = createStack()
s.push("one")
s.push("two")
s.push("three")
print(s.string())
func createRandomStackDispenser<T>(with data: [T]) -> () -> T? {
let state = createStack(with:data.shuffled())
return {
state.pop()
}
}
func createStack<T>(with array:[T] = [], divider: (top: String, bottom: String) = (top:"-", bottom:"+")) -> _Stack<T> {
var array:[T] = array
var typeDescription: String { String(describing:T.self) }
var topDivider : String {
array.count > 0
? "\(3*divider.top) " + "Stack<\(typeDescription)>: \(array.count) elements " + "\(3*divider.top)" + "\n"
: "\(3*divider.top) " + "Empty Stack<\(typeDescription)> " + "\(3*divider.top)" + "\n"
}
var bottomDivider : String { divider.bottom * max((topDivider.count - 1), 0) + "\n" }
return (
typealias _Stack<T> = (
push : (T) -> (),
pop : ( ) -> T?,
peek : ( ) -> T?,
string: ( ) -> String
)
// MARK: - Executable Documentation
#if targetEnvironment(simulator)
enum LightingFeature {
static func Documentation () -> [(Message._Lighting,Message._Lighting,Message._Lighting)]{
let l = Light(id: "1", name: "1")
let r = Room(id: "a", title: "a")
let e = LightError.unknown
let docs: [(Message._Lighting,Message._Lighting,Message._Lighting)] =
// These are examples for every lighting command and their possible responses. These colums do show all commands the Lighting Module
// will understand and that are constructable. So to speak: it is the complete vocabulary.
import Quick
import Nimble
@testable import BrighterHue
import BrighterModel
final
class LightSpec: QuickSpec {
override func spec() {
let light = Light(id:"01", name:"desk")
describe("creating a light") {
import Foundation
import BrighterModel
typealias Input = (Message) -> ()
typealias Output = (Message) -> ()
enum StackKind { case hue, mock }
func createAppDomain(
store : Store,
import Quick
import Nimble
import BrighterModel
@testable import BrighterHue
final
class DimmerSpec: QuickSpec {
override func spec() {
var client : MockClient! ; beforeEach { client = MockClient(with: thelights, rooms: rooms) }; afterEach { client = nil }