simple_recommender 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_recommender/recommendable.rb +33 -42
- data/lib/simple_recommender/version.rb +1 -1
- data/test/dummy/app/models/book.rb +3 -1
- data/test/dummy/log/test.log +1037 -0
- data/test/dummy/test/models/book_test.rb +2 -51
- metadata +2 -2
@@ -3,63 +3,14 @@ require 'test_helper'
|
|
3
3
|
class BookTest < ActiveSupport::TestCase
|
4
4
|
describe BookTest do
|
5
5
|
|
6
|
-
describe "#similar_by" do
|
7
|
-
let(:book) { Book.first }
|
8
|
-
|
9
|
-
it "returns a result for a has_many through association" do
|
10
|
-
assert book.similar_by(:users)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns a result for a has_and_belongs_to_many association" do
|
14
|
-
assert book.similar_by(:tags)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "raises an ArgumentError for an invalid association type" do
|
18
|
-
assert_raises ArgumentError do
|
19
|
-
book.similar_by(:author)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "convenience methods" do
|
25
|
-
it "defines a convenience method for a has_and_belongs_to_many association" do
|
26
|
-
assert_equal true, Book.first.respond_to?(:similar_by_tags)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "defines a convenience method for a has_many through association" do
|
30
|
-
assert_equal true, Book.first.respond_to?(:similar_by_users)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "does not define a convenience method for an invalid association type" do
|
34
|
-
assert_equal false, Book.first.respond_to?(:similar_by_authors)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
6
|
let(:python_book) { Book.find_by(name: "Learning Python") }
|
39
7
|
let(:ruby_book) { Book.find_by(name: "Learning Ruby") }
|
40
8
|
let(:cpp_book) { Book.find_by(name: "Learning C++") }
|
41
9
|
let(:violin_book) { Book.find_by(name: "Playing Violin") }
|
42
10
|
|
43
|
-
describe "#
|
44
|
-
let(:n_results) { 3 }
|
45
|
-
subject { python_book.similar_by_tags(n_results: n_results) }
|
46
|
-
|
47
|
-
it "returns similar books" do
|
48
|
-
assert_equal [ruby_book, cpp_book, violin_book], subject
|
49
|
-
end
|
50
|
-
|
51
|
-
it "returns similarity scores" do
|
52
|
-
expected_similarities = [1.0, (2.0/3), (1.0/4)]
|
53
|
-
|
54
|
-
expected_similarities.zip(subject.map(&:similarity)).each do |expected, actual|
|
55
|
-
assert_in_delta expected, actual, 0.01
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "#similar_by_users" do
|
11
|
+
describe "#similar_items" do
|
61
12
|
let(:n_results) { 3 }
|
62
|
-
subject { python_book.
|
13
|
+
subject { python_book.similar_items(n_results: n_results) }
|
63
14
|
|
64
15
|
it "returns similar books" do
|
65
16
|
assert_equal [ruby_book, cpp_book, violin_book], subject
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_recommender
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoffrey Litt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|