Changeset 8136:718bda796fa3 in orange


Ignore:
Timestamp:
08/02/11 12:30:45 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
b5b98c08e5621f906c0403fd5f387eeae30b885f
Message:

Added tests for distance measures, io, knn, rules, table and variable.
Fixed some other tests.

Files:
7 added
5 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/misc/testing.py

    r8132 r8136  
    471471        prep = cPickle.loads(s) 
    472472         
    473              
     473         
     474from Orange.distance.instances import distance_matrix 
     475from Orange.misc import member_set 
     476 
     477class DistanceTestCase(DataTestCase): 
     478    """ Test orange.ExamplesDistance/Constructor 
     479    """ 
     480    DISTANCE_CONSTRUCTOR = None 
     481     
     482    def setUp(self): 
     483        self.distance_constructor = self.DISTANCE_CONSTRUCTOR 
     484         
     485    @test_on_data 
     486    def test_distance_on(self, dataset): 
     487        import numpy 
     488        indices = orange.MakeRandomIndices2(dataset, min(20, len(dataset))) 
     489        dataset = dataset.select(indices, 0) 
     490        with member_set(self.distance_constructor, "ignore_class", True): 
     491            mat = distance_matrix(dataset, self.distance_constructor) 
     492         
     493        m = numpy.array(list(mat)) 
     494        self.assertTrue((m >= 0.0).all()) 
     495         
     496        if dataset.domain.class_var: 
     497            with member_set(self.distance_constructor, "ignore_class", False): 
     498                mat = distance_matrix(dataset, self.distance_constructor) 
     499            m1 = numpy.array(list(mat)) 
     500            self.assertTrue((m1 != m).all() or dataset, "%r does not seem to respect the 'ignore_class' flag") 
     501         
    474502def test_case_script(path): 
    475503    """ Return a TestCase instance from a script in `path`. 
  • testing/unittests/tests/test_bayes.py

    r8042 r8136  
    22 
    33# TODO: test different prob estimators 
    4 @testing.datasets_driven(testing.CLASSIFICATION_DATASETS) 
     4@testing.datasets_driven(datasets=testing.CLASSIFICATION_DATASETS) 
    55class TestNaiveBayes(testing.LearnerTestCase):     
    66    def setUp(self): 
  • testing/unittests/tests/test_ensemble.py

    r8042 r8136  
    1212        testing.LearnerTestCase.test_pickling_on(self, dataset) 
    1313         
    14 @datasets_driven 
     14@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS +\ 
     15                 testing.REGRESSION_DATASETS) 
    1516class TestBagging(testing.LearnerTestCase): 
    1617    def setUp(self):  
     
    2223        testing.LearnerTestCase.test_pickling_on(self, dataset) 
    2324 
    24 @datasets_driven 
    25 class TestRandomForest(testing.LearnerTestCase):     
     25@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS) 
     26class TestRandomForest(testing.LearnerTestCase): 
    2627    def setUp(self):  
    2728        import orngEnsemble, orngTree 
  • testing/unittests/tests/test_hclustering.py

    r8042 r8136  
    44                            
    55from Orange.clustering.kmeans import Clustering 
    6 from Orange.distances import * 
     6from Orange.distance.instances import * 
    77                            
    88import Orange.misc.testing as testing 
  • testing/unittests/tests/test_svm.py

    r8042 r8136  
    22from Orange.classification.svm.kernels import BagOfWords, RBFKernelWrapper 
    33from Orange.misc import testing 
    4 from Orange.misc.testing import datasets_driven, test_on_datasets 
     4from Orange.misc.testing import datasets_driven, test_on_datasets, test_on_data 
    55import orange 
    66 
     
    3636    LEARNER = SVMLearner 
    3737     
    38     @test_on_datasets(datasets=datasets) 
     38    @test_on_data 
    3939    def test_learner_on(self, data): 
    4040        """ Test custom kernel wrapper 
     
    4747     
    4848     
    49 @datasets_driven(datasets=datasets) 
     49@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS) 
    5050class TestLinLearner(testing.LearnerTestCase): 
    5151    LEARNER = LinearLearner 
     
    5757 
    5858 
    59 @datasets_driven(datasets=datasets) 
     59@datasets_driven(datasets=["iris"]) 
    6060class TestRFE(testing.DataTestCase): 
    61     @datasets_driven 
     61    @test_on_data 
    6262    def test_rfe_on(self, data): 
    6363        rfe = RFE() 
Note: See TracChangeset for help on using the changeset viewer.