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
fun getTimes(times: Array<Int>, directions: Array<Int>): Array<Int> { | |
val result: Array<Int> = Array(times.size) { 0 } | |
val endTime: Int = times.max() ?: 0 | |
if (endTime == 0) return result | |
val inQueue: Queue<Int> = LinkedList() | |
val outQueue: Queue<Int> = LinkedList() | |
var currentIndex = 0 | |
var turnstile = 0 |
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
/// Stub that holds all of the values in memory | |
class StubStorage implements Storage { | |
final hash = <String, dynamic>{}; | |
@override | |
bool? getBool(String key) => hash[key] as bool?; | |
@override | |
String? getString(String key) => hash[key] as String?; |
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
Response<T> buildFailureResponse<T>( | |
String message, { | |
int code = 400, | |
http.BaseRequest? request, | |
}) { | |
final body = jsonDecode(message) as Map<String, dynamic>; | |
final error = buildBackendError(statusCode: code, body: body); | |
return Response( | |
http.Response(message, code, request: request), |
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
Response<T> buildFailureResponse<T>( | |
String message, { | |
int code = 400, | |
http.BaseRequest? request, | |
}) { | |
final body = jsonDecode(message) as Map<String, dynamic>; | |
final error = buildBackendError(statusCode: code, body: body); | |
return Response( | |
http.Response(message, code, request: request), |
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
Response<T> buildFailureResponse<T>( | |
String message, { | |
int code = 400, | |
http.BaseRequest? request, | |
}) { | |
final body = jsonDecode(message) as Map<String, dynamic>; | |
final error = buildBackendError(statusCode: code, body: body); | |
return Response( | |
http.Response(message, code, request: request), |
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
group('with a success', () { | |
setUpAll(() async { | |
when(pushNotifier.requestPermissions()).thenSucceed(true); | |
when(pushNotifier.onTokenRefresh()).thenStream(fcmRefreshedToken); | |
await subject().onInit(); | |
}); | |
test('ask for push permissions', () { | |
verify(pushNotifier.requestPermissions()); |
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
/// mocking the PostExpectation with a Future | |
extension FutureMock<T> on PostExpectation<Future<T>> { | |
void thenFuture(T body) { | |
thenAnswer((realInvocation) => Future.value(body)); | |
} | |
} | |
/// we use Result objet similar than a monad which returns a success, a failure, etc | |
/// this extension mocks a Result of success, failure or in order |
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
await onErrorRetry( | |
doIt: () async { | |
await _twilioModule.setup(); | |
_analytic.track('Platform Loaded'); | |
_router.replaceTo(HomeRoute()); | |
status = status.rebuild((b) => b..isLoadingVisible = false); | |
}, |
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
typedef FunctionOnRetry = Function( | |
dynamic ex, | |
int retryCount, | |
int retryInMilliseconds, | |
); | |
Future<void> onErrorRetry({ | |
required Future Function() doIt, | |
required FunctionOnRetry onRetry, | |
required int maxRetries, |
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 class uses Isolates.run, only available after Dart 2.19, allowing in parallel obtaining a file in bytes | |
/// then answering to its caller without blocking the UI | |
/// remember: when using isolates, the functions they call must be top level or static | |
import 'dart:isolate'; | |
import 'package:flutter/foundation.dart'; | |
import 'package:http/http.dart' as http; | |
Future<http.Response> _fileResponse(Uri uri) async { |
NewerOlder