Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint 7 #742

Open
wants to merge 12 commits into
base: project_sprint_3_start
Choose a base branch
from

Conversation

AlexVerpovskii
Copy link

No description provided.

Comment on lines +7 to +9

import UIKit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Импортирование UIKit в презентере - признак того, что часть работы с UI просочилась в презентер.
Было бы здорово оставить тут import Foundation и исправить возникшие ошибки (например, передать в контроллер data и уже в нем сгенерировать UIImage).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Благодарю, поправлю :)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здорово, что ты используешь комментарии // 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)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻👍🏻👍🏻

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)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Приватные методы обычно принято располагать ниже обычных.
Про организацию кода можно дополнительно посмотреть в этой статье.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Благодарю, поправлю :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants