mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
Added prefixes (#30)
This commit is contained in:
parent
c155f6c9c7
commit
4a646a0a7e
@ -997,6 +997,58 @@
|
||||
<string name="petafarad">Petafarad</string>
|
||||
<string name="petafarad_short">PF</string>
|
||||
|
||||
<!--Prefixes-->
|
||||
<string name="prefix_quetta">Quetta</string>
|
||||
<string name="prefix_quetta_short">Q</string>
|
||||
<string name="prefix_ronna">Ronna</string>
|
||||
<string name="prefix_ronna_short">R</string>
|
||||
<string name="prefix_yotta">Yotta</string>
|
||||
<string name="prefix_yotta_short">Y</string>
|
||||
<string name="prefix_zetta">Zetta</string>
|
||||
<string name="prefix_zetta_short">Z</string>
|
||||
<string name="prefix_exa">Exa</string>
|
||||
<string name="prefix_exa_short">E</string>
|
||||
<string name="prefix_peta">Peta</string>
|
||||
<string name="prefix_peta_short">P</string>
|
||||
<string name="prefix_tera">Tera</string>
|
||||
<string name="prefix_tera_short">T</string>
|
||||
<string name="prefix_giga">Giga</string>
|
||||
<string name="prefix_giga_short">G</string>
|
||||
<string name="prefix_mega">Mega</string>
|
||||
<string name="prefix_mega_short">M</string>
|
||||
<string name="prefix_kilo">Kilo</string>
|
||||
<string name="prefix_kilo_short">k</string>
|
||||
<string name="prefix_hecto">Hecto</string>
|
||||
<string name="prefix_hecto_short">h</string>
|
||||
<string name="prefix_deca">Deca</string>
|
||||
<string name="prefix_deca_short">da</string>
|
||||
<string name="prefix_base">Base</string>
|
||||
<string name="prefix_base_short">Base</string>
|
||||
<string name="prefix_deci">Deci</string>
|
||||
<string name="prefix_deci_short">d</string>
|
||||
<string name="prefix_centi">Centi</string>
|
||||
<string name="prefix_centi_short">c</string>
|
||||
<string name="prefix_milli">Milli</string>
|
||||
<string name="prefix_milli_short">m</string>
|
||||
<string name="prefix_micro">Micro</string>
|
||||
<string name="prefix_micro_short">μ</string>
|
||||
<string name="prefix_nano">Nano</string>
|
||||
<string name="prefix_nano_short">n</string>
|
||||
<string name="prefix_pico">Pico</string>
|
||||
<string name="prefix_pico_short">p</string>
|
||||
<string name="prefix_femto">Femto</string>
|
||||
<string name="prefix_femto_short">f</string>
|
||||
<string name="prefix_atto">Atto</string>
|
||||
<string name="prefix_atto_short">a</string>
|
||||
<string name="prefix_zepto">Zepto</string>
|
||||
<string name="prefix_zepto_short">z</string>
|
||||
<string name="prefix_yocto">Yocto</string>
|
||||
<string name="prefix_yocto_short">y</string>
|
||||
<string name="prefix_ronto">Ronto</string>
|
||||
<string name="prefix_ronto_short">r</string>
|
||||
<string name="prefix_quecto">Quecto</string>
|
||||
<string name="prefix_quecto_short">q</string>
|
||||
|
||||
<!--Groups-->
|
||||
<string name="length">Length</string>
|
||||
<string name="time">Time</string>
|
||||
@ -1016,6 +1068,7 @@
|
||||
<string name="flux">Flux</string>
|
||||
<string name="number_base">Base</string>
|
||||
<string name="electrostatic_capacitance">Capacitance</string>
|
||||
<string name="prefix">Prefix</string>
|
||||
|
||||
<!--Screen names-->
|
||||
<string name="units_screen_from">Convert from</string>
|
||||
|
@ -48,5 +48,6 @@ 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)
|
||||
ELECTROSTATIC_CAPACITANCE(res = R.string.electrostatic_capacitance),
|
||||
PREFIX(res = R.string.prefix),
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ import com.sadellie.unitto.data.units.collections.timeCollection
|
||||
import com.sadellie.unitto.data.units.collections.volumeCollection
|
||||
import com.sadellie.unitto.data.database.UnitsEntity
|
||||
import com.sadellie.unitto.data.units.collections.electrostaticCapacitance
|
||||
import com.sadellie.unitto.data.units.collections.prefix
|
||||
import java.math.BigDecimal
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
@ -80,7 +81,8 @@ class AllUnitsRepository @Inject constructor() {
|
||||
UnitGroup.DATA_TRANSFER to dataTransferCollection,
|
||||
UnitGroup.FLUX to fluxCollection,
|
||||
UnitGroup.NUMBER_BASE to numberBaseCollection,
|
||||
UnitGroup.ELECTROSTATIC_CAPACITANCE to electrostaticCapacitance
|
||||
UnitGroup.ELECTROSTATIC_CAPACITANCE to electrostaticCapacitance,
|
||||
UnitGroup.PREFIX to prefix,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -530,4 +530,31 @@ object MyUnitIDS {
|
||||
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"
|
||||
}
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 prefix: List<AbstractUnit> 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),
|
||||
)
|
||||
}
|
@ -391,6 +391,35 @@ class AllUnitsTest {
|
||||
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")
|
||||
}
|
||||
|
||||
private fun String.checkWith(checkingId: String, value: String, expected: String) {
|
||||
val unitFrom = allUnitsRepository.getById(this)
|
||||
val unitTo = allUnitsRepository.getById(checkingId)
|
||||
|
Loading…
x
Reference in New Issue
Block a user