Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Bits prefixes #22

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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