-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e1742d
commit 34a4b98
Showing
7 changed files
with
115 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
[tool.poetry] | ||
name = "octet" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
description = "Object-oriented way to represent digital sizes (bits and bytes)" | ||
authors = ["Enrique Soria <[email protected]>"] | ||
license = "MIT" | ||
readme = "README.md" | ||
homepage = "https://github.com/EnriqueSoria/octet" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.7" | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from __future__ import annotations | ||
|
||
from .base import Magnitude | ||
from .constants import BINARY | ||
from .constants import DECIMAL | ||
|
||
b = bit = Magnitude.create_magnitude("b") | ||
Kib = Kibibit = Magnitude.create_magnitude("Kib", base_magnitude=bit, base=BINARY, order=10) | ||
Mib = Mebibit = Magnitude.create_magnitude("Mib", base_magnitude=bit, base=BINARY, order=20) | ||
Gib = Gibibit = Magnitude.create_magnitude("Gib", base_magnitude=bit, base=BINARY, order=30) | ||
Tib = Tebibit = Magnitude.create_magnitude("Tib", base_magnitude=bit, base=BINARY, order=40) | ||
Pib = Pebibit = Magnitude.create_magnitude("Pib", base_magnitude=bit, base=BINARY, order=50) | ||
B = Byte = Magnitude.create_magnitude("B", base_magnitude=bit, base=BINARY, order=3) | ||
KiB = KibiByte = Magnitude.create_magnitude("KiB", base_magnitude=Byte, base=BINARY, order=10) | ||
MiB = MebiByte = Magnitude.create_magnitude("MiB", base_magnitude=Byte, base=BINARY, order=20) | ||
GiB = GibiByte = Magnitude.create_magnitude("GiB", base_magnitude=Byte, base=BINARY, order=30) | ||
TiB = TebiByte = Magnitude.create_magnitude("TiB", base_magnitude=Byte, base=BINARY, order=40) | ||
PiB = PebiByte = Magnitude.create_magnitude("PiB", base_magnitude=Byte, base=BINARY, order=50) | ||
Kb = Kilobit = Magnitude.create_magnitude("Kb", base_magnitude=bit, base=DECIMAL, order=3) | ||
Mb = Megabit = Magnitude.create_magnitude("Mb", base_magnitude=bit, base=DECIMAL, order=4) | ||
Gb = Gigabit = Magnitude.create_magnitude("Gb", base_magnitude=bit, base=DECIMAL, order=5) | ||
Tb = Terabit = Magnitude.create_magnitude("Tb", base_magnitude=bit, base=DECIMAL, order=6) | ||
Pb = Petabit = Magnitude.create_magnitude("Pb", base_magnitude=bit, base=DECIMAL, order=7) | ||
KB = KiloByte = Magnitude.create_magnitude("KB", base_magnitude=Byte, base=DECIMAL, order=3) | ||
MB = MegaByte = Magnitude.create_magnitude("MB", base_magnitude=Byte, base=DECIMAL, order=4) | ||
GB = GigaByte = Magnitude.create_magnitude("GB", base_magnitude=Byte, base=DECIMAL, order=5) | ||
TB = TeraByte = Magnitude.create_magnitude("TB", base_magnitude=Byte, base=DECIMAL, order=6) | ||
PB = PetaByte = Magnitude.create_magnitude("PB", base_magnitude=Byte, base=DECIMAL, order=7) | ||
|
||
|
||
__all__ = [ | ||
"b", | ||
"Kib", | ||
"Mib", | ||
"Gib", | ||
"Tib", | ||
"Pib", | ||
"B", | ||
"KiB", | ||
"MiB", | ||
"GiB", | ||
"TiB", | ||
"PiB", | ||
"Kb", | ||
"Mb", | ||
"Gb", | ||
"Tb", | ||
"Pb", | ||
"KB", | ||
"MB", | ||
"GB", | ||
"TB", | ||
"PB", | ||
"bit", | ||
"Kibibit", | ||
"Mebibit", | ||
"Gibibit", | ||
"Tebibit", | ||
"Pebibit", | ||
"Byte", | ||
"KibiByte", | ||
"MebiByte", | ||
"GibiByte", | ||
"TebiByte", | ||
"PebiByte", | ||
"Kilobit", | ||
"Megabit", | ||
"Gigabit", | ||
"Terabit", | ||
"Petabit", | ||
"KiloByte", | ||
"MegaByte", | ||
"GigaByte", | ||
"TeraByte", | ||
"PetaByte", | ||
] |
File renamed without changes.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from octet import * | ||
|
||
assert Byte.get_minor_unit_class() is bit | ||
assert KB.get_minor_unit_class() is bit | ||
|
||
assert Byte.from_minor_units(16) == Byte(2) | ||
assert bit(16).convert_to(Byte) == Byte(2) | ||
|
||
# Comparisons between different unit sizes | ||
assert bit(1024) > Byte(3) | ||
assert bit(1024) > bit(1) | ||
assert Byte(1024) > Byte(1) | ||
|
||
# Comparisons between magnitudes | ||
# bytes to bit | ||
assert B() == bit(8) | ||
assert KiB() == 8 * Kib() | ||
|
||
# bit to bit | ||
assert 1 * Kib() == 1024 * bit() | ||
assert 1 * Kib() == 1024 * bit() | ||
|
||
# byte to byte | ||
assert 1 * KiB() == 1024 * B() | ||
assert 1 * MiB() == 1024 * KiB() | ||
assert 1 * GiB() == 1024 * MiB() | ||
assert 1 * TiB() == 1024 * GiB() | ||
|
||
# kilo | ||
assert Kb() == 1000 * b() | ||
assert KB() == 8000 * b() | ||
|
||
# kibi vs kilo | ||
assert 1000 * Kib() == 1024 * Kb() | ||
|
||
assert GiB(1).convert_to(Byte).value == 2**30 | ||
assert GiB(1).to_minor_units().value == 2**30 * 8 |