Skip to content

Commit

Permalink
Merge pull request #42 from BastiaanJansen/dev
Browse files Browse the repository at this point in the history
Unit test for queue
  • Loading branch information
BastiaanJansen authored Sep 16, 2023
2 parents 3d12c7d + 114b478 commit bc52aa6
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
xcuserdata/
DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.swiftpm
8 changes: 8 additions & 0 deletions File.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// File.swift
// Toast
//
// Created by Bas Jansen on 16/09/2023.
//

import Foundation
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Toast",
dependencies: [])
dependencies: []),
.testTarget(
name: "ToastTests",
dependencies: ["Toast"])
]
)
36 changes: 36 additions & 0 deletions Screenshots/Tests/Queue/ToastQueueTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// ToastQueueTest.swift
//
//
// Created by Bas Jansen on 16/09/2023.
//

import XCTest
@testable import Toast

final class ToastQueueTest: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
16 changes: 14 additions & 2 deletions Sources/Toast/Queue/ToastQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@ public class ToastQueue {
delegates.forEach(multicast.add)
}

public func enqueue(toast: Toast) -> Void {
public func enqueue(_ toast: Toast) -> Void {
queue.append(toast)
}

public func enqueue(toasts: [Toast]) -> Void {
public func enqueue(_ toasts: [Toast]) -> Void {
toasts.forEach({ queue.append($0) })
}

public func dequeue(_ toastToDequeue: Toast) -> Void {
let index: Int? = queue.firstIndex { $0 === toastToDequeue }

if let index {
queue.remove(at: index)
}
}

public func size() -> Int {
return queue.count
}

public func show() -> Void {
if (queue.isEmpty) {
return
Expand Down
41 changes: 41 additions & 0 deletions Tests/ToastTests/Queue/ToastQueueTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// ToastQueuetest.swift
//
//
// Created by Bas Jansen on 16/09/2023.
//

import XCTest
@testable import Toast

final class ToastQueueTest: XCTestCase {

private var queue: ToastQueue!

override func setUpWithError() throws {
queue = ToastQueue()
}

override func tearDownWithError() throws {

}

func test_whenEnqueuingToast_sizeIsOne() throws {
let toast = Toast.text("Toast")

queue.enqueue(toast)

XCTAssertEqual(queue.size(), 1)
}

func test_whenEnqueuingMultipleToasts_sizeIsThree() throws {
let toast = Toast.text("Toast")
let toast2 = Toast.text("Toast")
let toast3 = Toast.text("Toast")

queue.enqueue([toast, toast2, toast3])

XCTAssertEqual(queue.size(), 3)
}

}

0 comments on commit bc52aa6

Please sign in to comment.