Skip to content

Commit

Permalink
Generate Bits prefixes haimkastner/unitsnet-js#11
Browse files Browse the repository at this point in the history
  • Loading branch information
haimkastner committed May 18, 2024
1 parent f65f20b commit 54074b4
Show file tree
Hide file tree
Showing 6 changed files with 1,104 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ print(results6.to_string(LengthUnits.Meter)) # 1000 m
# Complex objects

# Any object supports arithmetic operations can be used as well as unit
# see numpay array example:
# see numpy array example:
import numpy as np

np_array = np.array([[2, 4, 6], [7, 8, 9]])
Expand Down
9 changes: 9 additions & 0 deletions tests/test_unit_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Angle,
Length,
LengthUnits,
Information
)


Expand Down Expand Up @@ -31,6 +32,14 @@ def test_convert_unit_prefix_to_base(self):
angle = Angle.from_microradians(3141592.65358979)
self.assertAlmostEqual(angle.degrees, 180, delta=0.00001)

def test_convert_bits_prefix_to_base(self):
data = Information.from_kibibits(1)
self.assertAlmostEqual(data.bits, 1024)

def test_convert_base_to_bits_prefix(self):
data = Information.from_bits(1024)
self.assertAlmostEqual(data.kibibits, 1)

def test_convert_to_specific_unit_enum(self):
param_list = [
(LengthUnits.Meter, LengthUnits.Centimeter, 'centimeters'),
Expand Down
14 changes: 13 additions & 1 deletion units_generator/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def upper_to_lower_camelcase(s):
'Nano': 1e-9,
'Pico': 1e-12,
'Femto': 1e-15,
'Kibi': 1024,
'Mebi': 1024 ** 2,
'Gibi': 1024 ** 3,
'Tebi': 1024 ** 4,
'Pebi': 1024 ** 5,
'Exbi': 1024 ** 6
}


Expand All @@ -99,5 +105,11 @@ def upper_to_lower_camelcase(s):
'Micro': 'μ',
'Nano': 'n',
'Pico': 'p',
'Femto': 'f'
'Femto': 'f',
'Kibi': 'KiB',
'Mebi': 'MiB',
'Gibi': 'GiB',
'Tebi': 'TiB',
'Pebi': 'PiB',
'Exbi': 'EiB',
}
2 changes: 1 addition & 1 deletion units_generator/templates/readme_template.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ print(results6.to_string(LengthUnits.Meter)) # 1000 m
# Complex objects

# Any object supports arithmetic operations can be used as well as unit
# see numpay array example:
# see numpy array example:
import numpy as np

np_array = np.array([[2, 4, 6], [7, 8, 9]])
Expand Down
Loading

0 comments on commit 54074b4

Please sign in to comment.