pcbr 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pcbr.rb +6 -11
- data/spec/_spec.rb +15 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e17564130abbbb6ebddcf3a3302c5d1ab617f8a0
|
4
|
+
data.tar.gz: 6ba30f3821a168a951938aaf6d31671a1b632076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
12
|
+
example "order and methods: #score[key], #sorted, #data" do
|
13
13
|
rating = PCBR.new
|
14
|
-
|
15
|
-
1
|
16
|
-
2
|
17
|
-
3
|
18
|
-
4
|
19
|
-
6
|
20
|
-
5
|
21
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|