-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_recommendation.rb
117 lines (116 loc) · 5.44 KB
/
test_recommendation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require 'recommendation'
describe "Test recommendation" do
it "test sim_distance normal" do
rec = Recommendation.new
prefs = {
"斎藤 "=> { "謎解き"=> 4, "相棒"=> 5, "真夏の方程式"=> 4 },
"山田"=> { "謎解き"=> 3, "相棒"=> 4, "真夏の方程式"=> 2, "坂の上から"=> 5 }
}
expect(rec.sim_distance(prefs,"斎藤 ","山田").round(7)).to eq(0.1428571)
end
it "test sim_distance empty" do
rec = Recommendation.new
prefs = {
"斎藤 "=> { "謎解き"=> 4 },
"山田"=> { "相棒"=> 4, }
}
expect(rec.sim_distance prefs,"斎藤 ","山田").to eq(0)
end
it "test sim_distance same score" do
rec = Recommendation.new
prefs = {
"斎藤 "=> { "相棒"=> 4 },
"山田"=> { "相棒"=> 4 }
}
expect(rec.sim_distance prefs,"斎藤 ","山田").to eq(1)
end
it "test sim_pearson normal" do
rec = Recommendation.new
prefs = {
"斎藤 "=> { "謎解き"=> 4, "相棒"=> 5, "真夏の方程式"=> 4 },
"山田"=> { "謎解き"=> 3, "相棒"=> 4, "真夏の方程式"=> 2, "坂の上から"=> 5 }
}
expect(rec.sim_pearson(prefs,"斎藤 ","山田").round(7)).to eq(0.8660254)
end
it "test sim_pearson empty" do
rec = Recommendation.new
prefs = {
"斎藤 "=> { "謎解き"=> 4 },
"山田"=> { "相棒"=> 4, }
}
expect(rec.sim_pearson prefs,"斎藤 ","山田").to eq(0)
end
it "test sim_pearson same score" do
rec = Recommendation.new
prefs = {
"斎藤 "=> { "相棒"=> 4 },
"山田"=> { "相棒"=> 4 }
}
expect(rec.sim_pearson prefs,"斎藤 ","山田").to eq(0)
end
it "test top_maches normal by sim_pearson" do
rec = Recommendation.new
prefs = {
"斎藤"=> { "謎解き"=> 4, "相棒"=> 5, "真夏の方程式"=> 4 },
"山田"=> { "謎解き"=> 3, "相棒"=> 4, "真夏の方程式"=> 2, "坂の上から"=> 5 },
"岡田"=> { "謎解き"=> 5, "相棒"=> 2, "真夏の方程式"=> 4 },
"石川"=> { "謎解き"=> 2, "相棒"=> 4, "真夏の方程式"=> 3 },
"富田"=> { "男はつらいよ"=> 5, "謎解き"=> 5, "相棒"=>1,"真夏の方程式"=> 1 },
"大島"=> { "男はつらいよ"=> 2, "謎解き"=> 3, "相棒"=>5,"真夏の方程式"=> 2 },
"渡辺"=> { "謎解き"=> 4, "相棒"=>3,"真夏の方程式"=> 4,"坂の上から"=>4 }
}
expect(rec.top_matches(prefs, "斎藤",1)).to eq([[0.9449111825230686,"大島"]])
end
it "test sim_pearson same score" do
rec = Recommendation.new
prefs = {
"斎藤" => { "謎解き"=> 4, "相棒"=> 5, "真夏の方程式"=> 4 },
"山田" => { "謎解き"=> 4, "相棒"=> 5, "真夏の方程式"=> 4 }
}
expect(rec.top_matches(prefs, "斎藤",1)).to eq([[1,"山田"]])
end
it "test sim_pearson mismatch score" do
rec = Recommendation.new
prefs = {
"斎藤" => { "謎解き"=> 4 },
"山田" => { "相棒"=> 5 }
}
expect(rec.top_matches(prefs, "斎藤",1)).to eq([[0,"山田"]])
end
it "test sim_pearson another score" do
rec = Recommendation.new
prefs = {
"斎藤" => { "相棒"=> 1 },
"山田" => { "相棒"=> 5 }
}
expect(rec.top_matches(prefs, "斎藤",1)).to eq([[0,"山田"]])
end
it "test top_maches normal by sim_distance" do
rec = Recommendation.new
prefs = {
"斎藤"=> { "謎解き"=> 4, "相棒"=> 5, "真夏の方程式"=> 4 },
"山田"=> { "謎解き"=> 3, "相棒"=> 4, "真夏の方程式"=> 2, "坂の上から"=> 5 },
"岡田"=> { "謎解き"=> 5, "相棒"=> 2, "真夏の方程式"=> 4 },
"石川"=> { "謎解き"=> 2, "相棒"=> 4, "真夏の方程式"=> 3 },
"富田"=> { "男はつらいよ"=> 5, "謎解き"=> 5, "相棒"=>1,"真夏の方程式"=> 1 },
"大島"=> { "男はつらいよ"=> 2, "謎解き"=> 3, "相棒"=>5,"真夏の方程式"=> 2 },
"渡辺"=> { "謎解き"=> 4, "相棒"=>3,"真夏の方程式"=> 4,"坂の上から"=>4 }
}
expect(rec.top_matches(prefs, "斎藤",1,:sim_distance)).to eq([[0.2,"渡辺"]])
end
it "test get_recommendations sample" do
rec = Recommendation.new
prefs = {
"斎藤"=> { "謎解き"=> 4, "相棒"=> 5, "真夏の方程式"=> 4 },
"山田"=> { "謎解き"=> 3, "相棒"=> 4, "真夏の方程式"=> 2, "坂の上から"=> 5 },
"岡田"=> { "謎解き"=> 5, "相棒"=> 2, "真夏の方程式"=> 4 },
"石川"=> { "謎解き"=> 2, "相棒"=> 4, "真夏の方程式"=> 3 },
"富田"=> { "男はつらいよ"=> 5, "謎解き"=> 5, "相棒"=>1,"真夏の方程式"=> 1 },
"大島"=> { "男はつらいよ"=> 2, "謎解き"=> 3, "相棒"=>5,"真夏の方程式"=> 2 },
"渡辺"=> { "謎解き"=> 4, "相棒"=>3,"真夏の方程式"=> 4,"坂の上から"=>4,"男はつらいよ"=>1 }
}
expect(rec.get_recommendations(prefs, "斎藤")).not_to be_empty
expect(rec.get_recommendations(prefs, "山田")).not_to be_empty
expect(rec.get_recommendations(prefs, "渡辺", 1)).to be_empty
end
end