Sha256: b8b641771a3e873e6a73d3b4ddd6c18c856755699a1a5eaf2cb40be743cd53f5

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require 'test_helper'

describe Unitwise::Unit do

  let(:ms2) { Unitwise::Unit.new("m/s2") }
  let(:kg) { Unitwise::Unit.new("kg") }
  let(:psi) { Unitwise::Unit.new("[psi]")}
  let(:deg) { Unitwise::Unit.new("deg")}


  describe "#terms" do
    it "must be a collection of terms" do
      ms2.must_respond_to :terms
      ms2.terms.must_be_kind_of Enumerable
      ms2.terms.sample.must_be_instance_of Unitwise::Term
    end
  end

  describe "#root_terms" do
    it "must be an array of Terms" do
      ms2.must_respond_to :terms
      ms2.root_terms.must_be_kind_of Array
      ms2.root_terms.sample.must_be_instance_of Unitwise::Term
    end
  end

  describe "#scalar" do
    it "must return value relative to terminal atoms" do
      ms2.must_respond_to :scalar
      ms2.scalar.must_equal 1
      psi.scalar.must_equal 6894757.293168359
      deg.scalar.must_equal 0.017453292519943295
    end
  end

  describe "#composition" do
    it "must be a multiset" do
      ms2.must_respond_to :terms
      ms2.composition.must_be_instance_of SignedMultiset
    end
  end

  describe "#*" do
    it "should multiply units" do
      mult = kg * ms2
      mult.expression.to_s.must_equal "kg.m/s2"
    end
  end

  describe "#/" do
    it "should divide units" do
      div = kg / ms2
      div.expression.to_s.must_equal "kg.s2/m"
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unitwise-0.2.1 test/unitwise/unit_test.rb
unitwise-0.2.0 test/unitwise/unit_test.rb
unitwise-0.1.0 test/unitwise/unit_test.rb