Skip to content

Instantly share code, notes, and snippets.

View houssemzaier's full-sized avatar

Houssem Zaier houssemzaier

View GitHub Profile
@houssemzaier
houssemzaier / OperatorFlowOnTest.kt
Last active September 30, 2022 12:01
onEach and flowOn
package fr.x
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.runBlocking
import org.junit.Test
@houssemzaier
houssemzaier / TestSomeBehaviorSharedFlow.kt
Last active July 17, 2022 20:48
TestSomeBehaviorSharedFlow
package com.ankorstore.account.presentation
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import org.junit.Test
package com.bravedroid.connecta.presentation.main
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import kotlin.properties.ReadOnlyProperty
@houssemzaier
houssemzaier / Coroutines.kt
Created November 5, 2020 19:09
Pushing data to one Flow from two twoCoroutines (Senders) and dispatching the received data to 2 receivers (collectors) that are collecting from one sharedFlow (dispatcher)
package fr.francetv.francetvsport.arch.application
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collect
fun main() = runBlocking {
@houssemzaier
houssemzaier / Main3.kt
Created September 7, 2020 17:49
Without unit Testing just run as jvm console app
package com.raywenderlich.kotlin.coroutines
import androidx.arch.core.executor.ArchTaskExecutor
import androidx.arch.core.executor.TaskExecutor
import androidx.lifecycle.*
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
@ExperimentalCoroutinesApi
class Main3 {
@houssemzaier
houssemzaier / Main3.kt
Created September 6, 2020 23:03
synchronized data observed with a Page sealed class pattern
package com.raywenderlich.kotlin.coroutines
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.*
import kotlinx.coroutines.*
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.setMain
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
@houssemzaier
houssemzaier / TestingLifeCycleEffectCancelingParent.kt
Last active September 2, 2020 20:04
Testing Effect on children When Canceling Parent job
package fr.francetv.francetvsport.arch.presentation.videodetail
import kotlinx.coroutines.*
fun main() = runBlocking {
val parentJob = launch {
launch {
println("start launch child")
while (isActive) {
delay(500)
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
fun main() {
runBlocking {
val doIt1 = doIt1()
val doIt2 = doIt2()
val doIt3 = doIt3()
println("result ${doIt1 + doIt2 + doIt3}")
@houssemzaier
houssemzaier / Test1.kt
Created July 29, 2020 12:12
algo test for arc() dev
package fr.francetv.francetvsport.arch.infrastructure.data.source.remote.pic
//You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this "outlier" N.
fun find(integers: Array<Int>): Int {
var outlierInteger: Int = 0
val oddIntegers = mutableListOf<Int>()
val evenIntegers = mutableListOf<Int>()
var i = 0
while (i <= integers.lastIndex) {
val integer = integers[i]
if (integer.isEven()) {
@houssemzaier
houssemzaier / Test2.kt
Created July 29, 2020 12:12
algo test for arc() dev
package fr.francetv.francetvsport.arch.infrastructure.data.source.remote.pic
//Your task is to split the chocolate bar of given dimension n x m into small squares.
//Each square is of size 1x1 and unbreakable. Implement a function that will return minimum number of breaks needed.
//
//For example, if you are given a chocolate bar of size 2 x 1 you can split it to single squares in just one break, but for size 3 x 1 you must perform two breaks.
//
//If input data is invalid you should return 0 (as in no breaks are needed if we do not have any chocolate to split). Input will always be a non-negative integer.
fun breakChocolate(n: Int, m: Int): Int = if ((n in 0..1) && (m in 0..1)) {
0