Sha256: bdddc7af1ef99d50a47f4dd2664a39bd44470beac3e58918098f26e0f7b502b5

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'
module Alf
  describe Ordering, "compare" do

    it "should work on a singleton ordering" do
      key = Ordering.coerce [:a]
      key.compare({:a => 1}, {:a => 2}).should == -1
      key.compare({:a => 1}, {:a => 1}).should == 0
      key.compare({:a => 2}, {:a => 1}).should == 1
    end

    it "should work on singleton when :desc" do
      key = Ordering.coerce [[:a, :desc]]
      key.compare({:a => 1}, {:a => 2}).should == 1
      key.compare({:a => 1}, {:a => 1}).should == 0
      key.compare({:a => 2}, {:a => 1}).should == -1
    end

    it "should work with multiple keys" do
      key = Ordering.coerce [[:a, :asc], [:b, :desc]]
      key.compare({:a => 1, :b => 1}, {:a => 0, :b => 1}).should == 1
      key.compare({:a => -1, :b => 1}, {:a => 0, :b => 1}).should == -1
      key.compare({:a => 0, :b => 1}, {:a => 0, :b => 0}).should == -1
      key.compare({:a => 1, :b => 1}, {:a => 1, :b => 2}).should == 1
      key.compare({:a => 1, :b => 1}, {:a => 1, :b => 1}).should == 0
    end

  end # compare
end # Alf

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-types/ordering/test_compare.rb
alf-core-0.14.0 spec/unit/alf-types/ordering/test_compare.rb
alf-core-0.13.1 spec/unit/alf-types/ordering/test_compare.rb
alf-core-0.13.0 spec/unit/alf-types/ordering/test_compare.rb