From 6f7b694bbaf8352a4ffdece938644fdc6d4bbf09 Mon Sep 17 00:00:00 2001 From: Michael Ekstrand Date: Fri, 16 Feb 2024 16:12:07 -0500 Subject: [PATCH] test the util.clone() method --- tests/test_bias.py | 16 ++++++++++++++++ tests/test_util.py | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/test_bias.py b/tests/test_bias.py index 50af8106a..cde6084f4 100644 --- a/tests/test_bias.py +++ b/tests/test_bias.py @@ -69,6 +69,22 @@ def test_bias_clone(): assert getattr(a2, "user_offsets_", None) is None +def test_bias_clone_damping(): + algo = Bias(damping=(10, 5)) + algo.fit(simple_df) + + params = algo.get_params() + assert sorted(params.keys()) == ["damping", "items", "users"] + + a2 = lku.clone(algo) + assert a2 is not algo + assert getattr(a2, "item_damping", None) == 5 + assert getattr(a2, "user_damping", None) == 10 + assert getattr(a2, "mean_", None) is None + assert getattr(a2, "item_offsets_", None) is None + assert getattr(a2, "user_offsets_", None) is None + + def test_bias_global_only(): algo = Bias(users=False, items=False) algo.fit(simple_df) diff --git a/tests/test_util.py b/tests/test_util.py index 18bf34630..49e738f60 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -10,6 +10,8 @@ import numpy as np import pandas as pd +from hypothesis import given +from hypothesis import strategies as st from lenskit import util as lku @@ -80,3 +82,18 @@ def func(foo): assert len(history) == 1 cache("bar") assert len(history) == 2 + + +@given( + st.one_of( + st.lists(st.floats(allow_nan=False)), + st.tuples(st.floats(allow_nan=False)), + st.integers(), + st.floats(allow_nan=False), + st.emails(), + ) +) +def test_clone_core_obj(obj): + o2 = lku.clone(obj) + assert o2 == obj + assert type(o2) == type(obj)