Skip to content

Commit

Permalink
Merge pull request #41 from shivam091/4.9.0
Browse files Browse the repository at this point in the history
4.9.0
  • Loading branch information
shivam091 authored Oct 12, 2023
2 parents 2154399 + 02d63e7 commit a70c5fa
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 10 deletions.
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 unit 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
7 changes: 1 addition & 6 deletions lib/unit_measurements/unit_groups/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# -*- frozen_string_literal: true -*-
# -*- warn_indent: true -*-

## Fundamental SI units

require_relative "amount_of_substance"
require_relative "electric_current"
require_relative "length"
Expand All @@ -12,8 +10,6 @@
require_relative "time"
require_relative "weight"

## Derived units

require_relative "area"
require_relative "volume"
require_relative "density"
Expand Down Expand Up @@ -50,8 +46,7 @@
require_relative "radiation_exposure"
require_relative "radiation_absorbed_dose"
require_relative "radiation_equivalent_dose"

## Other units
require_relative "information_entropy"

require_relative "sound_level"
require_relative "plane_angle"
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* | byte, bytes |
| 3 | Sh | shannon, shannons |
| _4_ | _nat_ | _nit, nepit, natural unit of information_ |
| 5 | nybl | nibble, nibbles, nybble, nyble |
| 6 | Hart | hartley, ban, dit |

0 comments on commit a70c5fa

Please sign in to comment.