diff --git a/README.md b/README.md index 1fc01fe4..e71ded94 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ + +

+ +

+
+ +# Unitto – calculator and unit converter +

@@ -10,7 +18,7 @@ ## 📲 Download Google Play F-Droid -AppGallery +RuMarket ## 😎 Features - Instant expression evaluation diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1fe6b8ed..4886f509 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -32,7 +32,7 @@ android { applicationId = "com.sadellie.unitto" minSdk = 21 targetSdk = 33 - versionCode = 17 + versionCode = 18 versionName = "Illuminating emerald" } diff --git a/core/base/src/main/res/values/strings.xml b/core/base/src/main/res/values/strings.xml index 5de74fb9..5f0d9e45 100644 --- a/core/base/src/main/res/values/strings.xml +++ b/core/base/src/main/res/values/strings.xml @@ -122,47 +122,47 @@ K - Millimeter per hour + Millimeter/hour mm/h - Millimeter per minute + Millimeter/minute mm/m - Millimeter per second + Millimeter/second mm/s - Centimeter per hour + Centimeter/hour cm/h - Centimeter per minute + Centimeter/minute cm/m - Centimeter per second + Centimeter/second cm/s - Meter per hour + Meter/hour m/h - Meter per minute + Meter/minute m/m - Meter per second + Meter/second m/s - Kilometer per hour + Kilometer/hour km/h - Kilometer per minute + Kilometer/minute km/m - Kilometer per second + Kilometer/second km/s - Foot per hour + Foot/hour ft/h - Foot per minute + Foot/minute ft/m - Foot per second + Foot/second ft/s - Yard per hour + Yard/hour yd/h - Yard per minute + Yard/minute yd/m - Yard per second + Yard/second yd/s - Mile per hour + Mile/hour mi/h - Mile per minute + Mile/minute mi/m - Mile per second + Mile/second mi/s Knot kt @@ -220,41 +220,41 @@ EB - Bit per second + Bit/second b/s - Kibibit per second + Kibibit/second Kib/s - Kilobit per second + Kilobit/second Kb/s - Megabit per second + Megabit/second Mb/s - Mebibit per second + Mebibit/second Mib/s - Gigabit per second + Gigabit/second Gb/s - Terabit per second + Terabit/second Tb/s - Petabit per second + Petabit/second Pb/s - Exabit per second + Exabit/second Eb/s - Byte per second + Byte/second B/s - Kibibyte per second + Kibibyte/second KiB/s - Kilobyte per second + Kilobyte/second KB/s - Megabyte per second + Megabyte/second MB/s - Mebibyte per second + Mebibyte/second MiB/s - Gigabyte per second + Gigabyte/second GB/s - Terabyte per second + Terabyte/second TB/s - Petabyte per second + Petabyte/second PB/s - Exabyte per second + Exabyte/second EB/s @@ -446,9 +446,9 @@ PPa Exapascal EPa - Pound per square inch + Pound/square inch psi - Kilopound per square inch + Kilopound/square inch ksi Standard atmosphere atm @@ -460,29 +460,29 @@ mm Hg - Attometer per square second + Attometer/square second am/s^2 - Femtometer per square second + Femtometer/square second fm/s^2 - Picometer per square second + Picometer/square second pm/s^2 - Nanometer per square second + Nanometer/square second nm/s^2 - Micrometer per square second + Micrometer/square second µm/s^2 - Millimeter per square second + Millimeter/square second mm/s^2 - Centimeter per square second + Centimeter/square second cm/s^2 - Decimeter per square second + Decimeter/square second dm/s^2 - Meter per square second + Meter/square second m/s^2 - Kilometer per square second + Kilometer/square second km/s^2 - Dekameter per square second + Dekameter/square second dam/s^2 - Hectometer per square second + Hectometer/square second hm/s^2 Gal Gal @@ -971,6 +971,152 @@ Hexadecimal base16 + + Attofarad + aF + Statfarad + stF + Farad + F + Exafarad + EF + Picofarad + pF + Nanofarad + nF + Microfarad + µF + Millifarad + mF + Kilofarad + kF + Megafarad + MF + Gigafarad + GF + Petafarad + PF + + + Quetta + Q + Ronna + R + Yotta + Y + Zetta + Z + Exa + E + Peta + P + Tera + T + Giga + G + Mega + M + Kilo + k + Hecto + h + Deca + da + Base + Base + Deci + d + Centi + c + Milli + m + Micro + μ + Nano + n + Pico + p + Femto + f + Atto + a + Zepto + z + Yocto + y + Ronto + r + Quecto + q + + + Newton + N + Kilonewton + kN + Gram-force + gf + Kilogram-force + kgf + Ton-force + tf + Millinewton + mN + attonewton + aN + dyne + dyn + Joule/meter + J/m + Joule/centimeter + J/cm + Kilopound-force + kipf + Pound-force + lbf + Ounce-force + ozf + Pond + p + Kilopond + kp + + + Newton meter + N*m + Newton centimeter + N*cm + Newton millimeter + N*mm + Kilonewton meter + kN*m + Dyne meter + dyn*m + Dyne centimeter + dyn*cm + Dyne millimeter + dyn*mm + Kilogram-force meter + kgf*m + Kilogram-force centimeter + kgf*cm + Kilogram-force millimeter + kgf*mm + Gram-force meter + gf*m + Gram-force centimeter + gf*cm + Gram-force millimeter + gf*mm + Ounce-force foot + ozf*ft + Ounce-force inch + ozf*in + Pound-force foot + lbf*ft + Pound-force inch + lbf*in + Length Time @@ -989,6 +1135,10 @@ Currency Flux Base + Capacitance + Prefix + Force + Torque Convert from diff --git a/data/model/src/main/java/com/sadellie/unitto/data/model/UnitGroup.kt b/data/model/src/main/java/com/sadellie/unitto/data/model/UnitGroup.kt index 22f8a7c8..ebc7000f 100644 --- a/data/model/src/main/java/com/sadellie/unitto/data/model/UnitGroup.kt +++ b/data/model/src/main/java/com/sadellie/unitto/data/model/UnitGroup.kt @@ -48,4 +48,8 @@ enum class UnitGroup( DATA_TRANSFER(res = R.string.data_transfer), FLUX(res = R.string.flux), NUMBER_BASE(res = R.string.number_base), + ELECTROSTATIC_CAPACITANCE(res = R.string.electrostatic_capacitance), + PREFIX(res = R.string.prefix), + FORCE(res = R.string.force), + TORQUE(res = R.string.torque), } diff --git a/data/units/src/main/java/com/sadellie/unitto/data/units/AllUnitsRepository.kt b/data/units/src/main/java/com/sadellie/unitto/data/units/AllUnitsRepository.kt index 467b87a2..d1df129b 100644 --- a/data/units/src/main/java/com/sadellie/unitto/data/units/AllUnitsRepository.kt +++ b/data/units/src/main/java/com/sadellie/unitto/data/units/AllUnitsRepository.kt @@ -20,6 +20,7 @@ package com.sadellie.unitto.data.units import android.content.Context import com.sadellie.unitto.core.base.MAX_PRECISION +import com.sadellie.unitto.data.database.UnitsEntity import com.sadellie.unitto.data.model.AbstractUnit import com.sadellie.unitto.data.model.UnitGroup import com.sadellie.unitto.data.model.sortByLev @@ -29,18 +30,21 @@ import com.sadellie.unitto.data.units.collections.areaCollection import com.sadellie.unitto.data.units.collections.currencyCollection import com.sadellie.unitto.data.units.collections.dataCollection import com.sadellie.unitto.data.units.collections.dataTransferCollection +import com.sadellie.unitto.data.units.collections.electrostaticCapacitance import com.sadellie.unitto.data.units.collections.energyCollection import com.sadellie.unitto.data.units.collections.fluxCollection +import com.sadellie.unitto.data.units.collections.forceCollection import com.sadellie.unitto.data.units.collections.lengthCollection import com.sadellie.unitto.data.units.collections.massCollection import com.sadellie.unitto.data.units.collections.numberBaseCollection import com.sadellie.unitto.data.units.collections.powerCollection +import com.sadellie.unitto.data.units.collections.prefixCollection import com.sadellie.unitto.data.units.collections.pressureCollection import com.sadellie.unitto.data.units.collections.speedCollection import com.sadellie.unitto.data.units.collections.temperatureCollection import com.sadellie.unitto.data.units.collections.timeCollection +import com.sadellie.unitto.data.units.collections.torqueCollection import com.sadellie.unitto.data.units.collections.volumeCollection -import com.sadellie.unitto.data.database.UnitsEntity import java.math.BigDecimal import javax.inject.Inject import javax.inject.Singleton @@ -79,6 +83,10 @@ class AllUnitsRepository @Inject constructor() { UnitGroup.DATA_TRANSFER to dataTransferCollection, UnitGroup.FLUX to fluxCollection, UnitGroup.NUMBER_BASE to numberBaseCollection, + UnitGroup.ELECTROSTATIC_CAPACITANCE to electrostaticCapacitance, + UnitGroup.PREFIX to prefixCollection, + UnitGroup.FORCE to forceCollection, + UnitGroup.TORQUE to torqueCollection ) } diff --git a/data/units/src/main/java/com/sadellie/unitto/data/units/MyUnitIDS.kt b/data/units/src/main/java/com/sadellie/unitto/data/units/MyUnitIDS.kt index eb6669a8..cd9e5ed4 100644 --- a/data/units/src/main/java/com/sadellie/unitto/data/units/MyUnitIDS.kt +++ b/data/units/src/main/java/com/sadellie/unitto/data/units/MyUnitIDS.kt @@ -516,4 +516,81 @@ object MyUnitIDS { const val tetradecimal = "tetradecimal" const val pentadecimal = "pentadecimal" const val hexadecimal = "hexadecimal" + + // ELECTROSTATIC CAPACITANCE + const val attofarad = "attofarad" + const val statfarad = "statfarad" + const val farad = "farad" + const val exafarad = "exafarad" + const val picofarad = "picofarad" + const val nanofarad = "nanofarad" + const val microfarad = "microfarad" + const val millifarad = "millifarad" + const val kilofarad = "kilofarad" + const val megafarad = "megafarad" + const val gigafarad = "gigafarad" + const val petafarad = "petafarad" + + // PREFIX + const val prefix_quetta = "quetta" + const val prefix_ronna = "ronna" + const val prefix_yotta = "yotta" + const val prefix_zetta = "zetta" + const val prefix_exa = "exa" + const val prefix_peta = "peta" + const val prefix_tera = "tera" + const val prefix_giga = "giga" + const val prefix_mega = "mega" + const val prefix_kilo = "kilo" + const val prefix_hecto = "hecto" + const val prefix_deca = "deca" + const val prefix_base = "base" + const val prefix_deci = "deci" + const val prefix_centi = "centi" + const val prefix_milli = "milli" + const val prefix_micro = "micro" + const val prefix_nano = "nano" + const val prefix_pico = "pico" + const val prefix_femto = "femto" + const val prefix_atto = "atto" + const val prefix_zepto = "zepto" + const val prefix_yocto = "yocto" + const val prefix_ronto = "ronto" + const val prefix_quecto = "quecto" + + // FORCE + const val newton = "newton" + const val kilonewton = "kilonewton" + const val gram_force = "gram_force" + const val kilogram_force = "kilogram_force" + const val ton_force = "ton_force" + const val millinewton = "millinewton" + const val attonewton = "attonewton" + const val dyne = "dyne" + const val joule_per_meter = "joule_per_meter" + const val joule_per_centimeter = "joule_per_centimeter" + const val kilopound_force = "kilopound_force" + const val pound_force = "pound_force" + const val ounce_force = "ounce_force" + const val pond = "pond" + const val kilopond = "kilopond" + + // TORQUE + const val newton_meter = "newton_meter" + const val newton_centimeter = "newton_centimeter" + const val newton_millimeter = "newton_millimeter" + const val kilonewton_meter = "kilonewton_meter" + const val dyne_meter = "dyne_meter" + const val dyne_centimeter = "dyne_centimeter" + const val dyne_millimeter = "dyne_millimeter" + const val kilogram_force_meter = "kilogram_force_meter" + const val kilogram_force_centimeter = "kilogram_force_centimeter" + const val kilogram_force_millimeter = "kilogram_force_millimeter" + const val gram_force_meter = "gram_force_meter" + const val gram_force_centimeter = "gram_force_centimeter" + const val gram_force_millimeter = "gram_force_millimeter" + const val ounce_force_foot = "ounce_force_foot" + const val ounce_force_inch = "ounce_force_inch" + const val pound_force_foot = "pound_force_foot" + const val pound_force_inch = "pound_force_inch" } diff --git a/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Capacitance.kt b/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Capacitance.kt new file mode 100644 index 00000000..63a997bf --- /dev/null +++ b/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Capacitance.kt @@ -0,0 +1,43 @@ +/* + * 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 . + */ + +package com.sadellie.unitto.data.units.collections + +import com.sadellie.unitto.data.model.AbstractUnit +import com.sadellie.unitto.data.model.MyUnit +import com.sadellie.unitto.data.model.UnitGroup +import com.sadellie.unitto.data.units.MyUnitIDS +import com.sadellie.unitto.data.units.R +import java.math.BigDecimal + +internal val electrostaticCapacitance: List by lazy { + listOf( + MyUnit(MyUnitIDS.attofarad, BigDecimal.valueOf(1), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.attofarad, R.string.attofarad_short), + MyUnit(MyUnitIDS.picofarad, BigDecimal.valueOf(1E+6), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.picofarad, R.string.picofarad_short), + MyUnit(MyUnitIDS.statfarad, BigDecimal.valueOf(1112650.0561), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.statfarad, R.string.statfarad_short), + MyUnit(MyUnitIDS.nanofarad, BigDecimal.valueOf(1E+9), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.nanofarad, R.string.nanofarad_short), + MyUnit(MyUnitIDS.microfarad, BigDecimal.valueOf(1E+12), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.microfarad, R.string.microfarad_short), + MyUnit(MyUnitIDS.millifarad, BigDecimal.valueOf(1E+15), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.millifarad, R.string.millifarad_short), + MyUnit(MyUnitIDS.farad, BigDecimal.valueOf(1E+18), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.farad, R.string.farad_short), + MyUnit(MyUnitIDS.kilofarad, BigDecimal.valueOf(1E+21), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.kilofarad, R.string.kilofarad_short), + MyUnit(MyUnitIDS.megafarad, BigDecimal.valueOf(1E+24), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.megafarad, R.string.megafarad_short), + MyUnit(MyUnitIDS.gigafarad, BigDecimal.valueOf(1E+27), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.gigafarad, R.string.gigafarad_short), + MyUnit(MyUnitIDS.petafarad, BigDecimal.valueOf(1E+33), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.petafarad, R.string.petafarad_short), + MyUnit(MyUnitIDS.exafarad, BigDecimal.valueOf(1E+36), UnitGroup.ELECTROSTATIC_CAPACITANCE, R.string.exafarad, R.string.exafarad_short), + ) +} diff --git a/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Force.kt b/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Force.kt new file mode 100644 index 00000000..b8820adc --- /dev/null +++ b/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Force.kt @@ -0,0 +1,46 @@ +/* + * 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 . + */ + +package com.sadellie.unitto.data.units.collections + +import com.sadellie.unitto.data.model.AbstractUnit +import com.sadellie.unitto.data.model.MyUnit +import com.sadellie.unitto.data.model.UnitGroup +import com.sadellie.unitto.data.units.MyUnitIDS +import com.sadellie.unitto.data.units.R +import java.math.BigDecimal + +val forceCollection: List by lazy { + listOf( + MyUnit(MyUnitIDS.attonewton, BigDecimal.valueOf(1), UnitGroup.FORCE, R.string.attonewton, R.string.attonewton_short), + MyUnit(MyUnitIDS.dyne, BigDecimal.valueOf(1E+13), UnitGroup.FORCE, R.string.dyne, R.string.dyne_short), + MyUnit(MyUnitIDS.millinewton, BigDecimal.valueOf(1E+15), UnitGroup.FORCE, R.string.millinewton, R.string.millinewton_short), + MyUnit(MyUnitIDS.joule_per_centimeter, BigDecimal.valueOf(1E+16), UnitGroup.FORCE, R.string.joule_per_centimeter, R.string.joule_per_centimeter_short), + MyUnit(MyUnitIDS.newton, BigDecimal.valueOf(1E+18), UnitGroup.FORCE, R.string.newton, R.string.newton_short), + MyUnit(MyUnitIDS.joule_per_meter, BigDecimal.valueOf(1E+18), UnitGroup.FORCE, R.string.joule_per_meter, R.string.joule_per_meter_short), + MyUnit(MyUnitIDS.kilonewton, BigDecimal.valueOf(1E+21), UnitGroup.FORCE, R.string.kilonewton, R.string.kilonewton_short), + MyUnit(MyUnitIDS.gram_force, BigDecimal.valueOf(9.80665E+15), UnitGroup.FORCE, R.string.gram_force, R.string.gram_force_short), + MyUnit(MyUnitIDS.kilogram_force, BigDecimal.valueOf(9.80665E+18), UnitGroup.FORCE, R.string.kilogram_force, R.string.kilogram_force_short), + MyUnit(MyUnitIDS.ton_force, BigDecimal.valueOf(9.80665E+21), UnitGroup.FORCE, R.string.ton_force, R.string.ton_force_short), + MyUnit(MyUnitIDS.ounce_force, BigDecimal.valueOf(2.78013850953423008E17), UnitGroup.FORCE, R.string.ounce_force, R.string.ounce_force_short), + MyUnit(MyUnitIDS.pound_force, BigDecimal.valueOf(4.4482216152550001E18), UnitGroup.FORCE, R.string.pound_force, R.string.pound_force_short), + MyUnit(MyUnitIDS.kilopound_force, BigDecimal.valueOf(4.448221615255E+21), UnitGroup.FORCE, R.string.kilopound_force, R.string.kilopound_force_short), + MyUnit(MyUnitIDS.pond, BigDecimal.valueOf(9.80665E+15), UnitGroup.FORCE, R.string.pond, R.string.pond_short), + MyUnit(MyUnitIDS.kilopond, BigDecimal.valueOf(9.80665E+18), UnitGroup.FORCE, R.string.kilopond, R.string.kilopond_short), + ) +} diff --git a/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Prefix.kt b/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Prefix.kt new file mode 100644 index 00000000..45541d76 --- /dev/null +++ b/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Prefix.kt @@ -0,0 +1,56 @@ +/* + * 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 . + */ + +package com.sadellie.unitto.data.units.collections + +import com.sadellie.unitto.data.model.AbstractUnit +import com.sadellie.unitto.data.model.MyUnit +import com.sadellie.unitto.data.model.UnitGroup +import com.sadellie.unitto.data.units.MyUnitIDS +import com.sadellie.unitto.data.units.R +import java.math.BigDecimal + +val prefixCollection: List by lazy { + listOf( + MyUnit(MyUnitIDS.prefix_quetta, BigDecimal.valueOf(1E+30), UnitGroup.PREFIX, R.string.prefix_quetta, R.string.prefix_quetta_short), + MyUnit(MyUnitIDS.prefix_ronna, BigDecimal.valueOf(1E+27), UnitGroup.PREFIX, R.string.prefix_ronna, R.string.prefix_ronna_short), + MyUnit(MyUnitIDS.prefix_yotta, BigDecimal.valueOf(1E+24), UnitGroup.PREFIX, R.string.prefix_yotta, R.string.prefix_yotta_short), + MyUnit(MyUnitIDS.prefix_zetta, BigDecimal.valueOf(1E+21), UnitGroup.PREFIX, R.string.prefix_zetta, R.string.prefix_zetta_short), + MyUnit(MyUnitIDS.prefix_exa, BigDecimal.valueOf(1E+18), UnitGroup.PREFIX, R.string.prefix_exa, R.string.prefix_exa_short), + MyUnit(MyUnitIDS.prefix_peta, BigDecimal.valueOf(1E+15), UnitGroup.PREFIX, R.string.prefix_peta, R.string.prefix_peta_short), + MyUnit(MyUnitIDS.prefix_tera, BigDecimal.valueOf(1E+12), UnitGroup.PREFIX, R.string.prefix_tera, R.string.prefix_tera_short), + MyUnit(MyUnitIDS.prefix_giga, BigDecimal.valueOf(1E+9), UnitGroup.PREFIX, R.string.prefix_giga, R.string.prefix_giga_short), + MyUnit(MyUnitIDS.prefix_mega, BigDecimal.valueOf(1E+6), UnitGroup.PREFIX, R.string.prefix_mega, R.string.prefix_mega_short), + MyUnit(MyUnitIDS.prefix_kilo, BigDecimal.valueOf(1E+3), UnitGroup.PREFIX, R.string.prefix_kilo, R.string.prefix_kilo_short), + MyUnit(MyUnitIDS.prefix_hecto, BigDecimal.valueOf(1E+2), UnitGroup.PREFIX, R.string.prefix_hecto, R.string.prefix_hecto_short), + MyUnit(MyUnitIDS.prefix_deca, BigDecimal.valueOf(1E+1), UnitGroup.PREFIX, R.string.prefix_deca, R.string.prefix_deca_short), + MyUnit(MyUnitIDS.prefix_base, BigDecimal.valueOf(1E+0), UnitGroup.PREFIX, R.string.prefix_base, R.string.prefix_base_short), + MyUnit(MyUnitIDS.prefix_deci, BigDecimal.valueOf(1E-1), UnitGroup.PREFIX, R.string.prefix_deci, R.string.prefix_deci_short), + MyUnit(MyUnitIDS.prefix_centi, BigDecimal.valueOf(1E-2), UnitGroup.PREFIX, R.string.prefix_centi, R.string.prefix_centi_short), + MyUnit(MyUnitIDS.prefix_milli, BigDecimal.valueOf(1E-3), UnitGroup.PREFIX, R.string.prefix_milli, R.string.prefix_milli_short), + MyUnit(MyUnitIDS.prefix_micro, BigDecimal.valueOf(1E-6), UnitGroup.PREFIX, R.string.prefix_micro, R.string.prefix_micro_short), + MyUnit(MyUnitIDS.prefix_nano, BigDecimal.valueOf(1E-9), UnitGroup.PREFIX, R.string.prefix_nano, R.string.prefix_nano_short), + MyUnit(MyUnitIDS.prefix_pico, BigDecimal.valueOf(1E-12), UnitGroup.PREFIX, R.string.prefix_pico, R.string.prefix_pico_short), + MyUnit(MyUnitIDS.prefix_femto, BigDecimal.valueOf(1E-15), UnitGroup.PREFIX, R.string.prefix_femto, R.string.prefix_femto_short), + MyUnit(MyUnitIDS.prefix_atto, BigDecimal.valueOf(1E-18), UnitGroup.PREFIX, R.string.prefix_atto, R.string.prefix_atto_short), + MyUnit(MyUnitIDS.prefix_zepto, BigDecimal.valueOf(1E-21), UnitGroup.PREFIX, R.string.prefix_zepto, R.string.prefix_zepto_short), + MyUnit(MyUnitIDS.prefix_yocto, BigDecimal.valueOf(1E-24), UnitGroup.PREFIX, R.string.prefix_yocto, R.string.prefix_yocto_short), + MyUnit(MyUnitIDS.prefix_ronto, BigDecimal.valueOf(1E-27), UnitGroup.PREFIX, R.string.prefix_ronto, R.string.prefix_ronto_short), + MyUnit(MyUnitIDS.prefix_quecto, BigDecimal.valueOf(1E-30), UnitGroup.PREFIX, R.string.prefix_quecto, R.string.prefix_quecto_short), + ) +} diff --git a/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Torque.kt b/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Torque.kt new file mode 100644 index 00000000..cb945d03 --- /dev/null +++ b/data/units/src/main/java/com/sadellie/unitto/data/units/collections/Torque.kt @@ -0,0 +1,48 @@ +/* + * 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 . + */ + +package com.sadellie.unitto.data.units.collections + +import com.sadellie.unitto.data.model.AbstractUnit +import com.sadellie.unitto.data.model.MyUnit +import com.sadellie.unitto.data.model.UnitGroup +import com.sadellie.unitto.data.units.MyUnitIDS +import com.sadellie.unitto.data.units.R +import java.math.BigDecimal + +val torqueCollection: List by lazy { + listOf( + MyUnit(MyUnitIDS.dyne_millimeter, BigDecimal.valueOf(1), UnitGroup.TORQUE, R.string.dyne_millimeter, R.string.dyne_millimeter_short), + MyUnit(MyUnitIDS.dyne_centimeter, BigDecimal.valueOf(10), UnitGroup.TORQUE, R.string.dyne_centimeter, R.string.dyne_centimeter_short), + MyUnit(MyUnitIDS.dyne_meter, BigDecimal.valueOf(1000), UnitGroup.TORQUE, R.string.dyne_meter, R.string.dyne_meter_short), + MyUnit(MyUnitIDS.newton_millimeter, BigDecimal.valueOf(100000), UnitGroup.TORQUE, R.string.newton_millimeter, R.string.newton_millimeter_short), + MyUnit(MyUnitIDS.newton_centimeter, BigDecimal.valueOf(1000000), UnitGroup.TORQUE, R.string.newton_centimeter, R.string.newton_centimeter_short), + MyUnit(MyUnitIDS.newton_meter, BigDecimal.valueOf(100000000), UnitGroup.TORQUE, R.string.newton_meter, R.string.newton_meter_short), + MyUnit(MyUnitIDS.kilonewton_meter, BigDecimal.valueOf(100000000000), UnitGroup.TORQUE, R.string.kilonewton_meter, R.string.kilonewton_meter_short), + MyUnit(MyUnitIDS.gram_force_millimeter, BigDecimal.valueOf(980.665), UnitGroup.TORQUE, R.string.gram_force_millimeter, R.string.gram_force_millimeter_short), + MyUnit(MyUnitIDS.gram_force_centimeter, BigDecimal.valueOf(9806.65), UnitGroup.TORQUE, R.string.gram_force_centimeter, R.string.gram_force_centimeter_short), + MyUnit(MyUnitIDS.kilogram_force_millimeter, BigDecimal.valueOf(980665), UnitGroup.TORQUE, R.string.kilogram_force_millimeter, R.string.kilogram_force_millimeter_short), + MyUnit(MyUnitIDS.gram_force_meter, BigDecimal.valueOf(980665), UnitGroup.TORQUE, R.string.gram_force_meter, R.string.gram_force_meter_short), + MyUnit(MyUnitIDS.kilogram_force_centimeter, BigDecimal.valueOf(9806650), UnitGroup.TORQUE, R.string.kilogram_force_centimeter, R.string.kilogram_force_centimeter_short), + MyUnit(MyUnitIDS.kilogram_force_meter, BigDecimal.valueOf(980665000), UnitGroup.TORQUE, R.string.kilogram_force_meter, R.string.kilogram_force_meter_short), + MyUnit(MyUnitIDS.ounce_force_foot, BigDecimal.valueOf(8473862.4), UnitGroup.TORQUE, R.string.ounce_force_foot, R.string.ounce_force_foot_short), + MyUnit(MyUnitIDS.ounce_force_inch, BigDecimal.valueOf(706155.2), UnitGroup.TORQUE, R.string.ounce_force_inch, R.string.ounce_force_inch_short), + MyUnit(MyUnitIDS.pound_force_foot, BigDecimal.valueOf(135581800), UnitGroup.TORQUE, R.string.pound_force_foot, R.string.pound_force_foot_short), + MyUnit(MyUnitIDS.pound_force_inch, BigDecimal.valueOf(1.1298483333333334E7), UnitGroup.TORQUE, R.string.pound_force_inch, R.string.pound_force_inch_short), + ) +} diff --git a/data/units/src/test/java/com/sadellie/unitto/data/units/AllUnitsTest.kt b/data/units/src/test/java/com/sadellie/unitto/data/units/AllUnitsTest.kt index 57746019..3bd3347e 100644 --- a/data/units/src/test/java/com/sadellie/unitto/data/units/AllUnitsTest.kt +++ b/data/units/src/test/java/com/sadellie/unitto/data/units/AllUnitsTest.kt @@ -35,344 +35,429 @@ class AllUnitsTest { private val allUnitsRepository = AllUnitsRepository() @Test - fun testAcceleration() { - MyUnitIDS.attometer_per_square_second.checkWith(MyUnitIDS.femtometer_per_square_second, "69", "0.069") - MyUnitIDS.femtometer_per_square_second.checkWith(MyUnitIDS.picometer_per_square_second, "69", "0.069") - MyUnitIDS.picometer_per_square_second.checkWith(MyUnitIDS.micrometer_per_square_second, "69", "0.00007") - MyUnitIDS.nanometer_per_square_second.checkWith(MyUnitIDS.centimeter_per_square_second, "69", "0.000007") - MyUnitIDS.micrometer_per_square_second.checkWith(MyUnitIDS.nanometer_per_square_second, "69", "69000") - MyUnitIDS.millimeter_per_square_second.checkWith(MyUnitIDS.centimeter_per_square_second, "69", "6.9") - MyUnitIDS.centimeter_per_square_second.checkWith(MyUnitIDS.meter_per_square_second, "69", "0.69") - MyUnitIDS.decimeter_per_square_second.checkWith(MyUnitIDS.meter_per_square_second, "69", "6.9") - MyUnitIDS.meter_per_square_second.checkWith(MyUnitIDS.micrometer_per_square_second, "69", "69000000") - MyUnitIDS.kilometer_per_square_second.checkWith(MyUnitIDS.hectometer_per_square_second, "69", "690") - MyUnitIDS.dekameter_per_square_second.checkWith(MyUnitIDS.gal, "69", "69000") - MyUnitIDS.hectometer_per_square_second.checkWith(MyUnitIDS.gal, "69", "690000") - MyUnitIDS.gal.checkWith(MyUnitIDS.centimeter_per_square_second, "69", "69") - MyUnitIDS.mercury_surface_gravity.checkWith(MyUnitIDS.meter_per_square_second, "1", "3.7") - MyUnitIDS.venus_surface_gravity.checkWith(MyUnitIDS.meter_per_square_second, "1", "8.87") - MyUnitIDS.earth_surface_gravity.checkWith(MyUnitIDS.meter_per_square_second, "1", "9.80655") - MyUnitIDS.mars_surface_gravity.checkWith(MyUnitIDS.meter_per_square_second, "1", "3.71") - MyUnitIDS.jupiter_surface_gravity.checkWith(MyUnitIDS.meter_per_square_second, "1", "24.79") - MyUnitIDS.saturn_surface_gravity.checkWith(MyUnitIDS.meter_per_square_second, "1", "10.44") - MyUnitIDS.uranus_surface_gravity.checkWith(MyUnitIDS.meter_per_square_second, "1", "8.87") - MyUnitIDS.neptune_surface_gravity.checkWith(MyUnitIDS.meter_per_square_second, "1", "11.15") - MyUnitIDS.sun_surface_gravity.checkWith(MyUnitIDS.meter_per_square_second, "1", "274") + fun testAcceleration() = testWithUnits { + attometer_per_square_second.checkWith(femtometer_per_square_second, "69", "0.069") + femtometer_per_square_second.checkWith(picometer_per_square_second, "69", "0.069") + picometer_per_square_second.checkWith(micrometer_per_square_second, "69", "0.00007") + nanometer_per_square_second.checkWith(centimeter_per_square_second, "69", "0.000007") + micrometer_per_square_second.checkWith(nanometer_per_square_second, "69", "69000") + millimeter_per_square_second.checkWith(centimeter_per_square_second, "69", "6.9") + centimeter_per_square_second.checkWith(meter_per_square_second, "69", "0.69") + decimeter_per_square_second.checkWith(meter_per_square_second, "69", "6.9") + meter_per_square_second.checkWith(micrometer_per_square_second, "69", "69000000") + kilometer_per_square_second.checkWith(hectometer_per_square_second, "69", "690") + dekameter_per_square_second.checkWith(gal, "69", "69000") + hectometer_per_square_second.checkWith(gal, "69", "690000") + gal.checkWith(centimeter_per_square_second, "69", "69") + mercury_surface_gravity.checkWith(meter_per_square_second, "1", "3.7") + venus_surface_gravity.checkWith(meter_per_square_second, "1", "8.87") + earth_surface_gravity.checkWith(meter_per_square_second, "1", "9.80655") + mars_surface_gravity.checkWith(meter_per_square_second, "1", "3.71") + jupiter_surface_gravity.checkWith(meter_per_square_second, "1", "24.79") + saturn_surface_gravity.checkWith(meter_per_square_second, "1", "10.44") + uranus_surface_gravity.checkWith(meter_per_square_second, "1", "8.87") + neptune_surface_gravity.checkWith(meter_per_square_second, "1", "11.15") + sun_surface_gravity.checkWith(meter_per_square_second, "1", "274") } @Test - fun testAngle() { - MyUnitIDS.angle_second.checkWith(MyUnitIDS.angle_minute, "420.5", "7.00833") - MyUnitIDS.angle_minute.checkWith(MyUnitIDS.radian, "420.5", "0.12232") - MyUnitIDS.degree.checkWith(MyUnitIDS.turn, "420.5", "1.16806") - MyUnitIDS.radian.checkWith(MyUnitIDS.turn, "420.5", "66.92465") - MyUnitIDS.sextant.checkWith(MyUnitIDS.radian, "420.5", "440.34657") - MyUnitIDS.turn.checkWith(MyUnitIDS.angle_minute, "420.5", "9082800") + fun testAngle() = testWithUnits { + angle_second.checkWith(angle_minute, "420.5", "7.00833") + angle_minute.checkWith(radian, "420.5", "0.12232") + degree.checkWith(turn, "420.5", "1.16806") + radian.checkWith(turn, "420.5", "66.92465") + sextant.checkWith(radian, "420.5", "440.34657") + turn.checkWith(angle_minute, "420.5", "9082800") } @Test - fun testArea() { - MyUnitIDS.cent.checkWith(MyUnitIDS.acre, "75.9", "7590") - MyUnitIDS.acre.checkWith(MyUnitIDS.square_kilometer, "75.9", "0.30716") - MyUnitIDS.hectare.checkWith(MyUnitIDS.square_foot, "75.9", "8169808.00585") - MyUnitIDS.square_foot.checkWith(MyUnitIDS.square_decimeter, "75.9", "705.13407") - MyUnitIDS.square_mile.checkWith(MyUnitIDS.square_foot, "75.9", "2115970560.8762") - MyUnitIDS.square_yard.checkWith(MyUnitIDS.square_foot, "75.9", "683.1") - MyUnitIDS.square_inch.checkWith(MyUnitIDS.square_foot, "75.9", "0.52708") - MyUnitIDS.square_micrometer.checkWith(MyUnitIDS.square_millimeter, "75.9", "0.00008") - MyUnitIDS.square_millimeter.checkWith(MyUnitIDS.square_centimeter, "75.9", "0.759") - MyUnitIDS.square_centimeter.checkWith(MyUnitIDS.acre, "75.9", "0.000002") - MyUnitIDS.square_decimeter.checkWith(MyUnitIDS.square_meter, "75.9", "0.759") - MyUnitIDS.square_meter.checkWith(MyUnitIDS.acre, "75.9", "0.01876") - MyUnitIDS.square_kilometer.checkWith(MyUnitIDS.hectare, "75.9", "7590") - MyUnitIDS.electron_cross_section.checkWith(MyUnitIDS.square_micrometer, "75.9", "0.000000000000005") + fun testArea() = testWithUnits { + cent.checkWith(acre, "75.9", "7590") + acre.checkWith(square_kilometer, "75.9", "0.30716") + hectare.checkWith(square_foot, "75.9", "8169808.00585") + square_foot.checkWith(square_decimeter, "75.9", "705.13407") + square_mile.checkWith(square_foot, "75.9", "2115970560.8762") + square_yard.checkWith(square_foot, "75.9", "683.1") + square_inch.checkWith(square_foot, "75.9", "0.52708") + square_micrometer.checkWith(square_millimeter, "75.9", "0.00008") + square_millimeter.checkWith(square_centimeter, "75.9", "0.759") + square_centimeter.checkWith(acre, "75.9", "0.000002") + square_decimeter.checkWith(square_meter, "75.9", "0.759") + square_meter.checkWith(acre, "75.9", "0.01876") + square_kilometer.checkWith(hectare, "75.9", "7590") + electron_cross_section.checkWith(square_micrometer, "75.9", "0.000000000000005") } @Test - fun testDataTransfer() { - MyUnitIDS.bit_per_second.checkWith(MyUnitIDS.kilobit_per_second, "2048", "2.048") - MyUnitIDS.kibibit_per_second.checkWith(MyUnitIDS.bit_per_second, "2048", "2097152") - MyUnitIDS.kilobit_per_second.checkWith(MyUnitIDS.bit_per_second, "2048", "2048000") - MyUnitIDS.megabit_per_second.checkWith(MyUnitIDS.kilobit_per_second, "2048", "2048000") - MyUnitIDS.mebibit_per_second.checkWith(MyUnitIDS.kilobit_per_second, "2048", "2147483.648") - MyUnitIDS.gigabit_per_second.checkWith(MyUnitIDS.kilobit_per_second, "2048", "2048000000") - MyUnitIDS.terabit_per_second.checkWith(MyUnitIDS.gigabyte_per_second, "2048", "256000") - MyUnitIDS.petabit_per_second.checkWith(MyUnitIDS.gigabyte_per_second, "2048", "256000000") - MyUnitIDS.exabit_per_second.checkWith(MyUnitIDS.petabit_per_second, "2048", "2048000") - MyUnitIDS.byte_per_second.checkWith(MyUnitIDS.bit_per_second, "2048", "16384") - MyUnitIDS.kibibyte_per_second.checkWith(MyUnitIDS.bit_per_second, "2048", "16777216") - MyUnitIDS.kilobyte_per_second.checkWith(MyUnitIDS.kibibit_per_second, "2048", "16000") - MyUnitIDS.megabyte_per_second.checkWith(MyUnitIDS.kilobyte_per_second, "2048", "2048000") - MyUnitIDS.mebibyte_per_second.checkWith(MyUnitIDS.bit_per_second, "2048", "17179869184") - MyUnitIDS.gigabyte_per_second.checkWith(MyUnitIDS.kilobyte_per_second, "2048", "2048000000") - MyUnitIDS.terabyte_per_second.checkWith(MyUnitIDS.gigabyte_per_second, "2048", "2048000") - MyUnitIDS.petabyte_per_second.checkWith(MyUnitIDS.terabyte_per_second, "2048", "2048000") - MyUnitIDS.exabyte_per_second.checkWith(MyUnitIDS.petabyte_per_second, "2048", "2048000") + fun testDataTransfer() = testWithUnits { + bit_per_second.checkWith(kilobit_per_second, "2048", "2.048") + kibibit_per_second.checkWith(bit_per_second, "2048", "2097152") + kilobit_per_second.checkWith(bit_per_second, "2048", "2048000") + megabit_per_second.checkWith(kilobit_per_second, "2048", "2048000") + mebibit_per_second.checkWith(kilobit_per_second, "2048", "2147483.648") + gigabit_per_second.checkWith(kilobit_per_second, "2048", "2048000000") + terabit_per_second.checkWith(gigabyte_per_second, "2048", "256000") + petabit_per_second.checkWith(gigabyte_per_second, "2048", "256000000") + exabit_per_second.checkWith(petabit_per_second, "2048", "2048000") + byte_per_second.checkWith(bit_per_second, "2048", "16384") + kibibyte_per_second.checkWith(bit_per_second, "2048", "16777216") + kilobyte_per_second.checkWith(kibibit_per_second, "2048", "16000") + megabyte_per_second.checkWith(kilobyte_per_second, "2048", "2048000") + mebibyte_per_second.checkWith(bit_per_second, "2048", "17179869184") + gigabyte_per_second.checkWith(kilobyte_per_second, "2048", "2048000000") + terabyte_per_second.checkWith(gigabyte_per_second, "2048", "2048000") + petabyte_per_second.checkWith(terabyte_per_second, "2048", "2048000") + exabyte_per_second.checkWith(petabyte_per_second, "2048", "2048000") } @Test - fun testEnergy() { - MyUnitIDS.electron_volt.checkWith(MyUnitIDS.joule, "56000000000000000000", "8.97219") - MyUnitIDS.attojoule.checkWith(MyUnitIDS.calorie_th, "41840000000000", "0.00001") - MyUnitIDS.joule.checkWith(MyUnitIDS.kilocalorie_th, "4184", "1") - MyUnitIDS.kilojoule.checkWith(MyUnitIDS.calorie_th, "4184000000", "1000000000000") - MyUnitIDS.megajoule.checkWith(MyUnitIDS.calorie_th, "0.4184", "100000") - MyUnitIDS.gigajoule.checkWith(MyUnitIDS.calorie_th, "0.4184", "100000000") - MyUnitIDS.energy_ton.checkWith(MyUnitIDS.calorie_th, "0.4184", "418400000") - MyUnitIDS.kiloton.checkWith(MyUnitIDS.calorie_th, "0.4184", "418400000000") - MyUnitIDS.megaton.checkWith(MyUnitIDS.calorie_th, "0.4184", "418400000000000") - MyUnitIDS.gigaton.checkWith(MyUnitIDS.calorie_th, "0.000000004184", "4184000000") - MyUnitIDS.energy_horse_power_metric.checkWith(MyUnitIDS.joule, "10", "26477955") - MyUnitIDS.calorie_th.checkWith(MyUnitIDS.joule, "10", "41.84") - MyUnitIDS.kilocalorie_th.checkWith(MyUnitIDS.joule, "10", "41840") + fun testEnergy() = testWithUnits { + electron_volt.checkWith(joule, "56000000000000000000", "8.97219") + attojoule.checkWith(calorie_th, "41840000000000", "0.00001") + joule.checkWith(kilocalorie_th, "4184", "1") + kilojoule.checkWith(calorie_th, "4184000000", "1000000000000") + megajoule.checkWith(calorie_th, "0.4184", "100000") + gigajoule.checkWith(calorie_th, "0.4184", "100000000") + energy_ton.checkWith(calorie_th, "0.4184", "418400000") + kiloton.checkWith(calorie_th, "0.4184", "418400000000") + megaton.checkWith(calorie_th, "0.4184", "418400000000000") + gigaton.checkWith(calorie_th, "0.000000004184", "4184000000") + energy_horse_power_metric.checkWith(joule, "10", "26477955") + calorie_th.checkWith(joule, "10", "41.84") + kilocalorie_th.checkWith(joule, "10", "41840") } @Test - fun testFileSize() { - MyUnitIDS.bit.checkWith(MyUnitIDS.kilobit, "2048", "2.048") - MyUnitIDS.kibibit.checkWith(MyUnitIDS.bit, "2048", "2097152") - MyUnitIDS.kilobit.checkWith(MyUnitIDS.bit, "2048", "2048000") - MyUnitIDS.megabit.checkWith(MyUnitIDS.kilobit, "2048", "2048000") - MyUnitIDS.mebibit.checkWith(MyUnitIDS.kilobit, "2048", "2147483.648") - MyUnitIDS.gigabit.checkWith(MyUnitIDS.kilobit, "2048", "2048000000") - MyUnitIDS.terabit.checkWith(MyUnitIDS.gigabyte, "2048", "256000") - MyUnitIDS.petabit.checkWith(MyUnitIDS.gigabyte, "2048", "256000000") - MyUnitIDS.exabit.checkWith(MyUnitIDS.petabit, "2048", "2048000") - MyUnitIDS.byte.checkWith(MyUnitIDS.bit, "2048", "16384") - MyUnitIDS.kibibyte.checkWith(MyUnitIDS.bit, "2048", "16777216") - MyUnitIDS.kilobyte.checkWith(MyUnitIDS.kibibit, "2048", "16000") - MyUnitIDS.megabyte.checkWith(MyUnitIDS.kilobyte, "2048", "2048000") - MyUnitIDS.mebibyte.checkWith(MyUnitIDS.bit, "2048", "17179869184") - MyUnitIDS.gigabyte.checkWith(MyUnitIDS.kilobyte, "2048", "2048000000") - MyUnitIDS.terabyte.checkWith(MyUnitIDS.gigabyte, "2048", "2048000") - MyUnitIDS.petabyte.checkWith(MyUnitIDS.terabyte, "2048", "2048000") - MyUnitIDS.exabyte.checkWith(MyUnitIDS.petabyte, "2048", "2048000") + fun testFileSize() = testWithUnits { + bit.checkWith(kilobit, "2048", "2.048") + kibibit.checkWith(bit, "2048", "2097152") + kilobit.checkWith(bit, "2048", "2048000") + megabit.checkWith(kilobit, "2048", "2048000") + mebibit.checkWith(kilobit, "2048", "2147483.648") + gigabit.checkWith(kilobit, "2048", "2048000000") + terabit.checkWith(gigabyte, "2048", "256000") + petabit.checkWith(gigabyte, "2048", "256000000") + exabit.checkWith(petabit, "2048", "2048000") + byte.checkWith(bit, "2048", "16384") + kibibyte.checkWith(bit, "2048", "16777216") + kilobyte.checkWith(kibibit, "2048", "16000") + megabyte.checkWith(kilobyte, "2048", "2048000") + mebibyte.checkWith(bit, "2048", "17179869184") + gigabyte.checkWith(kilobyte, "2048", "2048000000") + terabyte.checkWith(gigabyte, "2048", "2048000") + petabyte.checkWith(terabyte, "2048", "2048000") + exabyte.checkWith(petabyte, "2048", "2048000") } @Test - fun testLength() { - MyUnitIDS.attometer.checkWith(MyUnitIDS.micrometer, "158000000000.7", "0.158") - MyUnitIDS.nanometer.checkWith(MyUnitIDS.inch, "158000000000.7", "6220.47244") - MyUnitIDS.micrometer.checkWith(MyUnitIDS.inch, "158000000000.7", "6220472.44097") - MyUnitIDS.millimeter.checkWith(MyUnitIDS.inch, "158000.7", "6220.5") - MyUnitIDS.centimeter.checkWith(MyUnitIDS.inch, "158000.7", "62205") - MyUnitIDS.decimeter.checkWith(MyUnitIDS.foot, "158000.7", "51837.5") - MyUnitIDS.meter.checkWith(MyUnitIDS.yard, "158000.7", "172791.66667") - MyUnitIDS.kilometer.checkWith(MyUnitIDS.mile, "100", "62.13712") - MyUnitIDS.nautical_mile.checkWith(MyUnitIDS.kilometer, "100", "185.2") - MyUnitIDS.inch.checkWith(MyUnitIDS.foot, "100", "8.33333") - MyUnitIDS.foot.checkWith(MyUnitIDS.inch, "100", "1200") - MyUnitIDS.yard.checkWith(MyUnitIDS.foot, "100", "300") - MyUnitIDS.mile.checkWith(MyUnitIDS.foot, "100", "528000") - MyUnitIDS.light_year.checkWith(MyUnitIDS.foot, "0.0000001", "3103914196.85037") - MyUnitIDS.parsec.checkWith(MyUnitIDS.foot, "0.00000001", "1012361411.25044") - MyUnitIDS.kiloparsec.checkWith(MyUnitIDS.foot, "0.00000000001", "1012361411.25044") - MyUnitIDS.megaparsec.checkWith(MyUnitIDS.foot, "0.00000000000001", "1012361411.25044") - MyUnitIDS.mercury_equatorial_radius.checkWith(MyUnitIDS.kilometer, "1", "2439.7") - MyUnitIDS.venus_equatorial_radius.checkWith(MyUnitIDS.kilometer, "1", "6051.8") - MyUnitIDS.earth_equatorial_radius.checkWith(MyUnitIDS.kilometer, "1", "6371") - MyUnitIDS.mars_equatorial_radius.checkWith(MyUnitIDS.kilometer, "1", "3389.5") - MyUnitIDS.jupiter_equatorial_radius.checkWith(MyUnitIDS.kilometer, "1", "69911") - MyUnitIDS.saturn_equatorial_radius.checkWith(MyUnitIDS.kilometer, "1", "58232") - MyUnitIDS.uranus_equatorial_radius.checkWith(MyUnitIDS.kilometer, "1", "25362") - MyUnitIDS.neptune_equatorial_radius.checkWith(MyUnitIDS.kilometer, "1", "24622") - MyUnitIDS.sun_equatorial_radius.checkWith(MyUnitIDS.kilometer, "1", "695508") + fun testLength() = testWithUnits { + attometer.checkWith(micrometer, "158000000000.7", "0.158") + nanometer.checkWith(inch, "158000000000.7", "6220.47244") + micrometer.checkWith(inch, "158000000000.7", "6220472.44097") + millimeter.checkWith(inch, "158000.7", "6220.5") + centimeter.checkWith(inch, "158000.7", "62205") + decimeter.checkWith(foot, "158000.7", "51837.5") + meter.checkWith(yard, "158000.7", "172791.66667") + kilometer.checkWith(mile, "100", "62.13712") + nautical_mile.checkWith(kilometer, "100", "185.2") + inch.checkWith(foot, "100", "8.33333") + foot.checkWith(inch, "100", "1200") + yard.checkWith(foot, "100", "300") + mile.checkWith(foot, "100", "528000") + light_year.checkWith(foot, "0.0000001", "3103914196.85037") + parsec.checkWith(foot, "0.00000001", "1012361411.25044") + kiloparsec.checkWith(foot, "0.00000000001", "1012361411.25044") + megaparsec.checkWith(foot, "0.00000000000001", "1012361411.25044") + mercury_equatorial_radius.checkWith(kilometer, "1", "2439.7") + venus_equatorial_radius.checkWith(kilometer, "1", "6051.8") + earth_equatorial_radius.checkWith(kilometer, "1", "6371") + mars_equatorial_radius.checkWith(kilometer, "1", "3389.5") + jupiter_equatorial_radius.checkWith(kilometer, "1", "69911") + saturn_equatorial_radius.checkWith(kilometer, "1", "58232") + uranus_equatorial_radius.checkWith(kilometer, "1", "25362") + neptune_equatorial_radius.checkWith(kilometer, "1", "24622") + sun_equatorial_radius.checkWith(kilometer, "1", "695508") } @Test - fun testMass() { - MyUnitIDS.electron_mass_rest.checkWith(MyUnitIDS.milligram, "1500000000000000000", "0.000001") - MyUnitIDS.atomic_mass_unit.checkWith(MyUnitIDS.electron_mass_rest, "150", "273433.27951") - MyUnitIDS.milligram.checkWith(MyUnitIDS.ounce, "1500", "0.05291") - MyUnitIDS.gram.checkWith(MyUnitIDS.ounce, "1500", "52.91094") - MyUnitIDS.kilogram.checkWith(MyUnitIDS.carat, "1500", "7500000") - MyUnitIDS.metric_ton.checkWith(MyUnitIDS.carat, "1500", "7500000000") - MyUnitIDS.imperial_ton.checkWith(MyUnitIDS.kilogram, "1500", "1524070.3632") - MyUnitIDS.ounce.checkWith(MyUnitIDS.pound, "1500", "93.75") - MyUnitIDS.carat.checkWith(MyUnitIDS.pound, "1500", "0.66139") - MyUnitIDS.pound.checkWith(MyUnitIDS.kilogram, "1500", "680.38856") - MyUnitIDS.mercury_mass.checkWith(MyUnitIDS.kilogram, "1", "330104000000000000000000") - MyUnitIDS.venus_mass.checkWith(MyUnitIDS.kilogram, "1", "4867320000000000000000000") - MyUnitIDS.earth_mass.checkWith(MyUnitIDS.kilogram, "1", "5972190000000000000000000") - MyUnitIDS.mars_mass.checkWith(MyUnitIDS.kilogram, "1", "641693000000000000000000") - MyUnitIDS.jupiter_mass.checkWith(MyUnitIDS.kilogram, "1", "1898130000000000000000000000") - MyUnitIDS.saturn_mass.checkWith(MyUnitIDS.kilogram, "1", "568319000000000000000000000") - MyUnitIDS.uranus_mass.checkWith(MyUnitIDS.kilogram, "1", "86810300000000000000000000") - MyUnitIDS.neptune_mass.checkWith(MyUnitIDS.kilogram, "1", "102410000000000000000000000") - MyUnitIDS.sun_mass.checkWith(MyUnitIDS.kilogram, "1", "1989100000000000000000000000000") + fun testMass() = testWithUnits { + electron_mass_rest.checkWith(milligram, "1500000000000000000", "0.000001") + atomic_mass_unit.checkWith(electron_mass_rest, "150", "273433.27951") + milligram.checkWith(ounce, "1500", "0.05291") + gram.checkWith(ounce, "1500", "52.91094") + kilogram.checkWith(carat, "1500", "7500000") + metric_ton.checkWith(carat, "1500", "7500000000") + imperial_ton.checkWith(kilogram, "1500", "1524070.3632") + ounce.checkWith(pound, "1500", "93.75") + carat.checkWith(pound, "1500", "0.66139") + pound.checkWith(kilogram, "1500", "680.38856") + mercury_mass.checkWith(kilogram, "1", "330104000000000000000000") + venus_mass.checkWith(kilogram, "1", "4867320000000000000000000") + earth_mass.checkWith(kilogram, "1", "5972190000000000000000000") + mars_mass.checkWith(kilogram, "1", "641693000000000000000000") + jupiter_mass.checkWith(kilogram, "1", "1898130000000000000000000000") + saturn_mass.checkWith(kilogram, "1", "568319000000000000000000000") + uranus_mass.checkWith(kilogram, "1", "86810300000000000000000000") + neptune_mass.checkWith(kilogram, "1", "102410000000000000000000000") + sun_mass.checkWith(kilogram, "1", "1989100000000000000000000000000") } @Test - fun testPower() { - MyUnitIDS.attowatt.checkWith(MyUnitIDS.watt, "3950000000000000", "0.00395") - MyUnitIDS.watt.checkWith(MyUnitIDS.kilowatt, "395", "0.395") - MyUnitIDS.kilowatt.checkWith(MyUnitIDS.horse_power_mechanical, "395", "529.70373") - MyUnitIDS.megawatt.checkWith(MyUnitIDS.horse_power_mechanical, "395", "529703.72539") - MyUnitIDS.horse_power_mechanical.checkWith(MyUnitIDS.kilowatt, "395", "294.55145") + fun testPower() = testWithUnits { + attowatt.checkWith(watt, "3950000000000000", "0.00395") + watt.checkWith(kilowatt, "395", "0.395") + kilowatt.checkWith(horse_power_mechanical, "395", "529.70373") + megawatt.checkWith(horse_power_mechanical, "395", "529703.72539") + horse_power_mechanical.checkWith(kilowatt, "395", "294.55145") } @Test - fun testPressure() { - MyUnitIDS.attopascal.checkWith(MyUnitIDS.femtopascal, "456", "0.456") - MyUnitIDS.femtopascal.checkWith(MyUnitIDS.picopascal, "456", "0.456") - MyUnitIDS.picopascal.checkWith(MyUnitIDS.nanopascal, "456", "0.456") - MyUnitIDS.nanopascal.checkWith(MyUnitIDS.micropascal, "456", "0.456") - MyUnitIDS.micropascal.checkWith(MyUnitIDS.millipascal, "456", "0.456") - MyUnitIDS.millipascal.checkWith(MyUnitIDS.centipascal, "456", "45.6") - MyUnitIDS.centipascal.checkWith(MyUnitIDS.decipascal, "456", "45.6") - MyUnitIDS.decipascal.checkWith(MyUnitIDS.dekapascal, "456", "4.56") - MyUnitIDS.pascal.checkWith(MyUnitIDS.bar, "456", "0.00456") - MyUnitIDS.dekapascal.checkWith(MyUnitIDS.bar, "456", "0.0456") - MyUnitIDS.hectopascal.checkWith(MyUnitIDS.psi, "456", "6.61372") - MyUnitIDS.millibar.checkWith(MyUnitIDS.psi, "456", "6.61372") - MyUnitIDS.bar.checkWith(MyUnitIDS.ksi, "456", "6.61372") - MyUnitIDS.kilopascal.checkWith(MyUnitIDS.psi, "456", "66.13721") - MyUnitIDS.megapascal.checkWith(MyUnitIDS.ksi, "456", "66.13721") - MyUnitIDS.gigapascal.checkWith(MyUnitIDS.torr, "456", "3420281273.13024") - MyUnitIDS.terapascal.checkWith(MyUnitIDS.gigapascal, "456", "456000") - MyUnitIDS.petapascal.checkWith(MyUnitIDS.gigapascal, "456", "456000000") - MyUnitIDS.exapascal.checkWith(MyUnitIDS.gigapascal, "456", "456000000000") - MyUnitIDS.psi.checkWith(MyUnitIDS.gigapascal, "456", "0.00314") - MyUnitIDS.ksi.checkWith(MyUnitIDS.gigapascal, "456", "3.14401") - MyUnitIDS.standard_atmosphere.checkWith(MyUnitIDS.torr, "456", "346560") - MyUnitIDS.torr.checkWith(MyUnitIDS.hectopascal, "456", "607.95") - MyUnitIDS.micron_of_mercury.checkWith(MyUnitIDS.hectopascal, "456", "0.60795") - MyUnitIDS.millimeter_of_mercury.checkWith(MyUnitIDS.hectopascal, "456", "607.95") + fun testPressure() = testWithUnits { + attopascal.checkWith(femtopascal, "456", "0.456") + femtopascal.checkWith(picopascal, "456", "0.456") + picopascal.checkWith(nanopascal, "456", "0.456") + nanopascal.checkWith(micropascal, "456", "0.456") + micropascal.checkWith(millipascal, "456", "0.456") + millipascal.checkWith(centipascal, "456", "45.6") + centipascal.checkWith(decipascal, "456", "45.6") + decipascal.checkWith(dekapascal, "456", "4.56") + pascal.checkWith(bar, "456", "0.00456") + dekapascal.checkWith(bar, "456", "0.0456") + hectopascal.checkWith(psi, "456", "6.61372") + millibar.checkWith(psi, "456", "6.61372") + bar.checkWith(ksi, "456", "6.61372") + kilopascal.checkWith(psi, "456", "66.13721") + megapascal.checkWith(ksi, "456", "66.13721") + gigapascal.checkWith(torr, "456", "3420281273.13024") + terapascal.checkWith(gigapascal, "456", "456000") + petapascal.checkWith(gigapascal, "456", "456000000") + exapascal.checkWith(gigapascal, "456", "456000000000") + psi.checkWith(gigapascal, "456", "0.00314") + ksi.checkWith(gigapascal, "456", "3.14401") + standard_atmosphere.checkWith(torr, "456", "346560") + torr.checkWith(hectopascal, "456", "607.95") + micron_of_mercury.checkWith(hectopascal, "456", "0.60795") + millimeter_of_mercury.checkWith(hectopascal, "456", "607.95") } @Test - fun testSpeed() { - MyUnitIDS.millimeter_per_hour.checkWith(MyUnitIDS.kilometer_per_hour, "396", "0.0004") - MyUnitIDS.millimeter_per_minute.checkWith(MyUnitIDS.kilometer_per_hour, "396", "0.02376") - MyUnitIDS.millimeter_per_second.checkWith(MyUnitIDS.kilometer_per_hour, "396", "1.4256") - MyUnitIDS.centimeter_per_hour.checkWith(MyUnitIDS.kilometer_per_hour, "396", "0.00396") - MyUnitIDS.centimeter_per_minute.checkWith(MyUnitIDS.kilometer_per_hour, "396", "0.2376") - MyUnitIDS.centimeter_per_second.checkWith(MyUnitIDS.kilometer_per_hour, "396", "14.256") - MyUnitIDS.meter_per_hour.checkWith(MyUnitIDS.kilometer_per_hour, "396", "0.396") - MyUnitIDS.meter_per_minute.checkWith(MyUnitIDS.kilometer_per_hour, "396", "23.76") - MyUnitIDS.meter_per_second.checkWith(MyUnitIDS.kilometer_per_hour, "396", "1425.6") - MyUnitIDS.kilometer_per_hour.checkWith(MyUnitIDS.mile_per_hour, "396", "246.06299") - MyUnitIDS.kilometer_per_minute.checkWith(MyUnitIDS.mile_per_hour, "396", "14763.77953") - MyUnitIDS.kilometer_per_second.checkWith(MyUnitIDS.mile_per_hour, "396", "885826.77165") - MyUnitIDS.foot_per_hour.checkWith(MyUnitIDS.mile_per_hour, "396", "0.075") - MyUnitIDS.foot_per_minute.checkWith(MyUnitIDS.mile_per_hour, "396", "4.5") - MyUnitIDS.foot_per_second.checkWith(MyUnitIDS.mile_per_hour, "396", "270") - MyUnitIDS.yard_per_hour.checkWith(MyUnitIDS.mile_per_hour, "396", "0.225") - MyUnitIDS.yard_per_minute.checkWith(MyUnitIDS.mile_per_hour, "396", "13.5") - MyUnitIDS.yard_per_second.checkWith(MyUnitIDS.mile_per_hour, "396", "810") - MyUnitIDS.mile_per_hour.checkWith(MyUnitIDS.foot_per_hour, "396", "2090880") - MyUnitIDS.mile_per_minute.checkWith(MyUnitIDS.foot_per_hour, "396", "125452800") - MyUnitIDS.mile_per_second.checkWith(MyUnitIDS.foot_per_hour, "396", "7527168000") - MyUnitIDS.knot.checkWith(MyUnitIDS.meter_per_hour, "396", "733392") - MyUnitIDS.velocity_of_light_in_vacuum.checkWith(MyUnitIDS.meter_per_second, "1", "299792458") - MyUnitIDS.cosmic_velocity_first.checkWith(MyUnitIDS.meter_per_second, "1", "7900") - MyUnitIDS.cosmic_velocity_second.checkWith(MyUnitIDS.meter_per_second, "1", "11200") - MyUnitIDS.cosmic_velocity_third.checkWith(MyUnitIDS.meter_per_second, "1", "16670") - MyUnitIDS.earths_orbital_speed.checkWith(MyUnitIDS.meter_per_second, "1", "29765") - MyUnitIDS.mach.checkWith(MyUnitIDS.meter_per_second, "1", "343.6") - MyUnitIDS.mach_si_standard.checkWith(MyUnitIDS.meter_per_second, "1", "295.0464") + fun testSpeed() = testWithUnits { + millimeter_per_hour.checkWith(kilometer_per_hour, "396", "0.0004") + millimeter_per_minute.checkWith(kilometer_per_hour, "396", "0.02376") + millimeter_per_second.checkWith(kilometer_per_hour, "396", "1.4256") + centimeter_per_hour.checkWith(kilometer_per_hour, "396", "0.00396") + centimeter_per_minute.checkWith(kilometer_per_hour, "396", "0.2376") + centimeter_per_second.checkWith(kilometer_per_hour, "396", "14.256") + meter_per_hour.checkWith(kilometer_per_hour, "396", "0.396") + meter_per_minute.checkWith(kilometer_per_hour, "396", "23.76") + meter_per_second.checkWith(kilometer_per_hour, "396", "1425.6") + kilometer_per_hour.checkWith(mile_per_hour, "396", "246.06299") + kilometer_per_minute.checkWith(mile_per_hour, "396", "14763.77953") + kilometer_per_second.checkWith(mile_per_hour, "396", "885826.77165") + foot_per_hour.checkWith(mile_per_hour, "396", "0.075") + foot_per_minute.checkWith(mile_per_hour, "396", "4.5") + foot_per_second.checkWith(mile_per_hour, "396", "270") + yard_per_hour.checkWith(mile_per_hour, "396", "0.225") + yard_per_minute.checkWith(mile_per_hour, "396", "13.5") + yard_per_second.checkWith(mile_per_hour, "396", "810") + mile_per_hour.checkWith(foot_per_hour, "396", "2090880") + mile_per_minute.checkWith(foot_per_hour, "396", "125452800") + mile_per_second.checkWith(foot_per_hour, "396", "7527168000") + knot.checkWith(meter_per_hour, "396", "733392") + velocity_of_light_in_vacuum.checkWith(meter_per_second, "1", "299792458") + cosmic_velocity_first.checkWith(meter_per_second, "1", "7900") + cosmic_velocity_second.checkWith(meter_per_second, "1", "11200") + cosmic_velocity_third.checkWith(meter_per_second, "1", "16670") + earths_orbital_speed.checkWith(meter_per_second, "1", "29765") + mach.checkWith(meter_per_second, "1", "343.6") + mach_si_standard.checkWith(meter_per_second, "1", "295.0464") } @Test - fun testTemperature() { - MyUnitIDS.celsius.checkWith(MyUnitIDS.celsius, "0", "0") - MyUnitIDS.celsius.checkWith(MyUnitIDS.fahrenheit, "0", "32") - MyUnitIDS.celsius.checkWith(MyUnitIDS.kelvin, "0", "273.15") - MyUnitIDS.celsius.checkWith(MyUnitIDS.celsius, "36.6", "36.6") - MyUnitIDS.celsius.checkWith(MyUnitIDS.fahrenheit, "36.6", "97.88") - MyUnitIDS.celsius.checkWith(MyUnitIDS.kelvin, "36.6", "309.75") - MyUnitIDS.celsius.checkWith(MyUnitIDS.celsius, "-36.6", "-36.6") - MyUnitIDS.celsius.checkWith(MyUnitIDS.fahrenheit, "-36.6", "-33.88") - MyUnitIDS.celsius.checkWith(MyUnitIDS.kelvin, "-36.6", "236.55") + fun testTemperature() = testWithUnits { + celsius.checkWith(celsius, "0", "0") + celsius.checkWith(fahrenheit, "0", "32") + celsius.checkWith(kelvin, "0", "273.15") + celsius.checkWith(celsius, "36.6", "36.6") + celsius.checkWith(fahrenheit, "36.6", "97.88") + celsius.checkWith(kelvin, "36.6", "309.75") + celsius.checkWith(celsius, "-36.6", "-36.6") + celsius.checkWith(fahrenheit, "-36.6", "-33.88") + celsius.checkWith(kelvin, "-36.6", "236.55") - MyUnitIDS.fahrenheit.checkWith(MyUnitIDS.celsius, "0", "-17.77778") - MyUnitIDS.fahrenheit.checkWith(MyUnitIDS.fahrenheit, "0", "0") - MyUnitIDS.fahrenheit.checkWith(MyUnitIDS.kelvin, "0", "255.37222") - MyUnitIDS.fahrenheit.checkWith(MyUnitIDS.celsius, "36.6", "2.55556") - MyUnitIDS.fahrenheit.checkWith(MyUnitIDS.fahrenheit, "36.6", "36.6") - MyUnitIDS.fahrenheit.checkWith(MyUnitIDS.kelvin, "36.6", "275.70556") - MyUnitIDS.fahrenheit.checkWith(MyUnitIDS.celsius, "-36.6", "-38.11111") - MyUnitIDS.fahrenheit.checkWith(MyUnitIDS.fahrenheit, "-36.6", "-36.6") - MyUnitIDS.fahrenheit.checkWith(MyUnitIDS.kelvin, "-36.6", "235.03889") + fahrenheit.checkWith(celsius, "0", "-17.77778") + fahrenheit.checkWith(fahrenheit, "0", "0") + fahrenheit.checkWith(kelvin, "0", "255.37222") + fahrenheit.checkWith(celsius, "36.6", "2.55556") + fahrenheit.checkWith(fahrenheit, "36.6", "36.6") + fahrenheit.checkWith(kelvin, "36.6", "275.70556") + fahrenheit.checkWith(celsius, "-36.6", "-38.11111") + fahrenheit.checkWith(fahrenheit, "-36.6", "-36.6") + fahrenheit.checkWith(kelvin, "-36.6", "235.03889") - MyUnitIDS.kelvin.checkWith(MyUnitIDS.celsius, "0", "-273.15") - MyUnitIDS.kelvin.checkWith(MyUnitIDS.fahrenheit, "0", "-459.67") - MyUnitIDS.kelvin.checkWith(MyUnitIDS.kelvin, "0", "0") - MyUnitIDS.kelvin.checkWith(MyUnitIDS.celsius, "36.6", "-236.55") - MyUnitIDS.kelvin.checkWith(MyUnitIDS.fahrenheit, "36.6", "-393.79") - MyUnitIDS.kelvin.checkWith(MyUnitIDS.kelvin, "36.6", "36.6") - MyUnitIDS.kelvin.checkWith(MyUnitIDS.celsius, "-36.6", "-309.75") - MyUnitIDS.kelvin.checkWith(MyUnitIDS.fahrenheit, "-36.6", "-525.55") - MyUnitIDS.kelvin.checkWith(MyUnitIDS.kelvin, "-36.6", "-36.6") + kelvin.checkWith(celsius, "0", "-273.15") + kelvin.checkWith(fahrenheit, "0", "-459.67") + kelvin.checkWith(kelvin, "0", "0") + kelvin.checkWith(celsius, "36.6", "-236.55") + kelvin.checkWith(fahrenheit, "36.6", "-393.79") + kelvin.checkWith(kelvin, "36.6", "36.6") + kelvin.checkWith(celsius, "-36.6", "-309.75") + kelvin.checkWith(fahrenheit, "-36.6", "-525.55") + kelvin.checkWith(kelvin, "-36.6", "-36.6") } @Test - fun testTime() { - MyUnitIDS.attosecond.checkWith(MyUnitIDS.millisecond, "366000000000", "0.00037") - MyUnitIDS.nanosecond.checkWith(MyUnitIDS.millisecond, "366", "0.00037") - MyUnitIDS.microsecond.checkWith(MyUnitIDS.millisecond, "366", "0.366") - MyUnitIDS.millisecond.checkWith(MyUnitIDS.second, "366", "0.366") - MyUnitIDS.jiffy.checkWith(MyUnitIDS.second, "366", "3.66") - MyUnitIDS.second.checkWith(MyUnitIDS.millisecond, "366", "366000") - MyUnitIDS.minute.checkWith(MyUnitIDS.millisecond, "366", "21960000") - MyUnitIDS.hour.checkWith(MyUnitIDS.millisecond, "366", "1317600000") - MyUnitIDS.day.checkWith(MyUnitIDS.hour, "366", "8784") - MyUnitIDS.week.checkWith(MyUnitIDS.hour, "366", "61488") + fun testTime() = testWithUnits { + attosecond.checkWith(millisecond, "366000000000", "0.00037") + nanosecond.checkWith(millisecond, "366", "0.00037") + microsecond.checkWith(millisecond, "366", "0.366") + millisecond.checkWith(second, "366", "0.366") + jiffy.checkWith(second, "366", "3.66") + second.checkWith(millisecond, "366", "366000") + minute.checkWith(millisecond, "366", "21960000") + hour.checkWith(millisecond, "366", "1317600000") + day.checkWith(hour, "366", "8784") + week.checkWith(hour, "366", "61488") } @Test - fun testVolume() { - MyUnitIDS.attoliter.checkWith(MyUnitIDS.millimeter, "1507000000000", "0.00151") - MyUnitIDS.milliliter.checkWith(MyUnitIDS.liter, "1507", "1.507") - MyUnitIDS.liter.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "398.10728") - MyUnitIDS.us_liquid_gallon.checkWith(MyUnitIDS.us_fluid_ounce, "1507", "192896") - MyUnitIDS.us_liquid_quart.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "376.75") - MyUnitIDS.us_liquid_pint.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "188.375") - MyUnitIDS.us_legal_cup.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "94.1875") - MyUnitIDS.us_fluid_ounce.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "11.77344") - MyUnitIDS.us_tablespoon.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "5.88672") - MyUnitIDS.us_teaspoon.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "1.96224") - MyUnitIDS.imperial_gallon.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "1809.83154") - MyUnitIDS.imperial_quart.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "452.45788") - MyUnitIDS.imperial_pint.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "226.22894") - MyUnitIDS.imperial_cup.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "113.11447") - MyUnitIDS.imperial_fluid_ounce.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "11.31145") - MyUnitIDS.imperial_tablespoon.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "7.06965") - MyUnitIDS.imperial_teaspoon.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "2.35655") - MyUnitIDS.cubic_millimeter.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "0.0004") - MyUnitIDS.cubic_centimeter.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "0.39811") - MyUnitIDS.cubic_meter.checkWith(MyUnitIDS.us_liquid_gallon, "1507", "398107.2829") - MyUnitIDS.cubic_kilometer.checkWith(MyUnitIDS.us_liquid_gallon, "0.0000001507", "39810.72829") + fun testVolume() = testWithUnits { + attoliter.checkWith(millimeter, "1507000000000", "0.00151") + milliliter.checkWith(liter, "1507", "1.507") + liter.checkWith(us_liquid_gallon, "1507", "398.10728") + us_liquid_gallon.checkWith(us_fluid_ounce, "1507", "192896") + us_liquid_quart.checkWith(us_liquid_gallon, "1507", "376.75") + us_liquid_pint.checkWith(us_liquid_gallon, "1507", "188.375") + us_legal_cup.checkWith(us_liquid_gallon, "1507", "94.1875") + us_fluid_ounce.checkWith(us_liquid_gallon, "1507", "11.77344") + us_tablespoon.checkWith(us_liquid_gallon, "1507", "5.88672") + us_teaspoon.checkWith(us_liquid_gallon, "1507", "1.96224") + imperial_gallon.checkWith(us_liquid_gallon, "1507", "1809.83154") + imperial_quart.checkWith(us_liquid_gallon, "1507", "452.45788") + imperial_pint.checkWith(us_liquid_gallon, "1507", "226.22894") + imperial_cup.checkWith(us_liquid_gallon, "1507", "113.11447") + imperial_fluid_ounce.checkWith(us_liquid_gallon, "1507", "11.31145") + imperial_tablespoon.checkWith(us_liquid_gallon, "1507", "7.06965") + imperial_teaspoon.checkWith(us_liquid_gallon, "1507", "2.35655") + cubic_millimeter.checkWith(us_liquid_gallon, "1507", "0.0004") + cubic_centimeter.checkWith(us_liquid_gallon, "1507", "0.39811") + cubic_meter.checkWith(us_liquid_gallon, "1507", "398107.2829") + cubic_kilometer.checkWith(us_liquid_gallon, "0.0000001507", "39810.72829") } @Test - fun testFlux() { - MyUnitIDS.maxwell.checkWith(MyUnitIDS.milliweber, "68.2", "0.00068") - MyUnitIDS.weber.checkWith(MyUnitIDS.milliweber, "68.2", "68200") - MyUnitIDS.milliweber.checkWith(MyUnitIDS.weber, "68.2", "0.0682") - MyUnitIDS.microweber.checkWith(MyUnitIDS.milliweber, "68.2", "0.0682") - MyUnitIDS.kiloweber.checkWith(MyUnitIDS.weber, "68.2", "68200") - MyUnitIDS.megaweber.checkWith(MyUnitIDS.weber, "68.2", "68200000") - MyUnitIDS.gigaweber.checkWith(MyUnitIDS.weber, "68.2", "68200000000") + fun testFlux() = testWithUnits { + maxwell.checkWith(milliweber, "68.2", "0.00068") + weber.checkWith(milliweber, "68.2", "68200") + milliweber.checkWith(weber, "68.2", "0.0682") + microweber.checkWith(milliweber, "68.2", "0.0682") + kiloweber.checkWith(weber, "68.2", "68200") + megaweber.checkWith(weber, "68.2", "68200000") + gigaweber.checkWith(weber, "68.2", "68200000000") } @Test - fun testNumberBase() { - MyUnitIDS.binary.checkWith(MyUnitIDS.octal, "1000001001", "1011") - MyUnitIDS.ternary.checkWith(MyUnitIDS.decimal, "10112020111", "69430") - MyUnitIDS.quaternary.checkWith(MyUnitIDS.quinary, "20321", "4234") - MyUnitIDS.quinary.checkWith(MyUnitIDS.nonary, "4234", "702") - MyUnitIDS.senary.checkWith(MyUnitIDS.nonary, "4234", "1274") - MyUnitIDS.septenary.checkWith(MyUnitIDS.nonary, "4234", "2041") - MyUnitIDS.octal.checkWith(MyUnitIDS.undecimal, "42343277", "5107945") - MyUnitIDS.nonary.checkWith(MyUnitIDS.duodecimal, "42343287", "69b9a81") - MyUnitIDS.decimal.checkWith(MyUnitIDS.duodecimal, "42343287", "12220273") - MyUnitIDS.undecimal.checkWith(MyUnitIDS.hexadecimal, "4234a287", "4e3f0c2") - MyUnitIDS.duodecimal.checkWith(MyUnitIDS.hexadecimal, "4234a287", "8f30d07") - MyUnitIDS.tridecimal.checkWith(MyUnitIDS.hexadecimal, "4234a287", "f9c3ff4") - MyUnitIDS.tetradecimal.checkWith(MyUnitIDS.hexadecimal, "bb", "a5") - MyUnitIDS.pentadecimal.checkWith(MyUnitIDS.hexadecimal, "BABE", "9a82") - MyUnitIDS.hexadecimal.checkWith(MyUnitIDS.quinary, "FADE", "4023342") + fun testNumberBase() = testWithUnits { + binary.checkWith(octal, "1000001001", "1011") + ternary.checkWith(decimal, "10112020111", "69430") + quaternary.checkWith(quinary, "20321", "4234") + quinary.checkWith(nonary, "4234", "702") + senary.checkWith(nonary, "4234", "1274") + septenary.checkWith(nonary, "4234", "2041") + octal.checkWith(undecimal, "42343277", "5107945") + nonary.checkWith(duodecimal, "42343287", "69b9a81") + decimal.checkWith(duodecimal, "42343287", "12220273") + undecimal.checkWith(hexadecimal, "4234a287", "4e3f0c2") + duodecimal.checkWith(hexadecimal, "4234a287", "8f30d07") + tridecimal.checkWith(hexadecimal, "4234a287", "f9c3ff4") + tetradecimal.checkWith(hexadecimal, "bb", "a5") + pentadecimal.checkWith(hexadecimal, "BABE", "9a82") + hexadecimal.checkWith(quinary, "FADE", "4023342") + } + + @Test + fun testElectrostaticCapacitance() = testWithUnits { + attofarad.checkWith(nanofarad, "364354322342", "364.35432") + statfarad.checkWith(microfarad, "123312", "0.1372") + farad.checkWith(kilofarad, "123312", "123.312") + exafarad.checkWith(petafarad, "123312", "123312000") + picofarad.checkWith(nanofarad, "11233", "11.233") + nanofarad.checkWith(millifarad, "11233", "0.01123") + microfarad.checkWith(nanofarad, "1123433", "1123433000") + millifarad.checkWith(nanofarad, "112", "112000000") + kilofarad.checkWith(microfarad, "11132", "11132000000000") + megafarad.checkWith(kilofarad, "11132", "11132000") + gigafarad.checkWith(petafarad, "11132", "0.01113") + petafarad.checkWith(kilofarad, "11132", "11132000000000000") + } + + @Test + fun testPrefix() = testWithUnits { + prefix_quetta.checkWith(prefix_base, "1", "1000000000000000000000000000000") + prefix_ronna.checkWith(prefix_base, "1", "1000000000000000000000000000") + prefix_yotta.checkWith(prefix_base, "1", "1000000000000000000000000") + prefix_zetta.checkWith(prefix_base, "1", "1000000000000000000000") + prefix_exa.checkWith(prefix_base, "1", "1000000000000000000") + prefix_peta.checkWith(prefix_base, "1", "1000000000000000") + prefix_tera.checkWith(prefix_base, "1", "1000000000000") + prefix_giga.checkWith(prefix_base, "1", "1000000000") + prefix_mega.checkWith(prefix_base, "1", "1000000") + prefix_kilo.checkWith(prefix_base, "1", "1000") + prefix_hecto.checkWith(prefix_base, "1", "100") + prefix_deca.checkWith(prefix_base, "1", "10") + prefix_base.checkWith(prefix_base, "77777", "77777") + prefix_deci.checkWith(prefix_base, "1", "0.1") + prefix_centi.checkWith(prefix_base, "1", "0.01") + prefix_milli.checkWith(prefix_base, "1", "0.001") + prefix_micro.checkWith(prefix_base, "1", "0.000001") + prefix_nano.checkWith(prefix_base, "1", "0.000000001") + prefix_pico.checkWith(prefix_base, "1", "0.000000000001") + prefix_femto.checkWith(prefix_base, "1", "0.000000000000001") + prefix_atto.checkWith(prefix_base, "1", "0.000000000000000001") + prefix_zepto.checkWith(prefix_base, "1", "0.000000000000000000001") + prefix_yocto.checkWith(prefix_base, "1", "0.000000000000000000000001") + prefix_ronto.checkWith(prefix_base, "1", "0.000000000000000000000000001") + prefix_quecto.checkWith(prefix_base, "1", "0.000000000000000000000000000001") + } + + @Test + fun testForce() = testWithUnits { + newton.checkWith(pond, "6553", "668220.03436") + kilonewton.checkWith(kilopound_force, "6553", "1473.173") + gram_force.checkWith(kilonewton, "6553", "0.06426") + kilogram_force.checkWith(ton_force, "6553", "6.553") + ton_force.checkWith(millinewton, "6553", "64262977450") + millinewton.checkWith(kilonewton, "6553", "0.00655") + attonewton.checkWith(dyne, "6553123123", "0.00066") + dyne.checkWith(joule_per_meter, "6553", "0.06553") + joule_per_meter.checkWith(pond, "6553", "668220.03436") + joule_per_centimeter.checkWith(kilopond, "6553", "6.6822") + kilopound_force.checkWith(kilopond, "6553", "2972390.80061") + pound_force.checkWith(ounce_force, "6553", "104848") + ounce_force.checkWith(pound_force, "6553", "409.5625") + pond.checkWith(kilonewton, "6553", "0.06426") + kilopond.checkWith(kilonewton, "6553", "64.26298") + } + + @Test + fun testTorque() = testWithUnits { + newton_meter.checkWith(dyne_meter, "2134", "213400000") + newton_centimeter.checkWith(kilogram_force_millimeter, "2345", "2391.23452") + newton_millimeter.checkWith(pound_force_inch, "2345", "20.755") + kilonewton_meter.checkWith(kilogram_force_meter, "2134", "217607.43985") + dyne_meter.checkWith(newton_centimeter, "2134", "2.134") + dyne_centimeter.checkWith(gram_force_centimeter, "2134", "2.17607") + dyne_millimeter.checkWith(gram_force_millimeter, "2134", "2.17607") + kilogram_force_meter.checkWith(dyne_millimeter, "2134", "2092739110000") + kilogram_force_centimeter.checkWith(gram_force_meter, "2134", "21340") + kilogram_force_millimeter.checkWith(ounce_force_inch, "2134", "2963.56822") + gram_force_meter.checkWith(newton_millimeter, "2134", "20927.3911") + gram_force_centimeter.checkWith(kilogram_force_centimeter, "2134", "2.134") + gram_force_millimeter.checkWith(kilonewton_meter, "2134", "0.00002") + ounce_force_foot.checkWith(kilogram_force_millimeter, "2134", "18439.75503") + ounce_force_inch.checkWith(dyne_meter, "2134", "1506935.1968") + pound_force_foot.checkWith(newton_millimeter, "2134", "2893315.612") + pound_force_inch.checkWith(ounce_force_foot, "2134", "2845.33337") } private fun String.checkWith(checkingId: String, value: String, expected: String) { @@ -399,4 +484,6 @@ class AllUnitsTest { // GROUP : testedCount / totalCount println("${unitGroup.name} : ${history[unitGroup]?.size} / ${allUnitsRepository.getCollectionByGroup(unitGroup).size}") } + + private fun testWithUnits(block: MyUnitIDS.() -> Unit): Unit = with(MyUnitIDS, block = block) } diff --git a/data/userprefs/src/main/java/com/sadellie/unitto/data/userprefs/UserPreferences.kt b/data/userprefs/src/main/java/com/sadellie/unitto/data/userprefs/UserPreferences.kt index d8453d02..21ad7def 100644 --- a/data/userprefs/src/main/java/com/sadellie/unitto/data/userprefs/UserPreferences.kt +++ b/data/userprefs/src/main/java/com/sadellie/unitto/data/userprefs/UserPreferences.kt @@ -54,6 +54,7 @@ import javax.inject.Inject * @property shownUnitGroups [UnitGroup]s that user wants to see. Excludes other [UnitGroup]s, * @property enableVibrations When true will use haptic feedback in app. * @property enableToolsExperiment When true will enable experimental Tools screen. + * @property radianMode AngleMode in mxParser. When true - Radian, when False - Degree. */ data class UserPreferences( val themingMode: ThemingMode? = null, @@ -67,7 +68,8 @@ data class UserPreferences( val shownUnitGroups: List = ALL_UNIT_GROUPS, val enableVibrations: Boolean = true, val enableToolsExperiment: Boolean = false, - val startingScreen: String = TopLevelDestinations.Converter.route + val startingScreen: String = TopLevelDestinations.Converter.route, + val radianMode: Boolean = true ) /** @@ -90,6 +92,7 @@ class UserPreferencesRepository @Inject constructor(private val dataStore: DataS val ENABLE_VIBRATIONS = booleanPreferencesKey("ENABLE_VIBRATIONS_PREF_KEY") val ENABLE_TOOLS_EXPERIMENT = booleanPreferencesKey("ENABLE_TOOLS_EXPERIMENT_PREF_KEY") val STARTING_SCREEN = stringPreferencesKey("STARTING_SCREEN_PREF_KEY") + val RADIAN_MODE = booleanPreferencesKey("RADIAN_MODE_PREF_KEY") } val userPreferencesFlow: Flow = dataStore.data @@ -134,6 +137,7 @@ class UserPreferencesRepository @Inject constructor(private val dataStore: DataS val enableVibrations: Boolean = preferences[PrefsKeys.ENABLE_VIBRATIONS] ?: true val enableToolsExperiment: Boolean = preferences[PrefsKeys.ENABLE_TOOLS_EXPERIMENT] ?: false val startingScreen: String = preferences[PrefsKeys.STARTING_SCREEN] ?: TopLevelDestinations.Converter.route + val radianMode: Boolean = preferences[PrefsKeys.RADIAN_MODE] ?: true UserPreferences( themingMode = themingMode, @@ -147,7 +151,8 @@ class UserPreferencesRepository @Inject constructor(private val dataStore: DataS shownUnitGroups = shownUnitGroups, enableVibrations = enableVibrations, enableToolsExperiment = enableToolsExperiment, - startingScreen = startingScreen + startingScreen = startingScreen, + radianMode = radianMode ) } @@ -269,4 +274,15 @@ class UserPreferencesRepository @Inject constructor(private val dataStore: DataS preferences[PrefsKeys.ENABLE_TOOLS_EXPERIMENT] = enabled } } + + /** + * Update angle mode for calculator. + * + * @param radianMode When true - Radian, when False - Degree. + */ + suspend fun updateRadianMode(radianMode: Boolean) { + dataStore.edit { preferences -> + preferences[PrefsKeys.RADIAN_MODE] = radianMode + } + } } diff --git a/fastlane/metadata/android/en-US/changelogs/18.txt b/fastlane/metadata/android/en-US/changelogs/18.txt new file mode 100644 index 00000000..cb278c5f --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/18.txt @@ -0,0 +1 @@ +Fixed crashes in calculator. \ No newline at end of file diff --git a/fastlane/metadata/android/ru/changelogs/18.txt b/fastlane/metadata/android/ru/changelogs/18.txt new file mode 100644 index 00000000..1630c196 --- /dev/null +++ b/fastlane/metadata/android/ru/changelogs/18.txt @@ -0,0 +1 @@ +Исправлены ошибки в калькуляторе. \ No newline at end of file diff --git a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/AngleMode.kt b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/AngleMode.kt deleted file mode 100644 index 67318a58..00000000 --- a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/AngleMode.kt +++ /dev/null @@ -1,21 +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 . - */ - -package com.sadellie.unitto.feature.calculator - -internal enum class AngleMode { DEG, RAD } diff --git a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorScreen.kt b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorScreen.kt index afd4c138..65782103 100644 --- a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorScreen.kt +++ b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorScreen.kt @@ -270,7 +270,7 @@ private fun CalculatorScreen( numPad = { CalculatorKeyboard( modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp, vertical = 4.dp), - angleMode = uiState.angleMode, + radianMode = uiState.radianMode, allowVibration = uiState.allowVibration, addSymbol = addSymbol, clearSymbols = clearSymbols, diff --git a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorUIState.kt b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorUIState.kt index 0db225fc..36f46269 100644 --- a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorUIState.kt +++ b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorUIState.kt @@ -24,7 +24,7 @@ import com.sadellie.unitto.data.model.HistoryItem internal data class CalculatorUIState( val input: TextFieldValue = TextFieldValue(), val output: String = "", - val angleMode: AngleMode = AngleMode.RAD, + val radianMode: Boolean = true, val history: List = emptyList(), val allowVibration: Boolean = false ) diff --git a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorViewModel.kt b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorViewModel.kt index 955f37e0..5bcc7214 100644 --- a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorViewModel.kt +++ b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/CalculatorViewModel.kt @@ -34,7 +34,6 @@ import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch @@ -46,7 +45,7 @@ import org.mariuszgromada.math.mxparser.mXparser as MathParser @HiltViewModel internal class CalculatorViewModel @Inject constructor( - userPrefsRepository: UserPreferencesRepository, + private val userPrefsRepository: UserPreferencesRepository, private val calculatorHistoryRepository: CalculatorHistoryRepository, private val textFieldController: TextFieldController ) : ViewModel() { @@ -58,16 +57,15 @@ internal class CalculatorViewModel @Inject constructor( ) private val _output: MutableStateFlow = MutableStateFlow("") - private val _angleMode: MutableStateFlow = MutableStateFlow(AngleMode.RAD) private val _history = calculatorHistoryRepository.historyFlow val uiState = combine( - textFieldController.input, _output, _angleMode, _history, _userPrefs - ) { input, output, angleMode, history, userPrefs -> + textFieldController.input, _output, _history, _userPrefs + ) { input, output, history, userPrefs -> return@combine CalculatorUIState( input = input, output = output, - angleMode = angleMode, + radianMode = userPrefs.radianMode, history = history, allowVibration = userPrefs.enableVibrations ) @@ -82,14 +80,8 @@ internal class CalculatorViewModel @Inject constructor( fun clearSymbols() = textFieldController.clearInput() fun toggleCalculatorMode() { - _angleMode.update { - if (it == AngleMode.DEG) { - MathParser.setRadiansMode() - AngleMode.RAD - } else { - MathParser.setDegreesMode() - AngleMode.DEG - } + viewModelScope.launch { + userPrefsRepository.updateRadianMode(!_userPrefs.value.radianMode) } } @@ -185,7 +177,9 @@ internal class CalculatorViewModel @Inject constructor( // Observe and invoke calculation without UI lag. viewModelScope.launch(Dispatchers.Default) { - merge(_userPrefs, textFieldController.input, _angleMode).collectLatest { + combine(_userPrefs, textFieldController.input) { userPrefs, _ -> + if (userPrefs.radianMode) MathParser.setRadiansMode() else MathParser.setDegreesMode() + }.collectLatest { calculateInput() } } diff --git a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/TextFieldController.kt b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/TextFieldController.kt index 63d38a88..cca32725 100644 --- a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/TextFieldController.kt +++ b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/TextFieldController.kt @@ -57,11 +57,15 @@ class TextFieldController @Inject constructor() { val inputFormatted = newInput.fixFormat() val newSelectionStartEnd = inputFormatted.length - lastToEndDistance + val fixedCursor = fixCursor( + newPosition = newSelectionStartEnd..newSelectionStartEnd, + currentInput = inputFormatted + ) ?: newSelectionStartEnd..newSelectionStartEnd input.update { it.copy( text = inputFormatted, - selection = TextRange(newSelectionStartEnd, newSelectionStartEnd) + selection = TextRange(fixedCursor) ) } } @@ -72,16 +76,9 @@ class TextFieldController @Inject constructor() { fun pasteSymbols(symbols: String) = addToInput(symbols.filterUnknownSymbols()) fun moveCursor(newPosition: IntRange) { - val currentInput = input.value.text - if (newPosition.last > currentInput.length) return - - val fixedLeftCursor = cursorFixer.fixCursorIfNeeded(currentInput, newPosition.first) - val fixedRightCursor = cursorFixer.fixCursorIfNeeded(currentInput, newPosition.last) - - // Will modify input.update { it.copy( - selection = TextRange(fixedLeftCursor, fixedRightCursor) + selection = TextRange(fixCursor(newPosition) ?: return) ) } } @@ -115,7 +112,7 @@ class TextFieldController @Inject constructor() { .fixFormat() it.copy( text = newText, - selection = TextRange(newText.length - distanceFromEnd) + selection = TextRange((newText.length - distanceFromEnd).coerceAtLeast(0)) ) } } @@ -126,10 +123,24 @@ class TextFieldController @Inject constructor() { .replace(localFormatter.grouping, "") .replace(localFormatter.fractional, Token.dot) + private fun fixCursor( + newPosition: IntRange, + currentInput: String = input.value.text + ): IntRange? { + if (newPosition.last > currentInput.length) return null + + val fixedLeftCursor = cursorFixer.fixCursorIfNeeded(currentInput, newPosition.first) + val fixedRightCursor = cursorFixer.fixCursorIfNeeded(currentInput, newPosition.last) + + return fixedLeftCursor..fixedRightCursor + } + private fun String.fixFormat(): String = localFormatter.reFormat(this) private fun String.filterUnknownSymbols() = localFormatter.filterUnknownSymbols(this) + private fun TextRange(range: IntRange): TextRange = TextRange(range.first, range.last) + inner class CursorFixer { private val illegalTokens by lazy { listOf( diff --git a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/CalculatorKeyboard.kt b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/CalculatorKeyboard.kt index 978bf912..c49b3eb3 100644 --- a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/CalculatorKeyboard.kt +++ b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/CalculatorKeyboard.kt @@ -98,12 +98,11 @@ import com.sadellie.unitto.core.ui.common.key.unittoicons.RightBracket import com.sadellie.unitto.core.ui.common.key.unittoicons.Sin import com.sadellie.unitto.core.ui.common.key.unittoicons.SquareRootWide import com.sadellie.unitto.core.ui.common.key.unittoicons.Tan -import com.sadellie.unitto.feature.calculator.AngleMode @Composable internal fun CalculatorKeyboard( modifier: Modifier, - angleMode: AngleMode, + radianMode: Boolean, allowVibration: Boolean, addSymbol: (String) -> Unit, clearSymbols: () -> Unit, @@ -114,7 +113,7 @@ internal fun CalculatorKeyboard( if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT) { PortraitKeyboard( modifier = modifier, - angleMode = angleMode, + radianMode = radianMode, allowVibration = allowVibration, addSymbol = addSymbol, toggleAngleMode = toggleAngleMode, @@ -125,7 +124,7 @@ internal fun CalculatorKeyboard( } else { LandscapeKeyboard( modifier = modifier, - angleMode = angleMode, + radianMode = radianMode, allowVibration = allowVibration, addSymbol = addSymbol, toggleAngleMode = toggleAngleMode, @@ -139,7 +138,7 @@ internal fun CalculatorKeyboard( @Composable private fun PortraitKeyboard( modifier: Modifier, - angleMode: AngleMode, + radianMode: Boolean, allowVibration: Boolean, addSymbol: (String) -> Unit, toggleAngleMode: () -> Unit, @@ -185,7 +184,7 @@ private fun PortraitKeyboard( allowVibration = allowVibration, addSymbol = addSymbol, showAdditional = showAdditional, - angleMode = angleMode, + radianMode = radianMode, toggleAngleMode = toggleAngleMode, toggleInvMode = { invMode = !invMode } ) @@ -195,7 +194,7 @@ private fun PortraitKeyboard( allowVibration = allowVibration, addSymbol = addSymbol, showAdditional = showAdditional, - angleMode = angleMode, + radianMode = radianMode, toggleAngleMode = toggleAngleMode, toggleInvMode = { invMode = !invMode } ) @@ -212,7 +211,7 @@ private fun PortraitKeyboard( } } } - + Spacer(modifier = Modifier.height(verticalFraction(0.015f))) Row(weightModifier) { @@ -257,7 +256,7 @@ private fun AdditionalButtonsPortrait( allowVibration: Boolean, addSymbol: (String) -> Unit, showAdditional: Boolean, - angleMode: AngleMode, + radianMode: Boolean, toggleAngleMode: () -> Unit, toggleInvMode: () -> Unit ) { @@ -271,7 +270,7 @@ private fun AdditionalButtonsPortrait( AnimatedVisibility(showAdditional) { Column { Row { - KeyboardButtonAdditional(modifier, if (angleMode == AngleMode.DEG) UnittoIcons.Deg else UnittoIcons.Rad, allowVibration) { toggleAngleMode() } + KeyboardButtonAdditional(modifier, if (radianMode) UnittoIcons.Rad else UnittoIcons.Deg, allowVibration) { toggleAngleMode() } KeyboardButtonAdditional(modifier, UnittoIcons.Sin, allowVibration) { addSymbol(Token.sin) } KeyboardButtonAdditional(modifier, UnittoIcons.Cos, allowVibration) { addSymbol(Token.cos) } KeyboardButtonAdditional(modifier, UnittoIcons.Tan, allowVibration) { addSymbol(Token.tan) } @@ -293,7 +292,7 @@ private fun AdditionalButtonsPortraitInverse( allowVibration: Boolean, addSymbol: (String) -> Unit, showAdditional: Boolean, - angleMode: AngleMode, + radianMode: Boolean, toggleAngleMode: () -> Unit, toggleInvMode: () -> Unit ) { @@ -307,7 +306,7 @@ private fun AdditionalButtonsPortraitInverse( AnimatedVisibility(showAdditional) { Column { Row { - KeyboardButtonAdditional(modifier, if (angleMode == AngleMode.DEG) UnittoIcons.Deg else UnittoIcons.Rad, allowVibration) { toggleAngleMode() } + KeyboardButtonAdditional(modifier, if (radianMode) UnittoIcons.Rad else UnittoIcons.Deg, allowVibration) { toggleAngleMode() } KeyboardButtonAdditional(modifier, UnittoIcons.ArSin, allowVibration) { addSymbol(Token.arSin) } KeyboardButtonAdditional(modifier, UnittoIcons.ArCos, allowVibration) { addSymbol(Token.arCos) } KeyboardButtonAdditional(modifier, UnittoIcons.AcTan, allowVibration) { addSymbol(Token.acTan) } @@ -326,7 +325,7 @@ private fun AdditionalButtonsPortraitInverse( @Composable private fun LandscapeKeyboard( modifier: Modifier, - angleMode: AngleMode, + radianMode: Boolean, allowVibration: Boolean, addSymbol: (String) -> Unit, toggleAngleMode: () -> Unit, @@ -350,7 +349,7 @@ private fun LandscapeKeyboard( modifier = Modifier.weight(1f), buttonModifier = buttonModifier, allowVibration = allowVibration, - angleMode = angleMode, + radianMode = radianMode, addSymbol = addSymbol, toggleAngleMode = toggleAngleMode, toggleInvMode = { invMode = !invMode } @@ -360,7 +359,7 @@ private fun LandscapeKeyboard( modifier = Modifier.weight(1f), buttonModifier = buttonModifier, allowVibration = allowVibration, - angleMode = angleMode, + radianMode = radianMode, addSymbol = addSymbol, toggleAngleMode = toggleAngleMode, toggleInvMode = { invMode = !invMode } @@ -408,13 +407,13 @@ private fun AdditionalButtonsLandscape( modifier: Modifier, buttonModifier: Modifier, allowVibration: Boolean, - angleMode: AngleMode, + radianMode: Boolean, addSymbol: (String) -> Unit, toggleAngleMode: () -> Unit, toggleInvMode: () -> Unit ) { Column(modifier) { - KeyboardButtonAdditional(buttonModifier, if (angleMode == AngleMode.DEG) UnittoIcons.Deg else UnittoIcons.Rad, allowVibration) { toggleAngleMode() } + KeyboardButtonAdditional(buttonModifier, if (radianMode) UnittoIcons.Rad else UnittoIcons.Deg, allowVibration) { toggleAngleMode() } KeyboardButtonAdditional(buttonModifier, UnittoIcons.Inv, allowVibration) { toggleInvMode() } KeyboardButtonAdditional(buttonModifier, UnittoIcons.Sin, allowVibration) { addSymbol(Token.sin) } KeyboardButtonAdditional(buttonModifier, UnittoIcons.E, allowVibration) { addSymbol(Token.e) } @@ -440,13 +439,13 @@ private fun AdditionalButtonsLandscapeInverse( modifier: Modifier, buttonModifier: Modifier, allowVibration: Boolean, - angleMode: AngleMode, + radianMode: Boolean, addSymbol: (String) -> Unit, toggleAngleMode: () -> Unit, toggleInvMode: () -> Unit ) { Column(modifier) { - KeyboardButtonAdditional(buttonModifier, if (angleMode == AngleMode.DEG) UnittoIcons.Deg else UnittoIcons.Rad, allowVibration) { toggleAngleMode() } + KeyboardButtonAdditional(buttonModifier, if (radianMode) UnittoIcons.Rad else UnittoIcons.Deg, allowVibration) { toggleAngleMode() } KeyboardButtonAdditional(buttonModifier, UnittoIcons.Inv, allowVibration) { toggleInvMode() } KeyboardButtonAdditional(buttonModifier, UnittoIcons.ArSin, allowVibration) { addSymbol(Token.arSin) } KeyboardButtonAdditional(buttonModifier, UnittoIcons.E, allowVibration) { addSymbol(Token.e) } @@ -472,7 +471,7 @@ private fun AdditionalButtonsLandscapeInverse( private fun PreviewCalculatorKeyboard() { CalculatorKeyboard( modifier = Modifier, - angleMode = AngleMode.DEG, + radianMode = true, addSymbol = {}, clearSymbols = {}, deleteSymbol = {}, diff --git a/feature/calculator/src/test/java/com/sadellie/unitto/feature/calculator/TextFieldControllerTest.kt b/feature/calculator/src/test/java/com/sadellie/unitto/feature/calculator/TextFieldControllerTest.kt index e24a67c9..ee4d727c 100644 --- a/feature/calculator/src/test/java/com/sadellie/unitto/feature/calculator/TextFieldControllerTest.kt +++ b/feature/calculator/src/test/java/com/sadellie/unitto/feature/calculator/TextFieldControllerTest.kt @@ -184,6 +184,13 @@ internal class TextFieldControllerTest { textFieldController.delete() assertEquals("", textFieldController.text) assertEquals(0..0, textFieldController.selection) + + textFieldController.addToInput("1234") + // Place cursor like 1|,234 + textFieldController.moveCursor(1..1) + textFieldController.delete() + assertEquals("234", textFieldController.text) + assertEquals(0..0, textFieldController.selection) } @Test diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 289afa5c..c5c3287c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -appCode = "17" +appCode = "18" appName = "Illuminating emerald" kotlin = "1.8.10" androidxCore = "1.9.0" diff --git a/where-logo.png b/where-logo.png new file mode 100644 index 00000000..dd1478b0 Binary files /dev/null and b/where-logo.png differ