source: orange/Orange/testing/unit/tests/test_knn.py @ 10278:f3b1ffae9c29

Revision 10278:f3b1ffae9c29, 771 bytes checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Unittest2 for python 2.6.

Line 
1try:
2    import unittest2 as unittest
3except:
4    import unittest
5import Orange
6from Orange.misc import testing
7from Orange.misc.testing import datasets_driven, test_on_data
8from Orange.classification import knn
9from Orange.distance import Euclidean
10
11
12@testing.datasets_driven(datasets=testing.CLASSIFICATION_DATASETS + \
13                         testing.REGRESSION_DATASETS)
14class TestKNNLearner(testing.LearnerTestCase):
15    def setUp(self):
16        self.learner = knn.kNNLearner(distance_constructor=Euclidean())
17
18    @testing.test_on_data
19    def test_learner_on(self, dataset):
20        testing.LearnerTestCase.test_learner_on(self, dataset)
21        instance = dataset.random_instance()
22        self.assertEqual(len(self.classifier.find_nearest(3, instance)), 3)
23
24
25
26
Note: See TracBrowser for help on using the repository browser.