|
| 1 | +import unittest |
| 2 | +from unittest.mock import Mock |
| 3 | + |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +from Orange.data import Domain, Table, DiscreteVariable, ContinuousVariable |
| 7 | +from Orange.preprocess import fss |
| 8 | + |
| 9 | + |
| 10 | +class SelectBestFeaturesTest(unittest.TestCase): |
| 11 | + def test_no_nice_features(self): |
| 12 | + method = Mock() |
| 13 | + method.feature_type = DiscreteVariable |
| 14 | + selector = fss.SelectBestFeatures(method, 5) |
| 15 | + |
| 16 | + domain = Domain([]) |
| 17 | + data = Table.from_numpy(domain, np.zeros((100, 0))) |
| 18 | + selection = selector.score_only_nice_features(data, method) |
| 19 | + self.assertEqual(selection.size, 0) |
| 20 | + method.assert_not_called() |
| 21 | + |
| 22 | + domain = Domain([ContinuousVariable("x")]) |
| 23 | + data = Table.from_numpy(domain, np.zeros((100, 1))) |
| 24 | + selector.decreasing = True |
| 25 | + selection = selector.score_only_nice_features(data, method) |
| 26 | + np.testing.assert_equal(selection, [float('-inf')]) |
| 27 | + method.assert_not_called() |
| 28 | + |
| 29 | + selector.decreasing = False |
| 30 | + selection = selector.score_only_nice_features(data, method) |
| 31 | + np.testing.assert_equal(selection, [float('inf')]) |
| 32 | + method.assert_not_called() |
| 33 | + |
| 34 | + |
| 35 | +if __name__ == "__main__": |
| 36 | + unittest.main() |
0 commit comments