Skip to content

Commit

Permalink
The test case pass for vary ordering due to identical scores
Browse files Browse the repository at this point in the history
  • Loading branch information
lthoang committed May 21, 2024
1 parent 55e7f2e commit eb16fcf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/cornac/models/test_recommender.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import unittest

import numpy as np

from cornac.data import BasketDataset, Dataset, SequentialDataset, Reader
from cornac.models import MF, GPTop, SPop, NextBasketRecommender, NextItemRecommender

Expand Down Expand Up @@ -85,7 +87,10 @@ def test_fit(self):
model.fit(dataset)
model.score(0, [])
result = model.rank(0, history_items=[])
self.assertTrue((result[0] == [3, 2, 4, 1, 0, 5, 8, 7, 6]).all())
self.assertTrue((result[0][0:3] == [3, 2, 4]).all())
self.assertTrue((np.sort(result[0][3:5]) == [0, 1]).any()) # identical scores, sorting may affect the ordering
self.assertTrue((result[0][5:6] == [5]).all())
self.assertTrue((np.sort(result[0][6:9]) == [6, 7, 8]).any()) # identical scores, sorting may affect the ordering


if __name__ == "__main__":
Expand Down

0 comments on commit eb16fcf

Please sign in to comment.