intersection_host_test.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import unittest
  17. import uuid
  18. from fate_arch.session import computing_session as session
  19. from federatedml.param.intersect_param import IntersectParam
  20. class TestRsaIntersectHost(unittest.TestCase):
  21. def setUp(self):
  22. self.jobid = str(uuid.uuid1())
  23. session.init(self.jobid)
  24. from federatedml.statistic.intersect import RsaIntersectionHost
  25. from federatedml.statistic.intersect import RawIntersectionHost
  26. intersect_param = IntersectParam()
  27. self.rsa_operator = RsaIntersectionHost()
  28. self.rsa_operator.load_params(intersect_param)
  29. self.raw_operator = RawIntersectionHost()
  30. self.raw_operator.load_params(intersect_param)
  31. def data_to_table(self, data):
  32. return session.parallelize(data, include_key=True, partition=2)
  33. def test_func_generate_rsa_key(self):
  34. res = self.rsa_operator.generate_rsa_key(1024)
  35. self.assertEqual(65537, res[0])
  36. def test_get_common_intersection(self):
  37. d1 = [(1, "a"), (2, "b"), (4, "c")]
  38. d2 = [(4, "a"), (5, "b"), (6, "c")]
  39. d3 = [(4, "a"), (5, "b"), (7, "c")]
  40. D1 = self.data_to_table(d1)
  41. D2 = self.data_to_table(d2)
  42. D3 = self.data_to_table(d3)
  43. res = self.raw_operator.get_common_intersection([D1, D2, D3])
  44. gt = [(4, None)]
  45. self.assertListEqual(list(res.collect()), gt)
  46. def tearDown(self):
  47. session.stop()
  48. if __name__ == "__main__":
  49. unittest.main()