-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.coffee
104 lines (89 loc) · 2.52 KB
/
tests.coffee
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
test "Test rating parser", ()->
rating_text = """
All of LVB's rankings at Criticker.com
100 Battlestar Galactica (2003)
http://www.criticker.com/film/Battlestar_Galactica_2003/rating/LVB
88 Borat: Cultural Learnings of America for Make Benefit Glorious Nation of Kazakhstan (2006)
http://www.criticker.com/film/Borat_Cultural_Learnings_of_America/rating/LVB
80 Big (1988)
http://www.criticker.com/film/Big/rating/LVB
12 shouldn't be found
http://www.criticker.com/film/Big/rating/LVB
44.3 Bogus, but handle it
0 Zero
-10 This should get ignored
100 The Bourne Identity (2002)
http://www.criticker.com/film/The_Bourne_Identity_2002/rating/LVB
"""
ratings = parse_ratings(rating_text)
deepEqual ratings, [100,88,80,44,0,100]
test "Ranges", ()->
active_config = configs[0]
ratings = [-1,0,1,9,10,11,20,40,80,89,90,91,99,100,101]
deepEqual(stratify(ratings, active_config), ([
["0-10",4],
["11-20",2],
["21-30",0],
["31-40",1],
["41-50",0],
["51-60",0],
["61-70",0],
["71-80",1],
["81-90",2],
["91-100",3] ]))
shuf_ratings = _.shuffle(ratings)
deepEqual(stratify(shuf_ratings, active_config), ([
["0-10",4],
["11-20",2],
["21-30",0],
["31-40",1],
["41-50",0],
["51-60",0],
["61-70",0],
["71-80",1],
["81-90",2],
["91-100",3] ]))
test "Continuous Buckets", ()->
active_config = configs[2]
ratings = [-1,0,1,1,3,5,6,6,6,8,10,11]
deepEqual(stratify(ratings, active_config), ([
["0",1],
["1",2],
["2",0],
["3",1],
["4",0],
["5",1],
["6",3],
["7",0],
["8",1],
["9",0],
["10",1] ]))
shuf_ratings = _.shuffle(ratings)
deepEqual(stratify(shuf_ratings, active_config), ([
["0",1],
["1",2],
["2",0],
["3",1],
["4",0],
["5",1],
["6",3],
["7",0],
["8",1],
["9",0],
["10",1] ]))
test "Discrete Buckets", ()->
active_config = configs[4]
ratings = [-25,-1,0,0,25,25,25,75,100,100,100,101,125]
deepEqual(stratify(ratings, active_config), ([
["0",2],
["25",3],
["50",0],
["75",1],
["100",3] ]))
shuf_ratings = _.shuffle(ratings)
deepEqual(stratify(shuf_ratings, active_config), ([
["0",2],
["25",3],
["50",0],
["75",1],
["100",3] ]))