This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Stack<String>: 3 elements --- | |
"three" | |
"two" | |
"one" | |
+++++++++++++++++++++++++++++++++ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s:_Stack<String> = createStack() | |
s.push("one") | |
s.push("two") | |
s.push("three") | |
print(s.string()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createRandomStackDispenser<T>(with data: [T]) -> () -> T? { | |
let state = createStack(with:data.shuffled()) | |
return { | |
state.pop() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias _Stack<T> = ( | |
push : (T) -> (), | |
pop : ( ) -> T?, | |
peek : ( ) -> T?, | |
string: ( ) -> String | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import BrighterModel | |
typealias Input = (Message) -> () | |
typealias Output = (Message) -> () | |
enum StackKind { case hue, mock } | |
func createAppDomain( | |
store : Store, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |