Sprint 7#742
Open
AlexVerpovskii wants to merge 12 commits into
Open
Conversation
…з систему контроля версий
Изменен вывод в консоль в файле AppDelegate
Task of the 4 sprint
home work sprint 5
Co-authored-by: averpovskii <averpovskii@phoenixit.ru>
Nikitaaeee
reviewed
Apr 23, 2024
Comment on lines
+7
to
+9
|
|
||
| import UIKit | ||
|
|
There was a problem hiding this comment.
Импортирование UIKit в презентере - признак того, что часть работы с UI просочилась в презентер.
Было бы здорово оставить тут import Foundation и исправить возникшие ошибки (например, передать в контроллер data и уже в нем сгенерировать UIImage).
Comment on lines
+12
to
+20
| // MARK: - Private Properties | ||
| private final var questionFactory: QuestionFactoryProtocol? | ||
| private weak var viewController: MovieQuizViewControllerProtocol? | ||
| private final var statisticService: StatisticServiceProtocol? | ||
| private var currentQuestion: QuizQuestion? | ||
|
|
||
| private var currentQuestionIndex: Int = 0 | ||
| private var correctAnswers: Int = 0 | ||
| private let questionsAmount: Int = 10 |
There was a problem hiding this comment.
Здорово, что ты используешь комментарии // MARK: - ..., а также не забываешь добавлять private 🔥
Comment on lines
+10
to
+49
| struct ArithmeticOperations { | ||
| func addition(num1: Int, num2: Int, handler: @escaping(Int) -> Void) { | ||
| DispatchQueue.global().asyncAfter(deadline: .now() + 1.0, execute: DispatchWorkItem(block: { | ||
| handler(num1 + num2) | ||
| })) | ||
| } | ||
|
|
||
| func subtraction(num1: Int, num2: Int, handler: @escaping(Int) -> Void) { | ||
| DispatchQueue.global().asyncAfter(deadline: .now() + 1.0, execute: DispatchWorkItem(block: { | ||
| handler(num1 - num2) | ||
| })) | ||
| } | ||
|
|
||
| func multiplication(num1: Int, num2: Int, handler: @escaping(Int) -> Void) { | ||
| DispatchQueue.global().asyncAfter(deadline: .now() + 1.0, execute: DispatchWorkItem(block: { | ||
| handler(num1 * num2) | ||
| })) | ||
| } | ||
| } | ||
|
|
||
| final class MovieQuizTests: XCTestCase { | ||
|
|
||
| func testAddition() throws { | ||
|
|
||
| //MARK: Given | ||
| let arithmeticOperations = ArithmeticOperations() | ||
| let num1 = 1 | ||
| let num2 = 2 | ||
|
|
||
| //MARK: When | ||
| let expectation = expectation(description: "Addition function expectation") | ||
|
|
||
| arithmeticOperations.addition(num1: num1, num2: num2) { result in | ||
| //MARK: Then | ||
| XCTAssertEqual(result, 3) | ||
| expectation.fulfill() | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 2) | ||
| } |
Comment on lines
+105
to
+134
| private func didAnswer(isCorrectAnswer: Bool){ | ||
| if (isCorrectAnswer) { correctAnswers += 1 } | ||
| } | ||
|
|
||
| func yesButtonClicked() { | ||
| didAnswer(isYes: true) | ||
| } | ||
|
|
||
| func noButtonClicked() { | ||
| didAnswer(isYes: false) | ||
| } | ||
|
|
||
| private func createMessage() -> String { | ||
| guard let statisticService else { return "" } | ||
| let bestGame = statisticService.bestGame | ||
| let result: String = "Ваш результат: \(correctAnswers)/\(questionsAmount)" | ||
| let count: String = "Количество сыгранных игр: \(statisticService.gamesCount)" | ||
| let record: String = "Рекорд: \(bestGame.correct)/\(bestGame.total) (\(bestGame.date.dateTimeString))" | ||
| let totalAccuracy: String = "Средняя точность: \(String(format: "%.2f", statisticService.totalAccuracy))%" | ||
| return [result, count, record, totalAccuracy].joined(separator: "\n") | ||
| } | ||
|
|
||
| func didLoadDataFromServer() { | ||
| viewController?.hideLoadingIndicator() | ||
| questionFactory?.requestNextQuestion() | ||
| } | ||
|
|
||
| func didFailToLoadData(with error: Error) { | ||
| viewController?.showNetworkError(message: error.localizedDescription) | ||
| } |
There was a problem hiding this comment.
Приватные методы обычно принято располагать ниже обычных.
Про организацию кода можно дополнительно посмотреть в этой статье.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.