instance_test.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. from federatedml.feature.instance import Instance
  18. class TestInstance(unittest.TestCase):
  19. def setUp(self):
  20. pass
  21. def test_instance(self):
  22. inst = Instance(inst_id=5, weight=2.0, features=[1, 2, 3], label=-5)
  23. self.assertTrue(inst.inst_id == 5 and abs(inst.weight - 2.0) < 1e-8
  24. and inst.features == [1, 2, 3] and inst.label == -5)
  25. inst.set_weight(3)
  26. inst.set_label(5)
  27. inst.set_feature(["yes", "no"])
  28. self.assertTrue(inst.weight == 3 and inst.label == 5 and inst.features == ["yes", "no"])
  29. if __name__ == '__main__':
  30. unittest.main()