pcbr 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pcbr.rb +8 -14
  3. data/pcbr.gemspec +1 -1
  4. data/spec/_spec.rb +20 -0
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94c525ae292660782aa466569e23c274024e1220
4
- data.tar.gz: 409faba010ccd426ad3f5cab17aa0f9470f680b7
3
+ metadata.gz: fb643a049750bf248970b7a81eb17a681421213d
4
+ data.tar.gz: d209e1311d679f5615746ea03fadc94207b40a7e
5
5
  SHA512:
6
- metadata.gz: 4caa489706874b4ff8bf10d9a535485f083b5e8566d5ee97317541fc3d3f2193ffd8e557e23f50140482d0fa3200e9d5557cc7ec2719e11d5f683a8be01f77e7
7
- data.tar.gz: 6390f836a93fc357aa7c184d6df9fbf1ac007077ebb4fc08d0312600798407abbd9136cb3d98da8ddcf5f506852e62dd85d531f33a1ac27e4358f5484f199a7e
6
+ metadata.gz: 6cdbb2fb68bbf2a0572a3cd71cd9b537819308e49df987d701923d17c584828dabd99726b3ed4d13bf7813d8874061b290e6a6a2446136df94be3b43d410a035
7
+ data.tar.gz: 0a47d2434ddc995fa20e72c36fd05ed5abf3bb5a43f2d758b205c692df9c3f92ad8f5ea675d3b982c8d5716f6ddd8decb857c7490bb93a777d93bfa6ade24133
@@ -9,36 +9,30 @@ module PCBR
9
9
  Storage.new &block
10
10
  end
11
11
 
12
- ARRAY_101 = [0, 0, 0]
13
12
  class Storage
14
13
  attr_reader :table
15
14
 
16
15
  def initialize &block
17
16
  @table = []
18
17
  @callback = block || lambda{ |a_, b_|
19
- ARRAY_101.dup.tap do |array|
20
- [*a_].zip([*b_]) do |a, b|
21
- t = a <=> b and array[t] = t
22
- end
23
- end.inject :+
18
+ raise Error.new "comparison vectors are of the different length" unless a_.size == b_.size
19
+ tt = [0, 0, 0]
20
+ [*a_].zip([*b_]) do |a, b|
21
+ t = a <=> b and tt[t] = t
22
+ end
23
+ tt[0] + tt[1] + tt[2]
24
24
  }
25
25
  end
26
26
 
27
27
  def store key, vector = nil
28
28
  raise Error.new "duplicating key" if @table.assoc key
29
29
  key = [NilClass, FalseClass, TrueClass, Numeric, Symbol, Method].any?{ |c| key.is_a? c } ? key : key.dup
30
- vector = if vector.nil?
31
- Array key
32
- else
33
- vector
34
- end
30
+ vector = Array key if vector.nil?
35
31
  score = 0
36
32
  @table.each do |item|
37
- # TODO test of this exception
38
- raise Error.new "comparison vectors are of the different length" unless vector.size == item[1].size
39
33
  point = @callback.call vector, item[1]
40
- score += point
41
34
  item[2] -= point
35
+ score += point
42
36
  end
43
37
  @table.push [key, vector, score]
44
38
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "pcbr"
3
- spec.version = "0.4.0"
3
+ spec.version = "0.4.1"
4
4
  spec.summary = "Pair Comparison Based Rating"
5
5
 
6
6
  spec.author = "Victor Maslov"
@@ -13,6 +13,12 @@ describe "basic specs" do
13
13
  expect(rating.sorted).to eq([2, 1])
14
14
  end
15
15
 
16
+ example "raises if vectors are of the different length" do
17
+ rating = PCBR.new
18
+ rating.store 1, [2]
19
+ expect{ rating.store 3, [4, 5] }.to raise_error PCBR::Error
20
+ end
21
+
16
22
  # example "#size" do
17
23
  # rating = PCBR.new
18
24
  # rating.store 1
@@ -43,6 +49,20 @@ describe "basic specs" do
43
49
  expect(n).to eq(6)
44
50
  end
45
51
 
52
+ example "the vector is not neccessary an Array" do
53
+ rating = PCBR.new do |a, b|
54
+ a <=> b
55
+ end
56
+ 0.class.class_eval do
57
+ def size
58
+ fail
59
+ end
60
+ end
61
+ rating.store 1, 2
62
+ rating.store 2, 1
63
+ expect(rating.sorted).to eq([1, 2])
64
+ end
65
+
46
66
  example "#sorted and #score[key]" do
47
67
  rating = PCBR.new
48
68
  table = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pcbr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-25 00:00:00.000000000 Z
11
+ date: 2018-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler