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

4.9.0 #39

Closed
wants to merge 6 commits into from
Closed
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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
## [4.8.0](https://github.com/shivam091/unit_measurements/compare/v4.7.0...v4.8.0) - 2023-10-11
## [4.9.0](https://github.com/shivam091/unit_measurements/compare/v4.8.0...v4.9.0) - 2023-10-13

### What's new

- Added units group for `information entropy` units.

----------

## [4.8.0](https://github.com/shivam091/unit_measurements/compare/v4.7.0...v4.8.0) - 2023-10-12

### What's new

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
unit_measurements (4.8.0)
unit_measurements (4.9.0)
activesupport (~> 7.0)

GEM
Expand Down
1 change: 1 addition & 0 deletions lib/unit_measurements/unit_groups/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
require_relative "radiation_exposure"
require_relative "radiation_absorbed_dose"
require_relative "radiation_equivalent_dose"
require_relative "information_entropy"

## Other units

Expand Down
15 changes: 15 additions & 0 deletions lib/unit_measurements/unit_groups/information_entropy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- encoding: utf-8 -*-
# -*- frozen_string_literal: true -*-
# -*- warn_indent: true -*-

UnitMeasurements::InformationEntropy = UnitMeasurements.build do
primitive "nat"

si_unit "b", value: "1 Sh", aliases: ["bit", "bits"]
si_unit "B", value: [2.pow(3), "b"], aliases: ["byte", "bytes"]

unit "Sh", value: [Math.log(2), "nat"], aliases: ["shannon", "shannons"]
unit "nat", aliases: ["nit", "nepit", "natural unit of information"]
unit "nybl", value: [2.pow(2), "b"], aliases: ["nibble", "nibbles", "nybble", "nyble"]
unit "Hart", value: [Math.log(10), "nat"], aliases: ["hartley", "ban", "dit"]
end
2 changes: 1 addition & 1 deletion lib/unit_measurements/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# -*- warn_indent: true -*-

module UnitMeasurements
VERSION = "4.8.0"
VERSION = "4.9.0"
end
151 changes: 151 additions & 0 deletions spec/unit_measurements/unit_groups/information_entropy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# -*- encoding: utf-8 -*-
# -*- frozen_string_literal: true -*-
# -*- warn_indent: true -*-

# spec/unit_measurements/unit_groups/information_entropy_spec.rb

RSpec.describe UnitMeasurements::InformationEntropy do
describe "nat" do
subject { described_class.new(1, "nat") }

it "converts to Sh" do
expect(subject.convert_to("Sh").quantity).to eq(1.44269504088896)
end

it "converts to Hart" do
expect(subject.convert_to("Hart").quantity).to eq(0.434294481903252)
end

it "converts to b" do
expect(subject.convert_to("b").quantity).to eq(1.44269504088896)
end

it "converts to B" do
expect(subject.convert_to("B").quantity).to eq(0.18033688011112)
end

it "converts to nybl" do
expect(subject.convert_to("nybl").quantity).to eq(0.360673760222241)
end
end

describe "Sh" do
subject { described_class.new(1, "Sh") }

it "converts to nat" do
expect(subject.convert_to("nat").quantity).to eq(0.693147180559945)
end

it "converts to Hart" do
expect(subject.convert_to("Hart").quantity).to eq(0.301029995663981)
end

it "converts to b" do
expect(subject.convert_to("b").quantity).to eq(1)
end

it "converts to B" do
expect(subject.convert_to("B").quantity).to eq(0.125)
end

it "converts to nybl" do
expect(subject.convert_to("nybl").quantity).to eq(0.25)
end
end

describe "Hart" do
subject { described_class.new(1, "Hart") }

it "converts to nat" do
expect(subject.convert_to("nat").quantity).to eq(2.30258509299405)
end

it "converts to Sh" do
expect(subject.convert_to("Sh").quantity).to eq(3.32192809488736)
end

it "converts to b" do
expect(subject.convert_to("b").quantity).to eq(3.32192809488736)
end

it "converts to B" do
expect(subject.convert_to("B").quantity).to eq(0.41524101186092)
end

it "converts to nybl" do
expect(subject.convert_to("nybl").quantity).to eq(0.830482023721841)
end
end

describe "b" do
subject { described_class.new(1, "b") }

it "converts to nat" do
expect(subject.convert_to("nat").quantity).to eq(0.693147180559945)
end

it "converts to Sh" do
expect(subject.convert_to("Sh").quantity).to eq(1)
end

it "converts to Hart" do
expect(subject.convert_to("Hart").quantity).to eq(0.301029995663981)
end

it "converts to B" do
expect(subject.convert_to("B").quantity).to eq(0.125)
end

it "converts to nybl" do
expect(subject.convert_to("nybl").quantity).to eq(0.25)
end
end

describe "B" do
subject { described_class.new(1, "B") }

it "converts to nat" do
expect(subject.convert_to("nat").quantity).to eq(5.54517744447956)
end

it "converts to Sh" do
expect(subject.convert_to("Sh").quantity).to eq(8)
end

it "converts to Hart" do
expect(subject.convert_to("Hart").quantity).to eq(2.40823996531185)
end

it "converts to b" do
expect(subject.convert_to("b").quantity).to eq(8)
end

it "converts to nybl" do
expect(subject.convert_to("nybl").quantity).to eq(2)
end
end

describe "nybl" do
subject { described_class.new(1, "nybl") }

it "converts to nat" do
expect(subject.convert_to("nat").quantity).to eq(2.77258872223978)
end

it "converts to Sh" do
expect(subject.convert_to("Sh").quantity).to eq(4)
end

it "converts to Hart" do
expect(subject.convert_to("Hart").quantity).to eq(1.20411998265592)
end

it "converts to b" do
expect(subject.convert_to("b").quantity).to eq(4)
end

it "converts to B" do
expect(subject.convert_to("B").quantity).to eq(0.5)
end
end
end
2 changes: 1 addition & 1 deletion spec/unit_measurements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

RSpec.describe UnitMeasurements do
it "has a valid version number" do
expect(UnitMeasurements::VERSION).to eq("4.8.0")
expect(UnitMeasurements::VERSION).to eq("4.9.0")
end
end
13 changes: 13 additions & 0 deletions units.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,16 @@ These units are defined in `UnitMeasurements::RadiationEquivalentDose`.
|:--|:--|:--|
| _1_ | _Sv*_ | _sievert, sieverts_ |
| 2 | rem | röntgen equivalent man, roentgen equivalent man |

## 48. Information entropy

These units are defined in `UnitMeasurements::InformationEntropy`.

| # | Name | Aliases |
|:--|:--|:--|
| 1 | b* | bit, bits |
| 2 | B* | bytes, bytes |
| _3_ | _nat_ | _nit, nepit, natural unit of information_ |
| 4 | Sh | shannon, shannons |
| 5 | Hart | hartley, ban, dit |
| 6 | nybl | nibble, nibbles, nybble, nyble |