summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_parameters.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/test_parameters.py b/test/test_parameters.py
new file mode 100644
index 0000000..a466d91
--- /dev/null
+++ b/test/test_parameters.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+
+from dfatool import dfatool as dt
+from dfatool import parameters
+from dfatool.utils import by_name_to_by_param
+import unittest
+
+import numpy as np
+
+
+class TestModels(unittest.TestCase):
+ def test_distinct_param_values(self):
+ X = np.arange(35)
+ by_name = {
+ "TX": {
+ "param": [(x % 5, x % 7) for x in X],
+ "power": X,
+ "attributes": ["power"],
+ }
+ }
+ self.assertEqual(
+ parameters.distinct_param_values(by_name, "TX"),
+ [list(range(5)), list(range(7))],
+ )
+
+ def test_parameter_detection_linear(self):
+ rng = np.random.default_rng()
+ X = np.arange(200) % 50
+ Y = X + rng.normal(size=X.size)
+ by_name = {
+ "TX": {
+ "param": [(x % 5, x) for x in X],
+ "power": Y,
+ "attributes": ["power"],
+ }
+ }
+ by_param = by_name_to_by_param(by_name)
+ stats = parameters.ParamStats(by_name, by_param, ["p_mod5", "p_linear"], dict())
+
+ self.assertEqual(stats.depends_on_param("TX", "power", "p_mod5"), False)
+ self.assertEqual(stats.depends_on_param("TX", "power", "p_linear"), True)
+
+ paramfit = dt.ParallelParamFit(by_param)
+ paramfit.enqueue("TX", "power", 1, "p_linear")
+ paramfit.fit()
+
+ fit_result = dt.get_fit_result(paramfit.results, "TX", "power")
+ self.assertEqual(fit_result["p_linear"]["best"], "linear")
+
+
+if __name__ == "__main__":
+ unittest.main()