Exemple #1
0
  def testCreateFromString(self, ceptMock):
    term = Term()
    term = term.createFromString("fox")

    # Check that our mock object was called
    ceptMock.assert_called_with("fox")

    # Check that we have a Term type
    self.assertIsInstance(term, Term)
  def test_createFromString(self):
    # Test enablePlaceholder
    term = Term().createFromString("thisisaninvalidterm", enablePlaceholder=False)
    self.assertEqual(sum(term.toArray()), 0)

    term = Term().createFromString("thisisaninvalidterm", enablePlaceholder=True)
    self.assertGreater(sum(term.toArray()), 0)
    self.assertGreater(term.sparsity, 0)
    placeholder = term.bitmap

    # Make sure we get the same placeholder back for the same term
    term = Term().createFromString("thisisaninvalidterm", enablePlaceholder=True)
    self.assertEqual(term.bitmap, placeholder)

    # Make sure we get a different placeholder back for a different term
    term = Term().createFromString("differentinvalidterm", enablePlaceholder=True)
    self.assertNotEqual(term.bitmap, placeholder)