Skip to content

Commit ce7aa26

Browse files
antmarakisnorvig
authored andcommitted
Add new tests (aimacode#314)
- Added tests for PluralityLearner, NaiveBayes and kNN algorithms - Replace parse_csv with non-trivial input
1 parent 1356ab9 commit ce7aa26

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tests/test_learning.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import pytest
2-
from learning import parse_csv, weighted_mode, weighted_replicate
2+
from learning import parse_csv, weighted_mode, weighted_replicate, DataSet, \
3+
PluralityLearner, NaiveBayesLearner, NearestNeighborLearner
4+
from utils import DataFile
35

46

57
def test_parse_csv():
6-
assert parse_csv('1, 2, 3 \n 0, 2, na') == [[1, 2, 3], [0, 2, 'na']]
8+
Iris = DataFile('iris.csv').read()
9+
assert parse_csv(Iris)[0] == [5.1,3.5,1.4,0.2,'setosa']
710

811

912
def test_weighted_mode():
@@ -12,3 +15,21 @@ def test_weighted_mode():
1215

1316
def test_weighted_replicate():
1417
assert weighted_replicate('ABC', [1, 2, 1], 4) == ['A', 'B', 'B', 'C']
18+
19+
def test_plurality_learner():
20+
zoo = DataSet(name="zoo")
21+
22+
pL = PluralityLearner(zoo)
23+
assert pL([]) == "mammal"
24+
25+
def test_naive_bayes():
26+
iris = DataSet(name="iris")
27+
28+
nB = NaiveBayesLearner(iris)
29+
assert nB([5,3,1,0.1]) == "setosa"
30+
31+
def test_k_nearest_neighbors():
32+
iris = DataSet(name="iris")
33+
34+
kNN = NearestNeighborLearner(iris,k=3)
35+
assert kNN([5,3,1,0.1]) == "setosa"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy