-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- some remaining code clean up
- Loading branch information
Showing
13 changed files
with
132 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Copyright 2018-2020 Amazon.com, | ||
// Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
/// A Tree data type with a `value` of some type `E` and `children` subtrees. | ||
public class Tree<E> { | ||
public var value: E | ||
public var children: [Tree<E>] = [] | ||
public weak var parent: Tree<E>? | ||
|
||
public init(value: E) { | ||
self.value = value | ||
} | ||
|
||
/// Add a child to the tree's children and set a weak reference from the child to the parent (`self`) | ||
public func addChild(settingParentOf child: Tree) { | ||
children.append(child) | ||
child.parent = self | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
21 changes: 21 additions & 0 deletions
21
AmplifyPlugins/Core/AWSPluginsCore/Model/Support/GraphQLDocumentInput.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// Copyright 2018-2020 Amazon.com, | ||
// Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
/// Contains the `type` of the GraphQL document input parameter as a string value and `GraphQLDocumentInputValue` | ||
public struct GraphQLDocumentInput { | ||
|
||
public var type: String | ||
|
||
public var value: GraphQLDocumentInputValue | ||
|
||
public init(type: String, value: GraphQLDocumentInputValue) { | ||
self.type = type | ||
self.value = value | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Copyright 2018-2020 Amazon.com, | ||
// Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import XCTest | ||
@testable import Amplify | ||
|
||
class TreeTests: XCTestCase { | ||
|
||
func testTreeWithChildren() { | ||
let tree = Tree<Int>(value: 0) | ||
let child1 = Tree<Int>(value: 1) | ||
let child2 = Tree<Int>(value: 2) | ||
|
||
tree.addChild(settingParentOf: child1) | ||
tree.addChild(settingParentOf: child2) | ||
|
||
XCTAssertNotNil(tree) | ||
XCTAssertEqual(tree.value, 0) | ||
XCTAssertEqual(tree.children.count, 2) | ||
XCTAssertNotNil(child1.parent) | ||
XCTAssertEqual(child1.parent?.value, tree.value) | ||
XCTAssertNotNil(child2.parent) | ||
XCTAssertEqual(child2.parent?.value, tree.value) | ||
} | ||
} |