feature_imputation_test.py 1006 B

123456789101112131415161718192021222324252627282930313233343536
  1. import numpy as np
  2. import unittest
  3. from federatedml.feature.feature_imputation import load_value_to_type
  4. class TestFeatureImputation(unittest.TestCase):
  5. def test_load_value_to_type(self):
  6. true_v = None
  7. v_type = "None"
  8. str_v = None
  9. self.assertEqual(true_v, load_value_to_type(str_v, v_type))
  10. true_v = 42
  11. v_type = type(true_v).__name__
  12. str_v = "42"
  13. self.assertEqual(true_v, load_value_to_type(str_v, v_type))
  14. true_v = "42.0"
  15. v_type = type(true_v).__name__
  16. str_v = "42.0"
  17. self.assertEqual(true_v, load_value_to_type(str_v, v_type))
  18. true_v = 42.42
  19. v_type = type(true_v).__name__
  20. str_v = "42.42"
  21. self.assertEqual(true_v, load_value_to_type(str_v, v_type))
  22. true_v = np.array([42, 2, 3])[0]
  23. v_type = type(true_v).__name__
  24. str_v = 42
  25. self.assertEqual(true_v, load_value_to_type(str_v, v_type))
  26. if __name__ == "__main__":
  27. unittest.main()