You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_instance.py 1.1 kB

1234567891011121314151617181920212223242526272829303132333435
  1. import unittest
  2. from fastNLP import Instance
  3. class TestCase(unittest.TestCase):
  4. def test_init(self):
  5. fields = {"x": [1, 2, 3], "y": [4, 5, 6]}
  6. ins = Instance(x=[1, 2, 3], y=[4, 5, 6])
  7. self.assertTrue(isinstance(ins.fields, dict))
  8. self.assertEqual(ins.fields, fields)
  9. ins = Instance(**fields)
  10. self.assertEqual(ins.fields, fields)
  11. def test_add_field(self):
  12. fields = {"x": [1, 2, 3], "y": [4, 5, 6]}
  13. ins = Instance(**fields)
  14. ins.add_field("z", [1, 1, 1])
  15. fields.update({"z": [1, 1, 1]})
  16. self.assertEqual(ins.fields, fields)
  17. def test_get_item(self):
  18. fields = {"x": [1, 2, 3], "y": [4, 5, 6], "z": [1, 1, 1]}
  19. ins = Instance(**fields)
  20. self.assertEqual(ins["x"], [1, 2, 3])
  21. self.assertEqual(ins["y"], [4, 5, 6])
  22. self.assertEqual(ins["z"], [1, 1, 1])
  23. def test_repr(self):
  24. fields = {"x": [1, 2, 3], "y": [4, 5, 6], "z": [1, 1, 1]}
  25. ins = Instance(**fields)
  26. # simple print, that is enough.
  27. print(ins)