Merge branch 'tests-setup' into olive-green

This commit is contained in:
Sad Ellie 2023-10-01 13:27:09 +03:00
commit ac65677695
40 changed files with 490 additions and 262 deletions

View File

@ -21,6 +21,8 @@ plugins {
id("com.android.application")
id("kotlin-android")
id("unitto.android.application.jacoco")
id("jacoco")
id("unitto.android.hilt")
}
@ -56,6 +58,7 @@ android {
isMinifyEnabled = false
isShrinkResources = false
applicationIdSuffix = ".debug"
enableUnitTestCoverage = true
}
// Release with analytics and minified, not debuggable

View File

@ -65,5 +65,15 @@ gradlePlugin {
id = "unitto.room"
implementationClass = "UnittoRoomPlugin"
}
register("unittoAndroidApplicationJacoco") {
id = "unitto.android.application.jacoco"
implementationClass = "UnittoAndroidApplicationJacocoPlugin"
}
register("unittoAndroidLibraryJacocoPlugin") {
id = "unitto.android.library.jacoco"
implementationClass = "UnittoAndroidLibraryJacocoPlugin"
}
}
}

View File

@ -0,0 +1,37 @@
/*
* Unitto is a unit converter for Android
* Copyright (c) 2023 Elshan Agaev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.sadellie.unitto.configureJacoco
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
@Suppress("UNUSED")
class UnittoAndroidApplicationJacocoPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("org.gradle.jacoco")
apply("com.android.application")
}
val extension = extensions.getByType<ApplicationAndroidComponentsExtension>()
configureJacoco(extension)
}
}
}

View File

@ -0,0 +1,37 @@
/*
* Unitto is a unit converter for Android
* Copyright (c) 2023 Elshan Agaev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.sadellie.unitto.configureJacoco
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
@Suppress("UNUSED")
class UnittoAndroidLibraryJacocoPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("org.gradle.jacoco")
apply("com.android.library")
}
val extension = extensions.getByType<LibraryAndroidComponentsExtension>()
configureJacoco(extension)
}
}
}

View File

@ -39,6 +39,12 @@ internal fun Project.configureKotlinAndroid(
minSdk = 21
}
buildTypes {
getByName("debug") {
enableUnitTestCoverage = true
}
}
flavorDimensions += "mainFlavorDimension"
productFlavors {
create("playStore") {}

View File

@ -0,0 +1,90 @@
/*
* Unitto is a unit converter for Android
* Copyright (c) 2023 Elshan Agaev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sadellie.unitto
import com.android.build.api.variant.AndroidComponentsExtension
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
import org.gradle.testing.jacoco.tasks.JacocoReport
import java.util.Locale
private val coverageExclusions = listOf(
// Android
"**/R.class",
"**/R\$*.class",
"**/BuildConfig.*",
"**/Manifest*.*"
)
private fun String.capitalize() = replaceFirstChar {
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString()
}
internal fun Project.configureJacoco(
androidComponentsExtension: AndroidComponentsExtension<*, *, *>,
) {
configure<JacocoPluginExtension> {
toolVersion = libs.findVersion("orgJacocoOrgJacocoCore").get().toString()
}
val jacocoTestReport = tasks.create("jacocoTestReport")
androidComponentsExtension.onVariants { variant ->
val testTaskName = "test${variant.name.capitalize()}UnitTest"
val reportTask = tasks.register("jacoco${testTaskName.capitalize()}Report", JacocoReport::class) {
dependsOn(testTaskName)
reports {
xml.required.set(true)
html.required.set(true)
}
classDirectories.setFrom(
fileTree("$buildDir/tmp/kotlin-classes/${variant.name}") {
exclude(coverageExclusions)
}
)
sourceDirectories.setFrom(files("$projectDir/src/main/java", "$projectDir/src/main/kotlin"))
executionData.setFrom(file("$buildDir/jacoco/$testTaskName.exec"))
}
jacocoTestReport.dependsOn(reportTask)
}
tasks.withType<Test>().configureEach {
configure<JacocoTaskExtension> {
// Required for JaCoCo + Robolectric
isIncludeNoLocationClasses = true
// Required for JDK 11 with the above
// https://github.com/gradle/gradle/issues/5184#issuecomment-391982009
excludes = listOf("jdk.internal.*")
}
}
}

View File

