From 273cbcc0ff55c966c62835d9f8445aee178bdf9c Mon Sep 17 00:00:00 2001 From: Sad Ellie Date: Thu, 23 Mar 2023 13:41:46 +0300 Subject: [PATCH] Added force (#29) --- core/base/src/main/res/values/strings.xml | 33 +++++++++++++ .../sadellie/unitto/data/model/UnitGroup.kt | 1 + .../unitto/data/units/AllUnitsRepository.kt | 2 + .../sadellie/unitto/data/units/MyUnitIDS.kt | 17 +++++++ .../unitto/data/units/collections/Force.kt | 46 +++++++++++++++++++ .../unitto/data/units/AllUnitsTest.kt | 19 ++++++++ 6 files changed, 118 insertions(+) create mode 100644 data/units/src/main/java/com/sadellie/unitto/data/units/collections/Force.kt diff --git a/core/base/src/main/res/values/strings.xml b/core/base/src/main/res/values/strings.xml index b4c96438..ad211742 100644 --- a/core/base/src/main/res/values/strings.xml +++ b/core/base/src/main/res/values/strings.xml @@ -1049,6 +1049,38 @@ 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 + Length Time @@ -1069,6 +1101,7 @@ Base Capacitance Prefix + Force 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 55c3b3c7..452e3d40 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 @@ -50,4 +50,5 @@ enum class UnitGroup( NUMBER_BASE(res = R.string.number_base), ELECTROSTATIC_CAPACITANCE(res = R.string.electrostatic_capacitance), PREFIX(res = R.string.prefix), + FORCE(res = R.string.force), } 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 27f541a7..a81c6500 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 @@ -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.forceCollection import com.sadellie.unitto.data.units.collections.prefix import java.math.BigDecimal import javax.inject.Inject @@ -83,6 +84,7 @@ class AllUnitsRepository @Inject constructor() { UnitGroup.NUMBER_BASE to numberBaseCollection, UnitGroup.ELECTROSTATIC_CAPACITANCE to electrostaticCapacitance, UnitGroup.PREFIX to prefix, + UnitGroup.FORCE to forceCollection, ) } 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 9d671493..fc9ba7c9 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 @@ -557,4 +557,21 @@ object MyUnitIDS { 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" } 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..647ba164 --- /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.newton, BigDecimal.valueOf(1E+18), UnitGroup.FORCE, R.string.newton, R.string.newton_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.millinewton, BigDecimal.valueOf(1E+15), UnitGroup.FORCE, R.string.millinewton, R.string.millinewton_short), + 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.joule_per_meter, BigDecimal.valueOf(1E+18), UnitGroup.FORCE, R.string.joule_per_meter, R.string.joule_per_meter_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.kilopound_force, BigDecimal.valueOf(4.448221615255E+21), UnitGroup.FORCE, R.string.kilopound_force, R.string.kilopound_force_short), + MyUnit(MyUnitIDS.pound_force, BigDecimal.valueOf(4.4482216152550001E18), UnitGroup.FORCE, R.string.pound_force, R.string.pound_force_short), + MyUnit(MyUnitIDS.ounce_force, BigDecimal.valueOf(2.78013850953423008E17), UnitGroup.FORCE, R.string.ounce_force, R.string.ounce_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/test/java/com/sadellie/unitto/data/units/AllUnitsTest.kt b/data/units/src/test/java/com/sadellie/unitto/data/units/AllUnitsTest.kt index ae569b76..29087877 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 @@ -420,6 +420,25 @@ class AllUnitsTest { 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") + } + private fun String.checkWith(checkingId: String, value: String, expected: String) { val unitFrom = allUnitsRepository.getById(this) val unitTo = allUnitsRepository.getById(checkingId)