Testsを追加
This commit is contained in:
parent
e199f10453
commit
b7e89902b8
|
@ -2,10 +2,44 @@ import XCTest
|
||||||
@testable import Node
|
@testable import Node
|
||||||
|
|
||||||
final class NodeTests: XCTestCase {
|
final class NodeTests: XCTestCase {
|
||||||
func testExample() throws {
|
func testExample() throws {
|
||||||
// This is an example of a functional test case.
|
let inputDatas: [String: String?] = [
|
||||||
// Use XCTAssert and related functions to verify your tests produce the correct
|
"1": nil,
|
||||||
// results.
|
"2": "1",
|
||||||
XCTAssertEqual(Node().text, "Hello, World!")
|
"3": "2",
|
||||||
}
|
"4": "1",
|
||||||
|
"5": "4",
|
||||||
|
"6": "5"
|
||||||
|
]
|
||||||
|
|
||||||
|
let sources: [TweetNodeSource] = inputDatas.filter { $0.value != nil }.map { .init(id: $0.key, parentID: $0.value!) }
|
||||||
|
|
||||||
|
let topNode = inputDatas.first { $0.value == nil }!
|
||||||
|
var node: TweetNode = .init(id: topNode.key)
|
||||||
|
node.setAllData(sources: sources)
|
||||||
|
|
||||||
|
print(node)
|
||||||
|
XCTAssertEqual(node, TweetNode(id: "1", children: [.init(id: "2", children: [.init(id: "3")]), .init(id: "4", children: [.init(id: "5", children: [.init(id: "6")])])]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TweetNodeSource: NodeSource {
|
||||||
|
let id: String
|
||||||
|
let parentID: String
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TweetNode: Node, Equatable {
|
||||||
|
let id: String
|
||||||
|
var children: [TweetNode]
|
||||||
|
typealias Source = TweetNodeSource
|
||||||
|
|
||||||
|
init(id: String) {
|
||||||
|
self.id = id
|
||||||
|
self.children = []
|
||||||
|
}
|
||||||
|
|
||||||
|
init(id: String, children: [TweetNode] = []) {
|
||||||
|
self.id = id
|
||||||
|
self.children = children
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue