Added Electrostatic capacitance #28

This commit is contained in:
Sad Ellie 2023-03-22 13:17:31 +03:00
parent 7eb0edaeed
commit 5b8d811ad6
6 changed files with 103 additions and 0 deletions

View File

@ -971,6 +971,32 @@
<string name="hexadecimal">Hexadecimal</string> <string name="hexadecimal">Hexadecimal</string>
<string name="hexadecimal_short">base16</string> <string name="hexadecimal_short">base16</string>
<!--ELECTROSTATIC CAPACITANCE-->
<string name="attofarad">Attofarad</string>
<string name="attofarad_short">aF</string>
<string name="statfarad">Statfarad</string>
<string name="statfarad_short">stF</string>
<string name="farad">Farad</string>
<string name="farad_short">F</string>
<string name="exafarad">Exafarad</string>
<string name="exafarad_short">EF</string>
<string name="picofarad">Picofarad</string>
<string name="picofarad_short">pF</string>
<string name="nanofarad">Nanofarad</string>
<string name="nanofarad_short">nF</string>
<string name="microfarad">Microfarad</string>
<string name="microfarad_short">µF</string>
<string name="millifarad">Millifarad</string>
<string name="millifarad_short">mF</string>
<string name="kilofarad">Kilofarad</string>
<string name="kilofarad_short">kF</string>
<string name="megafarad">Megafarad</string>
<string name="megafarad_short">MF</string>
<string name="gigafarad">Gigafarad</string>
<string name="gigafarad_short">GF</string>
<string name="petafarad">Petafarad</string>
<string name="petafarad_short">PF</string>
<!--Groups--> <!--Groups-->
<string name="length">Length</string> <string name="length">Length</string>
<string name="time">Time</string> <string name="time">Time</string>
@ -989,6 +1015,7 @@
<string name="currency">Currency</string> <string name="currency">Currency</string>
<string name="flux">Flux</string> <string name="flux">Flux</string>
<string name="number_base">Base</string> <string name="number_base">Base</string>
<string name="electrostatic_capacitance">Capacitance</string>
<!--Screen names--> <!--Screen names-->
<string name="units_screen_from">Convert from</string> <string name="units_screen_from">Convert from</string>

View File

@ -48,4 +48,5 @@ enum class UnitGroup(
DATA_TRANSFER(res = R.string.data_transfer), DATA_TRANSFER(res = R.string.data_transfer),
FLUX(res = R.string.flux), FLUX(res = R.string.flux),
NUMBER_BASE(res = R.string.number_base), NUMBER_BASE(res = R.string.number_base),
ELECTROSTATIC_CAPACITANCE(res = R.string.electrostatic_capacitance)
} }

View File

@ -41,6 +41,7 @@ import com.sadellie.unitto.data.units.collections.temperatureCollection
import com.sadellie.unitto.data.units.collections.timeCollection import com.sadellie.unitto.data.units.collections.timeCollection
import com.sadellie.unitto.data.units.collections.volumeCollection import com.sadellie.unitto.data.units.collections.volumeCollection
import com.sadellie.unitto.data.database.UnitsEntity import com.sadellie.unitto.data.database.UnitsEntity
import com.sadellie.unitto.data.units.collections.electrostaticCapacitance
import java.math.BigDecimal import java.math.BigDecimal
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -79,6 +80,7 @@ class AllUnitsRepository @Inject constructor() {
UnitGroup.DATA_TRANSFER to dataTransferCollection, UnitGroup.DATA_TRANSFER to dataTransferCollection,
UnitGroup.FLUX to fluxCollection, UnitGroup.FLUX to fluxCollection,
UnitGroup.NUMBER_BASE to numberBaseCollection, UnitGroup.NUMBER_BASE to numberBaseCollection,
UnitGroup.ELECTROSTATIC_CAPACITANCE to electrostaticCapacitance
) )
} }

View File

@ -516,4 +516,18 @@ object MyUnitIDS {
const val tetradecimal = "tetradecimal" const val tetradecimal = "tetradecimal"
const val pentadecimal = "pentadecimal" const val pentadecimal = "pentadecimal"
const val hexadecimal = "hexadecimal" 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"
} }

View File

@ -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 <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
internal val electrostaticCapacitance: List<AbstractUnit> 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),
)
}

View File

@ -375,6 +375,22 @@ class AllUnitsTest {
MyUnitIDS.hexadecimal.checkWith(MyUnitIDS.quinary, "FADE", "4023342") MyUnitIDS.hexadecimal.checkWith(MyUnitIDS.quinary, "FADE", "4023342")
} }
@Test
fun testElectrostaticCapacitance() {
MyUnitIDS.attofarad.checkWith(MyUnitIDS.nanofarad, "364354322342", "364.35432")
MyUnitIDS.statfarad.checkWith(MyUnitIDS.microfarad, "123312", "0.1372")
MyUnitIDS.farad.checkWith(MyUnitIDS.kilofarad, "123312", "123.312")
MyUnitIDS.exafarad.checkWith(MyUnitIDS.petafarad, "123312", "123312000")
MyUnitIDS.picofarad.checkWith(MyUnitIDS.nanofarad, "11233", "11.233")
MyUnitIDS.nanofarad.checkWith(MyUnitIDS.millifarad, "11233", "0.01123")
MyUnitIDS.microfarad.checkWith(MyUnitIDS.nanofarad, "1123433", "1123433000")
MyUnitIDS.millifarad.checkWith(MyUnitIDS.nanofarad, "112", "112000000")
MyUnitIDS.kilofarad.checkWith(MyUnitIDS.microfarad, "11132", "11132000000000")
MyUnitIDS.megafarad.checkWith(MyUnitIDS.kilofarad, "11132", "11132000")
MyUnitIDS.gigafarad.checkWith(MyUnitIDS.petafarad, "11132", "0.01113")
MyUnitIDS.petafarad.checkWith(MyUnitIDS.kilofarad, "11132", "11132000000000000")
}
private fun String.checkWith(checkingId: String, value: String, expected: String) { private fun String.checkWith(checkingId: String, value: String, expected: String) {
val unitFrom = allUnitsRepository.getById(this) val unitFrom = allUnitsRepository.getById(this)
val unitTo = allUnitsRepository.getById(checkingId) val unitTo = allUnitsRepository.getById(checkingId)