from learning import parse_csv, weighted_mode, weighted_replicate, DataSet, \
                     PluralityLearner, NaiveBayesLearner, NearestNeighborLearner
from utils import DataFile


def test_parse_csv():
    Iris = DataFile('iris.csv').read()
    assert parse_csv(Iris)[0] == [5.1, 3.5, 1.4, 0.2, 'setosa']


def test_weighted_mode():
    assert weighted_mode('abbaa', [1, 2, 3, 1, 2]) == 'b'


def test_weighted_replicate():
    assert weighted_replicate('ABC', [1, 2, 1], 4) == ['A', 'B', 'B', 'C']


def test_plurality_learner():
    zoo = DataSet(name="zoo")

    pL = PluralityLearner(zoo)
    assert pL([]) == "mammal"


def test_naive_bayes():
    iris = DataSet(name="iris")

    nB = NaiveBayesLearner(iris)
    assert nB([5, 3, 1, 0.1]) == "setosa"


def test_k_nearest_neighbors():
    iris = DataSet(name="iris")

    kNN = NearestNeighborLearner(iris, k=3)
    assert kNN([5, 3, 1, 0.1]) == "setosa"

@@ -151,17 +151,98 @@
 rLearner
+, %5C%0A                     NeuralNetLearner, PerceptronLearner, DecisionTreeLearner
 %0A
-
 from uti
@@ -262,16 +262,17 @@
 aFile%0A%0A%0A
+%0A
 def test
@@ -366,24 +366,20 @@
 5.1,
- 
 3.5,
- 
 1.4,
- 
 0.2,
- 
 'set
@@ -687,16 +687,62 @@
 ert pL(%5B
+1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1
 %5D) == %22m
@@ -853,31 +853,28 @@
 ssert nB(%5B5,
- 
 3,
- 
 1,
- 
 0.1%5D) == %22se
@@ -984,17 +984,16 @@
 er(iris,
- 
 k=3)%0A   
@@ -1011,29 +1011,796 @@
 (%5B5,
- 3, 1, 0.1%5D) == %22setosa%22
+3,1,0.1%5D) == %22setosa%22%0A%0Adef test_decision_tree_learner():%0A    iris = DataSet(name=%22iris%22)%0A%0A    dTL = DecisionTreeLearner(iris)%0A    assert dTL(%5B5,3,1,0.1%5D) == %22setosa%22%0A%0A%0Adef test_neural_network_learner():%0A    iris = DataSet(name=%22iris%22)%0A    classes = %5B%22setosa%22,%22versicolor%22,%22virginica%22%5D%0A%0A    iris.classes_to_numbers()%0A%0A    nNL = NeuralNetLearner(iris)%0A    # NeuralNetLearner might be wrong. Just check if prediction is in range%0A    assert nNL(%5B5,3,1,0.1%5D) in range(len(classes))%0A%0A%0Adef test_perceptron():%0A    iris = DataSet(name=%22iris%22)%0A    classes = %5B%22setosa%22,%22versicolor%22,%22virginica%22%5D%0A%0A    iris.classes_to_numbers()%0A%0A    perceptron = PerceptronLearner(iris)%0A    # PerceptronLearner might be wrong. Just check if prediction is in range%0A    assert perceptron(%5B5,3,1,0.1%5D) in range(len(classes))
 %0A

Update test_learning.py (#376)