From cd5c63f8b622cf4e56cb176acd3b43706c06dca8 Mon Sep 17 00:00:00 2001 From: Trung-Hoang Le Date: Thu, 23 May 2024 00:54:34 +0800 Subject: [PATCH] Fix failed test case due to different ordering caused by identical scores (#622) --- tests/cornac/models/test_recommender.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/cornac/models/test_recommender.py b/tests/cornac/models/test_recommender.py index d29b05a3..2006064a 100644 --- a/tests/cornac/models/test_recommender.py +++ b/tests/cornac/models/test_recommender.py @@ -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 @@ -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]).all()) # 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]).all()) # identical scores, sorting may affect the ordering if __name__ == "__main__":