@ -16,15 +16,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
plugins {
id("unitto.library")
id("unitto.android.hilt")
}
package com.sadellie.unitto
android {
namespace = "com.sadellie.unitto.data.epoch"
}
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType
dependencies {
testImplementation(libs.junit.junit)
}
val Project.libs
get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")

View File

@ -18,6 +18,7 @@
plugins {
id("unitto.library")
id("unitto.android.library.jacoco")
}
android {
@ -44,9 +45,9 @@ android {
buildConfig = true
}
lint {
this.warning.add("MissingTranslation")
}
testOptions.unitTests.isIncludeAndroidResources = true
lint.warning.add("MissingTranslation")
}
fun com.android.build.api.dsl.VariantDimension.storeLink(url: String) {
@ -56,3 +57,7 @@ fun com.android.build.api.dsl.VariantDimension.storeLink(url: String) {
"\"${url}\""
)
}
dependencies {
testImplementation(libs.junit.junit)
}

View File

@ -19,7 +19,7 @@
package com.sadellie.unitto.core.base
/**
* Output format here means whether or now use engineering notation
* Output format here means whether or not use engineering notation
*/
object OutputFormat {
// Never use engineering notation

View File

@ -0,0 +1,45 @@
/*
* Unitto is a unit converter for Android
* Copyright (c) 2023 Elshan Agaev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sadellie.unitto.core.base
import org.junit.Assert
import org.junit.Test
class OutputFormatTest {
@Test
fun testExists() {
Assert.assertNotNull(OutputFormat)
}
@Test
fun testOutputFormatPlain() {
Assert.assertEquals(0, OutputFormat.PLAIN)
}
@Test
fun testOutputFormatAllowEngineering() {
Assert.assertEquals(1, OutputFormat.ALLOW_ENGINEERING)
}
@Test
fun testOutputFormatForceEngineering() {
Assert.assertEquals(2, OutputFormat.FORCE_ENGINEERING)
}
}

View File

@ -0,0 +1,45 @@
/*
* Unitto is a unit converter for Android
* Copyright (c) 2023 Elshan Agaev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sadellie.unitto.core.base
import org.junit.Assert
import org.junit.Test
class SeparatorTest {
@Test
fun testExists() {
Assert.assertNotNull(Separator)
}
@Test
fun testSeparatorSpace() {
Assert.assertEquals(0, Separator.SPACE)
}
@Test
fun testSeparatorPeriod() {
Assert.assertEquals(1, Separator.PERIOD)
}
@Test
fun testSeparatorComma() {
Assert.assertEquals(2, Separator.COMMA)
}
}

View File

@ -0,0 +1,150 @@
/*
* Unitto is a unit converter for Android
* Copyright (c) 2023 Elshan Agaev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sadellie.unitto.core.base
import org.junit.Assert
import org.junit.Test
class TokenTest {
@Test
fun testDigit() {
Assert.assertEquals("1234567890", Token.Digit.all.joinToString(""))
Assert.assertEquals("1234567890.", Token.Digit.allWithDot.joinToString(""))
}
@Test
fun testLetter() {
Assert.assertEquals("ABCDEF", Token.Letter.all.joinToString(""))
}
@Test
fun testOperator() {
listOf(
"+",
"",
"×",
"÷",
"(",
")",
"^",
"!",
"#",
"%",
"",
).forEach {
assert(it in Token.Operator.all)
}
}
@Test
fun testFunc() {
listOf(
"sin",
"cos",
"tan",
"sin⁻¹",
"cos⁻¹",
"tan⁻¹",
"ln",
"log",
"exp",
).forEach {
assert(it in Token.Func.all)
}
listOf(
"sin(",
"cos(",
"tan(",
"sin⁻¹(",
"cos⁻¹(",
"tan⁻¹(",
"ln(",
"log(",
"exp(",
).forEach {
assert(it in Token.Func.allWithOpeningBracket)
}
}
@Test
fun testConst() {
listOf(
"π",
"e",
).forEach {
assert(it in Token.Const.all)
}
}
@Test
fun testExpressionTokens() {
val operator = listOf(
"+",
"",
"×",
"÷",
"(",
")",
"^",
"!",
"#",
"%",
"",
).joinToString("")
val func = listOf(
"sin⁻¹",
"cos⁻¹",
"tan⁻¹",
"sin",
"cos",
"tan",
"log",
"exp",
"ln",
).joinToString("")
val consts = listOf(
"π",
"e",
).joinToString("")
Assert.assertEquals("1234567890.$operator$func$consts", Token.expressionTokens.joinToString(""))
}
@Test
fun testNumberBaseTokens() {
Assert.assertEquals("1234567890ABCDEF", Token.numberBaseTokens.joinToString(""))
}
@Test
fun testDisplayOnlyObject() {
Assert.assertNotNull(Token.DisplayOnly)
}
@Test
fun testSexyToUgly() {
listOf(
"", "÷", "×", "sin⁻¹", "cos⁻¹", "tan⁻¹"
).forEach {
assert(it in Token.sexyToUgly.keys)
}
}
}

View File

@ -22,23 +22,20 @@ plugins {
id("unitto.library")
id("unitto.library.compose")
id("unitto.android.hilt")
id("unitto.android.library.jacoco")
}
android {
namespace = "com.sadellie.unitto.core.ui"
// Workaround from https://github.com/robolectric/robolectric/pull/4736
testOptions {
unitTests {
isIncludeAndroidResources = true
}
}
testOptions.unitTests.isIncludeAndroidResources = true
}
dependencies {
testImplementation(libs.junit.junit)
testImplementation(libs.org.robolectric.robolectric)
testImplementation(libs.androidx.compose.ui.test.junit4)
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
debugImplementation(libs.androidx.compose.ui.test.manifest)
implementation(libs.androidx.navigation.navigation.compose)

View File

@ -18,23 +18,21 @@
package com.sadellie.unitto.core.ui
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import com.sadellie.unitto.core.ui.datetime.formatOffset
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.assertEquals
import org.robolectric.RobolectricTestRunner
import java.time.ZonedDateTime
@RunWith(RobolectricTestRunner::class)
class ZonedDateTimeUtilsTest {
@get: Rule
val composeTestRule = createComposeRule()
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
@Test
fun `no difference`() = composeTestRule.setContent {
fun noDifference() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(12)
.withMinute(0)
@ -45,7 +43,7 @@ class ZonedDateTimeUtilsTest {
}
@Test
fun `show positive hour`() = composeTestRule.setContent {
fun showPositiveHour() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(12)
.withMinute(0)
@ -58,7 +56,7 @@ class ZonedDateTimeUtilsTest {
}
@Test
fun `show positive hour minute`() = composeTestRule.setContent {
fun showPositiveHourMinute() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(12)
.withMinute(0)
@ -71,7 +69,7 @@ class ZonedDateTimeUtilsTest {
}
@Test
fun `show positive hour minute day`() = composeTestRule.setContent {
fun showPositiveHourMinuteDay() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(12)
.withMinute(0)
@ -84,7 +82,7 @@ class ZonedDateTimeUtilsTest {
}
@Test
fun `show positive minute`() = composeTestRule.setContent {
fun showPositiveMinute() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(12)
.withMinute(0)
@ -97,7 +95,7 @@ class ZonedDateTimeUtilsTest {
}
@Test
fun `show positive minute day`() = composeTestRule.setContent {
fun showPositiveMinuteDay() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(23)
.withMinute(45)
@ -110,7 +108,7 @@ class ZonedDateTimeUtilsTest {
}
@Test
fun `show negative hour`() = composeTestRule.setContent {
fun showNegativeHour() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(12)
.withMinute(0)
@ -123,7 +121,7 @@ class ZonedDateTimeUtilsTest {
}
@Test
fun `show negative hour minute`() = composeTestRule.setContent {
fun showNegativeHourMinute() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(12)
.withMinute(0)
@ -136,7 +134,7 @@ class ZonedDateTimeUtilsTest {
}
@Test
fun `show negative hour minute day`() = composeTestRule.setContent {
fun showNegativeHourMinuteDay() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(12)
.withMinute(0)
@ -149,7 +147,7 @@ class ZonedDateTimeUtilsTest {
}
@Test
fun `show negative minute`() = composeTestRule.setContent {
fun showNegativeMinute() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(12)
.withMinute(0)
@ -162,7 +160,7 @@ class ZonedDateTimeUtilsTest {
}
@Test
fun `show negative minute day`() = composeTestRule.setContent {
fun showNegativeMinuteDay() = composeTestRule.setContent {
val currentTime = ZonedDateTime.now()
.withHour(0)
.withMinute(15)

View File

@ -18,14 +18,10 @@
package com.sadellie.unitto.core.ui
import androidx.compose.ui.test.junit4.createComposeRule
import com.sadellie.unitto.core.ui.common.textfield.FormatterSymbols
import com.sadellie.unitto.core.ui.common.textfield.formatExpression
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
private const val ENG_VALUE = "123E+21"
private const val ENG_VALUE_FRACTIONAL = "123.3E+21"
@ -37,12 +33,8 @@ private const val COMPLETE_EXPR = "50+123456÷8×0.8-12+0-√9×4^9+2×(9+8×7)"
private const val LONG_HALF_COMPLETE_EXPR = "50+123456÷89078..9×0.8-12+0-√9×4^9+2×(9+8×7)×sin(13sin123cos"
private const val SOME_BRACKETS = "(((((((("
@RunWith(RobolectricTestRunner::class)
class FormatterTest {
@get: Rule
val composeTestRule = createComposeRule()
@Test
fun setSeparatorSpaces() {
fun String.format(): String = formatExpression(FormatterSymbols.Spaces)

View File

@ -19,6 +19,7 @@
plugins {
id("unitto.library")
id("unitto.android.hilt")
id("unitto.android.library.jacoco")
}
android {

View File

@ -18,6 +18,7 @@
plugins {
id("unitto.library")
id("unitto.android.library.jacoco")
}
android {

View File

@ -20,6 +20,7 @@ plugins {
id("unitto.library")
id("unitto.android.hilt")
id("unitto.room")
id("unitto.android.library.jacoco")
}
android {

View File

@ -1 +0,0 @@
/build

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Unitto is a unit converter for Android
~ Copyright (c) 2023 Elshan Agaev
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<manifest>
</manifest>

View File

@ -1,50 +0,0 @@
/*
* Unitto is a unit converter for Android
* Copyright (c) 2023 Elshan Agaev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sadellie.unitto.data.epoch
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeParseException
object EpochDateConverter {
private val pattern by lazy {
DateTimeFormatter.ofPattern("HHmmssddMMyyyy")
}
fun convertDateToUnix(date: String): String {
return try {
// Here we add some zeros, so that input is 14 symbols long
LocalDateTime
.parse(date.padEnd(14, '0'), pattern)
.toEpochSecond(ZoneOffset.UTC)
} catch (e: DateTimeParseException) {
0
}.toString()
}
fun convertUnixToDate(unix: String): String {
val unixLong = unix.toLong().takeIf { it <= 253402300559L }
?: throw IllegalArgumentException("Max unix is 253402300559")
return LocalDateTime
.ofEpochSecond(unixLong, 0, ZoneOffset.UTC)
.format(pattern)
}
}

View File

@ -1,60 +0,0 @@
/*
* Unitto is a unit converter for Android
* Copyright (c) 2023 Elshan Agaev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sadellie.unitto.data.epoch
import org.junit.Assert.assertEquals
import org.junit.Test
class DateToEpochTest {
@Test
fun `00h0m00s 00 00 0000`() {
convertDateToUnixTest("00:00:00 00.00.0000", "0")
}
@Test
fun `00h00m00s 01 01 0001`() {
convertDateToUnixTest("00:00:00 01.01.0001", "-62135596800")
}
@Test
fun `00h00m00s 01 01 1970`() {
convertDateToUnixTest("00:00:00 01.01.1970", "0")
}
@Test
fun `23h55m59s 31 12 9999`() {
convertDateToUnixTest("23:55:59 31.12.9999", "253402300559")
}
@Test
fun `99h99m99s 99 99 9999`() {
convertDateToUnixTest("99:99:99 99.99.9999", "0")
}
private fun convertDateToUnixTest(inputDate: String, expectedUnix: String) {
// Date input comes "fancy"
val cleanInputDate = inputDate.filter{ it.isDigit() }
assertEquals(
"Couldn't convert $inputDate ($cleanInputDate) into unix",
expectedUnix,
EpochDateConverter.convertDateToUnix(cleanInputDate)
)
}
}

View File

@ -1,72 +0,0 @@
/*
* Unitto is a unit converter for Android
* Copyright (c) 2023 Elshan Agaev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sadellie.unitto.data.epoch
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Test
class EpochToDateTest {
@Test
fun `0`() {
convertUnixToDate("0", "00:00:00 01.01.1970")
}
@Test
fun `00000000000000 max input length`() {
convertUnixToDate("00000000000000", "00:00:00 01.01.1970")
}
@Test
fun `253402300559 max possible date`() {
convertUnixToDate("253402300559", "23:55:59 31.12.9999")
}
@Test
fun `2534023005599999 input longe than allowed`() {
convertUnixToDate("2534023005599999", "23:55:59 31.12.9999", IllegalArgumentException())
}
@Test
fun `99999999999999 max possible unix with max length`() {
convertUnixToDate("99999999999999", "23:55:59 31.12.9999", IllegalArgumentException())
}
private fun convertUnixToDate(inputUnix: String, expectedDate: String, throwable: Throwable? = null) {
// Date input comes "fancy"
val cleanExpectedDate = expectedDate.filter{ it.isDigit() }
// Will throw
if (throwable != null) {
assertThrows(
"Failed to throw ${throwable.javaClass} when converting $inputUnix into $expectedDate ($cleanExpectedDate)",
throwable.javaClass
) { EpochDateConverter.convertUnixToDate(inputUnix) }
return
}
// Should actually convert
assertEquals(
"Couldn't convert $inputUnix into $expectedDate ($cleanExpectedDate)",
cleanExpectedDate,
EpochDateConverter.convertUnixToDate(inputUnix)
)
}
}

View File

@ -18,6 +18,7 @@
plugins {
id("unitto.library")
id("unitto.android.library.jacoco")
}
android {

View File

@ -39,4 +39,7 @@ class ExpressionExceptionsTest {
@Test
fun `ugly ahh expression2`() = assertExprFail(TokenizerException.BadNumber::class.java, "...")
@Test
fun `too big`() = assertExprFail(ExpressionException.TooBig::class.java, "999999!")
}

View File

@ -19,6 +19,7 @@
plugins {
id("unitto.library")
id("unitto.android.hilt")
id("unitto.android.library.jacoco")
}
android {

View File

@ -18,6 +18,7 @@
plugins {
id("unitto.library")
id("unitto.android.library.jacoco")
}
android {

View File

@ -19,6 +19,7 @@
plugins {
id("unitto.library")
id("unitto.android.hilt")
id("unitto.android.library.jacoco")
}
android {

View File

@ -20,6 +20,7 @@ plugins {
id("unitto.library")
id("unitto.android.hilt")
id("unitto.room")
id("unitto.android.library.jacoco")
}
android {

View File

@ -40,9 +40,11 @@ class AllUnitsTest {
private var history: MutableMap<UnitGroup, Set<String>> = mutableMapOf()
private val mContext: Context = RuntimeEnvironment.getApplication().applicationContext
private val database = Room.inMemoryDatabaseBuilder(mContext, UnittoDatabase::class.java).build()
private val allUnitsRepository = UnitsRepository(
Room.inMemoryDatabaseBuilder(mContext, UnittoDatabase::class.java).build().unitsDao(),
mContext
unitsDao = database.unitsDao(),
currencyRatesDao = database.currencyRatesDao(),
mContext = mContext
)
@Test

View File

@ -38,7 +38,7 @@ val baseList = listOf(
NormalUnit("", BigDecimal.ONE, UnitGroup.ANGLE, R.string.kilometer, R.string.kilometer_short),
NormalUnit("", BigDecimal.ONE, UnitGroup.ANGLE, R.string.mile, R.string.mile_short),
NormalUnit("", BigDecimal.ONE, UnitGroup.ANGLE, R.string.pound, R.string.pound_short),
NormalUnit("", BigDecimal.ONE, UnitGroup.ANGLE, R.string.kilometer_per_square_second, R.string.kilometer_per_square_second_short),
NormalUnit("", BigDecimal.ONE, UnitGroup.ANGLE, R.string.kilometer_per_second, R.string.kilometer_per_second_short),
)
@RunWith(RobolectricTestRunner::class)
@ -52,7 +52,7 @@ class LevenshteinFilterAndSortTest {
val result = baseList.asSequence().filterByLev(searchQuery, mContext).map { mContext.getString(it.displayName) }.toList()
println(result)
assertEquals(
listOf("Kilometer", "Kilometer per square", "Attometer", "Nanometer"),
listOf("Kilometer", "Kilometer/second", "Attometer", "Nanometer"),
result
)
}
@ -63,7 +63,7 @@ class LevenshteinFilterAndSortTest {
val result = baseList.asSequence().filterByLev(searchQuery, mContext).map { mContext.getString(it.displayName) }.toList()
println(result)
assertEquals(
listOf("Kilometer per square", "Kilometer"),
listOf("Kilometer", "Kilometer/second"),
result
)
}
@ -74,7 +74,7 @@ class LevenshteinFilterAndSortTest {
val result = baseList.asSequence().filterByLev(searchQuery, mContext).map { mContext.getString(it.displayName) }.toList()
println(result)
assertEquals(
listOf("Meter", "Attometer", "Nanometer", "Millimeter", "Kilometer","Kilometer per square"),
listOf("Meter", "Attometer", "Nanometer", "Millimeter", "Kilometer","Kilometer/second"),
result
)
}
@ -96,7 +96,7 @@ class LevenshteinFilterAndSortTest {
val result = baseList.asSequence().filterByLev(searchQuery, mContext).map { mContext.getString(it.displayName) }.toList()
println(result)
assertEquals(
listOf("Attometer", "Nanometer", "Millimeter", "Meter", "Kilometer", "Kilometer per square"),
listOf("Attometer", "Nanometer", "Millimeter", "Meter", "Kilometer", "Kilometer/second"),
result
)
}

View File

@ -19,6 +19,7 @@
plugins {
id("unitto.library")
id("unitto.android.hilt")
id("unitto.android.library.jacoco")
}
android {

View File

@ -21,6 +21,7 @@ plugins {
id("unitto.library.compose")
id("unitto.library.feature")
id("unitto.android.hilt")
id("unitto.android.library.jacoco")
}
android {

View File

@ -21,6 +21,7 @@ plugins {
id("unitto.library.compose")
id("unitto.library.feature")
id("unitto.android.hilt")
id("unitto.android.library.jacoco")
}
android {

View File

@ -21,6 +21,7 @@ plugins {
id("unitto.library.compose")
id("unitto.library.feature")
id("unitto.android.hilt")
id("unitto.android.library.jacoco")
}
android {

View File

@ -24,10 +24,10 @@ import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
class ZonedDateTimeDifferenceKtTest {
private val fromatt: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
private val `may 1 2023`: ZonedDateTime = ZonedDateTime.parse("2023-05-01 12:00", fromatt)
private val `may 2 2023`: ZonedDateTime = ZonedDateTime.parse("2023-05-02 12:00", fromatt)
private val `june 1 2023`: ZonedDateTime = ZonedDateTime.parse("2023-06-01 12:00", fromatt)
private val formatter: DateTimeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME
private val `may 1 2023`: ZonedDateTime = ZonedDateTime.parse("2023-05-01T12:00+01:00[Europe/Paris]", formatter)
private val `may 2 2023`: ZonedDateTime = ZonedDateTime.parse("2023-05-02T12:00+01:00[Europe/Paris]", formatter)
private val `june 1 2023`: ZonedDateTime = ZonedDateTime.parse("2023-06-01T12:00+01:00[Europe/Paris]", formatter)
@Test
fun `same dates`() {

View File

@ -21,6 +21,7 @@ plugins {
id("unitto.library.compose")
id("unitto.library.feature")
id("unitto.android.hilt")
id("unitto.android.library.jacoco")
}
android {

View File

@ -21,6 +21,7 @@ plugins {
id("unitto.library.compose")
id("unitto.library.feature")
id("unitto.android.hilt")
id("unitto.android.library.jacoco")
}
android {

View File

@ -22,6 +22,7 @@ comGoogleAccompanistAccompanistSystemuicontroller = "0.30.1"
comGoogleDagger = "2.47"
comSquareupMoshiMoshiKotlin = "1.15.0"
comSquareupRetrofit2ConverterMoshi = "2.9.0"
orgJacocoOrgJacocoCore = "0.8.10"
junitJunit = "4.13.2"
kotlin = "1.9.0"
ksp = "1.9.0-1.0.13"
@ -68,6 +69,7 @@ android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", ver
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
com-google-dagger = { group = "com.google.dagger", name = "hilt-android-gradle-plugin", version.ref = "comGoogleDagger" }
ksp-gradlePlugin = { group = "com.google.devtools.ksp", name = "com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" }
org-jacoco-org-jacoco-core = { group = "org.jacoco", name = "org.jacoco.core", version.ref = "orgJacocoOrgJacocoCore" }
[plugins]
android-gradlePlugin = { id = "com.android.application", version.ref = "androidGradlePlugin" }