diff --git a/README.md b/README.md index 1e930a2..9765276 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DV - Dimensional Variables -[![main](https://github.com/alextac98/dv/actions/workflows/main.yaml/badge.svg)](https://github.com/alextac98/dv/actions/workflows/main.yaml) ![Crates.io Version](https://img.shields.io/crates/v/dv) ![PyPI - Version](https://img.shields.io/pypi/v/dv_py) +[![main](https://github.com/alextac98/dv/actions/workflows/main.yaml/badge.svg)](https://github.com/alextac98/dv/actions/workflows/main.yaml) [![Crates.io Version](https://img.shields.io/crates/v/dv)](https://crates.io/crates/dv) [![PyPI - Version](https://img.shields.io/pypi/v/dv_py)](https://pypi.org/project/dv-py/) > [!NOTE] > Full information, documentation, examples, and more can be found on the project website: https://dv.alextac.com/ diff --git a/VERSION.toml b/VERSION.toml index c4096f2..6167061 100644 --- a/VERSION.toml +++ b/VERSION.toml @@ -6,4 +6,4 @@ major = 0 minor = 3 -patch = 0 +patch = 1 diff --git a/core/Cargo.toml b/core/Cargo.toml index 409302b..3609b83 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dv" -version = "0.3.0" +version = "0.3.1" edition = "2021" authors = [ "Alex Tacescu ",] description = "Core Rust library for DimensionalVariable, a multi-language library for handling physical quantities with units." diff --git a/core/src/units.rs b/core/src/units.rs index 368b0da..15fc6a0 100644 --- a/core/src/units.rs +++ b/core/src/units.rs @@ -88,7 +88,7 @@ pub fn unit_map() -> HashMap<&'static str, Unit> { ("MA", Unit { name: "megaampere", conversion_factor: 1e6, base_unit: [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0] }), // ===== Energy Units ===== - ("ev", Unit { name: "electronvolt", conversion_factor: 1.602176634e-19, base_unit: [2.0, 1.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] }), + ("eV", Unit { name: "electronvolt", conversion_factor: 1.602176634e-19, base_unit: [2.0, 1.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] }), ("mJ", Unit { name: "millijoule", conversion_factor: 1e-3, base_unit: [2.0, 1.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] }), ("J", Unit { name: "joule", conversion_factor: 1.0, base_unit: [2.0, 1.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] }), ("kJ", Unit { name: "kilojoule", conversion_factor: 1e3, base_unit: [2.0, 1.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] }), @@ -110,6 +110,21 @@ pub fn unit_map() -> HashMap<&'static str, Unit> { ("TW", Unit { name: "terawatt", conversion_factor: 1e12, base_unit: [2.0, 1.0, -3.0, 0.0, 0.0, 0.0, 0.0, 0.0] }), ("hp", Unit { name: "horsepower", conversion_factor: 745.6998715822702, base_unit: [2.0, 1.0, -3.0, 0.0, 0.0, 0.0, 0.0, 0.0] }), + // ===== Electrical Charge Units ===== + ("Coulomb", Unit { name: "coulomb", conversion_factor: 1.0, base_unit: [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0] }), + ("mC", Unit { name: "millicoulomb", conversion_factor: 1e-3, base_unit: [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0] }), + ("kC", Unit { name: "kilocoulomb", conversion_factor: 1e3, base_unit: [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0] }), + + // ===== Electric Potential Units ===== + ("V", Unit { name: "volt", conversion_factor: 1.0, base_unit: [2.0, 1.0, -3.0, 0.0, -1.0, 0.0, 0.0, 0.0] }), + ("mV", Unit { name: "millivolt", conversion_factor: 1e-3, base_unit: [2.0, 1.0, -3.0, 0.0, -1.0, 0.0, 0.0, 0.0] }), + ("kV", Unit { name: "kilovolt", conversion_factor: 1e3, base_unit: [2.0, 1.0, -3.0, 0.0, -1.0, 0.0, 0.0, 0.0] }), + + // ===== Electric Resistance Units ===== + ("Ohm", Unit { name: "ohm", conversion_factor: 1.0, base_unit: [2.0, 1.0, -3.0, 0.0, -2.0, 0.0, 0.0, 0.0] }), + ("mOhm", Unit { name: "milliohm", conversion_factor: 1e-3, base_unit: [2.0, 1.0, -3.0, 0.0, -2.0, 0.0, 0.0, 0.0] }), + ("kOhm", Unit { name: "kiloohm", conversion_factor: 1e3, base_unit: [2.0, 1.0, -3.0, 0.0, -2.0, 0.0, 0.0, 0.0] }), + // ===== Amount of Substance Units ===== ("mol", Unit { name: "mole", conversion_factor: 1.0, base_unit: [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0] }), ("kmol", Unit { name: "kilomole", conversion_factor: 1e3, base_unit: [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0] }), diff --git a/core/tests/units_tests.rs b/core/tests/units_tests.rs index 8647320..a3a3459 100644 --- a/core/tests/units_tests.rs +++ b/core/tests/units_tests.rs @@ -104,3 +104,15 @@ fn errors_on_unknown_unit() { let result = dv::new(1.0, "unknown_unit"); assert!(result.is_err(), "Expected error on unknown unit"); } + +#[test] +fn electrical_units() { + let voltage = dv::new(10.0, "V").expect(FAIL_MSG); + let current = dv::new(2.0, "A").expect(FAIL_MSG); + let resistance = dv::new(5.0, "Ohm").expect(FAIL_MSG); + + assert!(voltage == ¤t * &resistance, "Ohm's law failed"); + + let power = dv::new(20.0, "W").expect(FAIL_MSG); + assert!(power == &voltage * ¤t, "Power calculation failed"); +} diff --git a/python/Cargo.toml b/python/Cargo.toml index e436848..ceda7d6 100644 --- a/python/Cargo.toml +++ b/python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dv_py" -version = "0.3.0" +version = "0.3.1" edition = "2021" authors = [ "Alex Tacescu ",] homepage = "https://dv.alextac.com" diff --git a/python/pyproject.toml b/python/pyproject.toml index f84dac9..b7fcaf3 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "dv_py" -version = "0.3.0" +version = "0.3.1" description = "Python bindings for dv (DimensionalVariable) - keeping track of units and dimensions for physical quantities" readme = "pip-readme.md" requires-python = ">=3.8"