From 43f24cd81d068ccf2e3d594926266cb362060a15 Mon Sep 17 00:00:00 2001 From: Ajda Date: Fri, 22 Mar 2024 13:28:51 +0100 Subject: [PATCH] Word Cloud: test document count output --- .../text/widgets/tests/test_owwordcloud.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/orangecontrib/text/widgets/tests/test_owwordcloud.py b/orangecontrib/text/widgets/tests/test_owwordcloud.py index 03f846089..d20dfd821 100644 --- a/orangecontrib/text/widgets/tests/test_owwordcloud.py +++ b/orangecontrib/text/widgets/tests/test_owwordcloud.py @@ -69,7 +69,8 @@ def test_bow_features(self): np.testing.assert_array_almost_equal(weights, [1, 2, 2]) output = self.get_output(self.widget.Outputs.word_counts) - np.testing.assert_array_almost_equal([2, 2, 1], output.X.flatten()) + np.testing.assert_array_almost_equal([2, 2, 1], output.X[:, + 0].flatten()) np.testing.assert_array_equal( ["Word3", "Word2", "Word1"], output.metas.flatten()) self.assertTupleEqual( @@ -93,7 +94,7 @@ def test_bow_features(self): np.testing.assert_array_almost_equal(weights, [1, 2]) output = self.get_output(self.widget.Outputs.word_counts) - np.testing.assert_array_almost_equal([2, 1], output.X.flatten()) + np.testing.assert_array_almost_equal([2, 1], output.X[:, 0].flatten()) np.testing.assert_array_equal( ["Word2", "Word1"], output.metas.flatten()) self.assertTupleEqual( @@ -168,6 +169,14 @@ def test_select_words_output(self): self.assertEqual(2, len(output)) self.assertEqual("words", output.domain["Words"].attributes["type"]) + def test_word_counts_output(self): + self.send_signal(self.widget.Inputs.corpus, self.corpus) + output = self.get_output(self.widget.Outputs.word_counts) + words = set(w for doc in list(self.corpus.ngrams) for w in doc) + self.assertEqual(len(words), len(output)) + self.assertLessEqual(output.X[:, 1][0], len(self.corpus)) + self.assertEqual(len(output.domain), 3) + if __name__ == "__main__": unittest.main()