Skip to content

Commit cd5c63f

Browse files
authored
Fix failed test case due to different ordering caused by identical scores (#622)
1 parent 55e7f2e commit cd5c63f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tests/cornac/models/test_recommender.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import unittest
1717

18+
import numpy as np
19+
1820
from cornac.data import BasketDataset, Dataset, SequentialDataset, Reader
1921
from cornac.models import MF, GPTop, SPop, NextBasketRecommender, NextItemRecommender
2022

@@ -85,7 +87,10 @@ def test_fit(self):
8587
model.fit(dataset)
8688
model.score(0, [])
8789
result = model.rank(0, history_items=[])
88-
self.assertTrue((result[0] == [3, 2, 4, 1, 0, 5, 8, 7, 6]).all())
90+
self.assertTrue((result[0][0:3] == [3, 2, 4]).all())
91+
self.assertTrue((np.sort(result[0][3:5]) == [0, 1]).all()) # identical scores, sorting may affect the ordering
92+
self.assertTrue((result[0][5:6] == [5]).all())
93+
self.assertTrue((np.sort(result[0][6:9]) == [6, 7, 8]).all()) # identical scores, sorting may affect the ordering
8994

9095

9196
if __name__ == "__main__":

0 commit comments

Comments
 (0)