Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0a44de
commit 177e984
Showing
30 changed files
with
545 additions
and
29 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
buildscript { | ||
ext.kotlin_version = '1.2.20' | ||
ext.kotlin_version = '1.2.21' | ||
repositories { | ||
jcenter() | ||
google() | ||
|
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 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 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 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 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 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 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 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 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 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 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 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 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
78 changes: 78 additions & 0 deletions
78
lemniscate/src/test/java/com/vlad1m1r/lemniscate/base/BaseCurveProgressViewTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.vlad1m1r.lemniscate.base | ||
|
||
import android.view.View | ||
import com.google.common.truth.Truth.assertThat | ||
import com.nhaarman.mockito_kotlin.any | ||
import com.nhaarman.mockito_kotlin.doCallRealMethod | ||
import com.nhaarman.mockito_kotlin.mock | ||
import com.nhaarman.mockito_kotlin.whenever | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
|
||
class BaseCurveProgressViewTest { | ||
|
||
val baseCurve: BaseCurve = BaseCurve() | ||
|
||
val baseCurveProgressView = mock<BaseCurveProgressView>() | ||
|
||
@Before | ||
fun setUp() { | ||
doCallRealMethod().whenever(baseCurveProgressView).getMaxViewSquareSize(any(), any(), any(), any()) | ||
doCallRealMethod().whenever(baseCurveProgressView).getViewDimension(any(), any(), any()) | ||
} | ||
|
||
@Test | ||
fun getMaxViewSquareSize() { | ||
assertThat(baseCurveProgressView.getMaxViewSquareSize(100, 200, 30, 50)).isEqualTo(100-50) | ||
assertThat(baseCurveProgressView.getMaxViewSquareSize(220, 150, 30, 50)).isEqualTo(150-30) | ||
} | ||
|
||
@Test | ||
fun getViewDimensionWhenViewSizeIsZero() { | ||
val defaultSize = 10f | ||
assertThat(baseCurveProgressView.getViewDimension(View.MeasureSpec.AT_MOST, 0f, defaultSize)).isEqualTo(defaultSize) | ||
} | ||
|
||
@Test | ||
fun getViewDimensionWhenExactly() { | ||
val viewSize = 10f | ||
assertThat(baseCurveProgressView.getViewDimension(View.MeasureSpec.EXACTLY, viewSize, 10f)).isEqualTo(viewSize) | ||
} | ||
|
||
@Test | ||
fun getViewDimensionWhenAtMost() { | ||
assertThat(baseCurveProgressView.getViewDimension(View.MeasureSpec.AT_MOST, 10f, 20f)).isEqualTo(10f) | ||
assertThat(baseCurveProgressView.getViewDimension(View.MeasureSpec.AT_MOST, 30f, 20f)).isEqualTo(20f) | ||
} | ||
|
||
@Test | ||
fun getViewDimensionWhenUnspecified() { | ||
val defaultSize = 10f | ||
assertThat(baseCurveProgressView.getViewDimension(View.MeasureSpec.UNSPECIFIED, 20f, defaultSize)).isEqualTo(defaultSize) | ||
} | ||
|
||
@Test | ||
fun getT() { | ||
assertThat(baseCurve.getT(0, 10)).isEqualTo(0.0f) | ||
assertThat(baseCurve.getT(1, 10)).isEqualTo(0.62831855f) | ||
assertThat(baseCurve.getT(10, 10)).isEqualTo(6.2831855f) | ||
assertThat(baseCurve.getT(99, 8)).isEqualTo(77.75442f) | ||
assertThat(baseCurve.getT(-1, 10)).isEqualTo(-0.62831855f) | ||
assertThat(baseCurve.getT(-10, 10)).isEqualTo(-6.2831855f) | ||
} | ||
|
||
inner class BaseCurve : IBaseCurveView { | ||
override fun getGraphX(t: Float): Float { | ||
return 0f | ||
} | ||
|
||
override fun getGraphY(t: Float): Float { | ||
return 0f | ||
} | ||
|
||
override fun invalidateProgressView() {} | ||
|
||
override fun requestProgressViewLayout() {} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
lemniscate/src/test/java/com/vlad1m1r/lemniscate/base/BaseProgressViewAttributesTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.vlad1m1r.lemniscate.base | ||
|
||
import android.content.Context | ||
import android.content.res.TypedArray | ||
import android.util.AttributeSet | ||
import com.google.common.truth.Truth.assertThat | ||
import com.nhaarman.mockito_kotlin.* | ||
import com.vlad1m1r.lemniscate.BernoullisProgressView | ||
import com.vlad1m1r.lemniscate.sample.lemniscate.R | ||
import com.vlad1m1r.lemniscate.testutils.TestLayoutInflater | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.RuntimeEnvironment | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class BaseProgressViewAttributesTest { | ||
|
||
val context = RuntimeEnvironment.application.applicationContext | ||
val typedArray = mock<TypedArray>() | ||
val atributeSet = mock<AttributeSet>() | ||
|
||
val contextSpy = spy(context) | ||
|
||
@Before | ||
fun setUp() { | ||
|
||
val layoutInflater = TestLayoutInflater(contextSpy) | ||
whenever(contextSpy.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) | ||
.thenReturn(layoutInflater) | ||
|
||
whenever(typedArray.getFloat(eq(R.styleable.BaseCurveProgressView_maxLineLength), any())).thenReturn(0.81f) | ||
whenever(typedArray.getFloat(eq(R.styleable.BaseCurveProgressView_minLineLength), any())).thenReturn(0.23f) | ||
|
||
whenever(typedArray.getColor(eq(R.styleable.BaseCurveProgressView_lineColor), any())).thenReturn(123) | ||
whenever(typedArray.getBoolean(eq(R.styleable.BaseCurveProgressView_hasHole), any())).thenReturn(true) | ||
whenever(typedArray.getDimension(eq(R.styleable.BaseCurveProgressView_strokeWidth), any())).thenReturn(32.2f) | ||
whenever(typedArray.getInteger(eq(R.styleable.BaseCurveProgressView_precision), any())).thenReturn(111) | ||
|
||
whenever(typedArray.getInteger(eq(R.styleable.BaseCurveProgressView_duration), any())).thenReturn(999) | ||
|
||
doReturn(typedArray).whenever(contextSpy).obtainStyledAttributes(atributeSet, R.styleable.BaseCurveProgressView, 0, 0) | ||
} | ||
|
||
@Test | ||
fun constructorWithAttributeSet() { | ||
val bernoullisProgressView = BernoullisProgressView(contextSpy, atributeSet) | ||
assertThat(bernoullisProgressView.lineMaxLength).isEqualTo(0.81f) | ||
assertThat(bernoullisProgressView.lineMinLength).isEqualTo(0.23f) | ||
|
||
assertThat(bernoullisProgressView.color).isEqualTo(123) | ||
assertThat(bernoullisProgressView.hasHole).isTrue() | ||
assertThat(bernoullisProgressView.strokeWidth).isEqualTo(32.2f) | ||
assertThat(bernoullisProgressView.precision).isEqualTo(111) | ||
|
||
assertThat(bernoullisProgressView.duration).isEqualTo(999) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
lemniscate/src/test/java/com/vlad1m1r/lemniscate/base/models/LineLengthParcelableTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.vlad1m1r.lemniscate.base.models | ||
|
||
import android.os.Parcel | ||
import com.google.common.truth.Truth.assertThat | ||
import com.vlad1m1r.lemniscate.testutils.isEqualTo | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class LineLengthParcelableTest { | ||
|
||
private lateinit var lineLength: LineLength | ||
|
||
@Before | ||
fun setUp() { | ||
lineLength = LineLength() | ||
lineLength.lineMinLength = 0.24f | ||
lineLength.lineMaxLength = 0.83f | ||
} | ||
|
||
@Test | ||
fun parcelable() { | ||
val parcel = Parcel.obtain() | ||
lineLength.writeToParcel(parcel, 0) | ||
parcel.setDataPosition(0) | ||
|
||
val copy = LineLength(parcel) | ||
parcel.recycle() | ||
|
||
assertThat(lineLength.isEqualTo(copy)).isTrue() | ||
} | ||
} |
Oops, something went wrong.