Skip to content

Commit

Permalink
Merge pull request #72 from DeluxeAlonso/feature/improvements
Browse files Browse the repository at this point in the history
Feature/improvements
  • Loading branch information
DeluxeAlonso committed Dec 2, 2023
2 parents 63d493e + 4a7a4e7 commit 4157f5e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class CalculatorEnvironmentObject: ObservableObject {
.dropFirst()
.receive(on: DispatchQueue.main)
.sink { [weak self] info in
guard let self = self else { return }
self.updateValue(info.0, isEnteringNumbers: info.1)

self?.updateValue(info.0, isEnteringNumbers: info.1)
}.store(in: &cancellables)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,38 @@ final class CalculatorEnvironmentObjectTests: XCTestCase {
XCTAssertEqual(operationHandler.deleteLastSingleDigitCallCount, 1)
}

func testUpdateValueIsEnteringValueTrue() {
// Arrange
let isEnteringValue = true
resultFormatter.formatEnteredNumberResult = "11"
let expectation = expectation(description: "Entered number should be formatted")
// Act
resultFormatter.formatEnteredNumberCall = { display in
XCTAssertEqual(display, "1")
expectation.fulfill()
}
operationHandler.calculatorDisplay.value = ("1", isEnteringValue)
// Assert
waitForExpectations(timeout: 1.0)
XCTAssertEqual(resultFormatter.formatEnteredNumberCallCount, 1)
XCTAssertEqual(calculatorEnvironmentObject.formattedCalculatorDisplay, "11")
}

func testUpdateValueIsEnteringValueFalse() {
// Arrange
let isEnteringValue = false
resultFormatter.formatResultResult = "11"
let expectation = expectation(description: "Result should be formatted")
// Act
resultFormatter.formatResultCall = { display in
XCTAssertEqual(display, "1")
expectation.fulfill()
}
operationHandler.calculatorDisplay.value = ("1", isEnteringValue)
// Assert
waitForExpectations(timeout: 1.0)
XCTAssertEqual(resultFormatter.formatResultCallCount, 1)
XCTAssertEqual(calculatorEnvironmentObject.formattedCalculatorDisplay, "11")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ import Combine
final class CalculatorResultFormatterMock: CalculatorResultFormatterProtocol {
var formatResultResult: String?
private(set) var formatResultCallCount = 0
var formatResultCall: ((String) -> Void)?
func formatResult(from calculatorDisplay: String) -> String? {
formatResultCallCount += 1
formatResultCall?(calculatorDisplay)
return formatResultResult
}

var formatEnteredNumberResult: String?
private(set) var formatEnteredNumberCallCount = 0
var formatEnteredNumberCall: ((String) -> Void)?
func formatEnteredNumber(from calculatorDisplay: String) -> String? {
formatEnteredNumberCallCount += 1
formatEnteredNumberCall?(calculatorDisplay)
return formatEnteredNumberResult
}
}

0 comments on commit 4157f5e

Please sign in to comment.