Skip to content

Commit

Permalink
test the util.clone() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed Mar 3, 2024
1 parent 29d1d0e commit 6f7b694
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 6f7b694

Please sign in to comment.