intersection_guest_test.py 2.1 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. from federatedml.secureprotol.hash.hash_factory import Hash
  21. class TestRsaIntersectGuest(unittest.TestCase):
  22. def setUp(self):
  23. self.jobid = str(uuid.uuid1())
  24. session.init(self.jobid)
  25. from federatedml.statistic.intersect import RsaIntersectionGuest
  26. from federatedml.statistic.intersect import RsaIntersect
  27. intersect_param = IntersectParam()
  28. self.rsa_operator = RsaIntersectionGuest()
  29. self.rsa_operator.load_params(intersect_param)
  30. self.rsa_op2 = RsaIntersect()
  31. self.rsa_op2.load_params(intersect_param)
  32. def data_to_table(self, data):
  33. return session.parallelize(data, include_key=True, partition=2)
  34. def test_func_map_raw_id_to_encrypt_id(self):
  35. d1 = [("a", 1), ("b", 2), ("c", 3)]
  36. d2 = [(4, "a"), (5, "b"), (6, "c")]
  37. D1 = self.data_to_table(d1)
  38. D2 = self.data_to_table(d2)
  39. res = self.rsa_operator.map_raw_id_to_encrypt_id(D1, D2)
  40. gt = [(4, None), (5, None), (6, None)]
  41. self.assertListEqual(list(res.collect()), gt)
  42. def test_hash(self):
  43. hash_operator = Hash("sha256")
  44. res = str(self.rsa_op2.hash("1", hash_operator))
  45. self.assertEqual(res, "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b")
  46. def tearDown(self):
  47. session.stop()
  48. if __name__ == "__main__":
  49. unittest.main()