34 lines
970 B
Python
34 lines
970 B
Python
"""Tests for preset comparison."""
|
|
|
|
import os
|
|
import sys
|
|
import unittest
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, os.path.join(ROOT, "tools"))
|
|
|
|
import compare_presets
|
|
|
|
|
|
class CompareTests(unittest.TestCase):
|
|
def game(self, appid):
|
|
return {"appid": appid, "name": f"Game {appid}", "score": 1.0}
|
|
|
|
def test_compare_lists(self):
|
|
result = compare_presets.compare_lists(
|
|
[self.game(1), self.game(2), self.game(3)],
|
|
[self.game(2), self.game(3), self.game(4)])
|
|
self.assertEqual(result["common"], [2, 3])
|
|
self.assertEqual(result["only_a"], [1])
|
|
self.assertEqual(result["only_b"], [4])
|
|
self.assertEqual(result["jaccard"], 0.5)
|
|
|
|
def test_empty(self):
|
|
result = compare_presets.compare_lists([], [])
|
|
self.assertEqual(result["jaccard"], 0.0)
|
|
self.assertEqual(result["common"], [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|