pcbr 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pcbr.rb +6 -11
  3. data/spec/_spec.rb +15 -24
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c9c0f6e6ebf91facae8f193b2d990e14d8ebda2
4
- data.tar.gz: df06fdbfd408a51c0dd698c1086456fb7b39dcca
3
+ metadata.gz: e17564130abbbb6ebddcf3a3302c5d1ab617f8a0
4
+ data.tar.gz: 6ba30f3821a168a951938aaf6d31671a1b632076
5
5
  SHA512:
6
- metadata.gz: ece51e1255f4eb3e530206ec05aa9775d62853acad02179003237ea72f1905a5006f7a23195a1d43d0c0c357cd15ff8c852f2ec42168155d158a633f91a82e11
7
- data.tar.gz: bfed2b1d0a291bdfc4e6301031f76a5182c9cf014aa58b9a4087c67f99424b89f88d61ce56431d47d6ee4950cbfbb81ec83a6853012169b448298fb49b92373d
6
+ metadata.gz: ce0bfae1f4db6f52806437cf2821b1e5325e6557de69e119829361c1f354eef205877a7f2a83fa220a31e4bbf777beae8db327f8304defd517d9415a22f7fc3b
7
+ data.tar.gz: 259c292b880fa28991baaa4359f3331b8e8683d61656eee4549ee12d62a65612433e936eadf512c1db4d844e0192508812e84f98a7ccda1fefc505d554a74fad
data/lib/pcbr.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  class PCBR
2
2
 
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
+
5
+ attr_reader :table
4
6
 
5
7
  def initialize &block
6
8
  @table = []
7
9
  @callback = block || ->*_{[*_[0]]}
8
10
  end
9
11
 
10
- def size
11
- @table.size
12
- end
12
+ # def size
13
+ # @table.size
14
+ # end
13
15
 
14
16
  def store key, *vector
15
17
  vector = vector.empty? ? [key] : vector.first
@@ -32,11 +34,4 @@ class PCBR
32
34
  @table.sort_by.with_index{ |item, i| [-item.last, i] }.map(&:first)
33
35
  end
34
36
 
35
- def data
36
- Hash[ @table.map{ |key, vector, score| [key, vector] } ]
37
- end
38
- def scores
39
- Hash[ @table.map{ |key, vector, score| [key, score] } ]
40
- end
41
-
42
37
  end
data/spec/_spec.rb CHANGED
@@ -2,40 +2,31 @@ require_relative "../lib/pcbr"
2
2
 
3
3
  describe "basic specs" do
4
4
 
5
- example "#size" do
5
+ example "#size", skip: :deprecated do
6
6
  rating = PCBR.new
7
7
  rating.store 1
8
8
  rating.store 2
9
9
  expect(rating.size).to eq(2)
10
10
  end
11
11
 
12
- example "order, #score[key] and main methods" do
12
+ example "order and methods: #score[key], #sorted, #data" do
13
13
  rating = PCBR.new
14
- data = {
15
- 1 => [1, 1],
16
- 2 => [2, 2],
17
- 3 => [0, 0],
18
- 4 => [1, 2],
19
- 6 => [1, 1],
20
- 5 => [0, 2],
21
- }.each do |key, vector|
14
+ table = [
15
+ [1, [1, 1], -1],
16
+ [2, [2, 2], 5],
17
+ [3, [0, 0], -5],
18
+ [4, [1, 2], 3],
19
+ [6, [1, 1], -1],
20
+ [5, [0, 2], -1],
21
+ ].each do |key, vector, |
22
22
  rating.store key, vector
23
23
  end
24
- expectation = {
25
- 2 => 5,
26
- 4 => 3,
27
- 1 => -1,
28
- 6 => -1,
29
- 5 => -1,
30
- 3 => -5,
31
- }.each do |item, score|
32
- expect(rating.score(item)).to eq(score)
33
- end
34
- aggregate_failures do
35
- expect(rating.sorted).to eq(expectation.keys)
36
- expect(rating.scores).to eq(expectation )
37
- expect(rating.data ).to eq(data )
24
+ expect(rating.sorted).to eq([2, 4, 1, 6, 5, 3])
25
+ expect(rating.table.map(&:last).inject(:+)).to be_zero
26
+ table.each do |key, _, score|
27
+ expect(rating.score(key)).to eq(score)
38
28
  end
29
+ expect(rating.table ).to eq(table)
39
30
  end
40
31
 
41
32
  example "&block" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pcbr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov