-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix empty clusters before you add any items * Fix mass=1, start with mass=0. Fixes #1
- Loading branch information
Showing
5 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
*.pyc | ||
build/ | ||
pygvm.egg-info | ||
.tox | ||
dist | ||
MANIFEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import unittest2 | ||
from pygvm import Clusters | ||
|
||
class TestClusters(unittest2.TestCase): | ||
def test_empty_clusters(self): | ||
cs = Clusters(dimension=2, capacity=2) | ||
|
||
self.assertEqual(len(cs.clusters), 0) | ||
|
||
def test_first_point(self): | ||
cs = Clusters(dimension=2, capacity=2) | ||
|
||
cs.add(1, (5, 5), 'bert') | ||
self.assertEqual(len(cs.clusters), 1) | ||
self.assertEqual(len(cs.clusters[0]), 1) | ||
|
||
self.assertEqual(cs.clusters[0].mass, 1) | ||
self.assertEqual(cs.clusters[0].center, (5, 5)) | ||
|
||
def test_same_point_multiple_times(self): | ||
# NOTE: this is stupid. If you seed both clusters with the same | ||
# point, your clustering will basically just be random. | ||
cs = Clusters(dimension=2, capacity=2) | ||
|
||
cs.add(1, (5, 5), 'tom') | ||
self.assertEqual(len(cs.clusters), 1) | ||
self.assertEqual(len(cs.clusters[0]), 1) | ||
|
||
cs.add(1, (5, 5), 'dick') | ||
self.assertEqual(len(cs.clusters), 2) | ||
self.assertEqual(len(cs.clusters[0]), 1) | ||
self.assertEqual(len(cs.clusters[1]), 1) | ||
|
||
cs.add(1, (5, 5), 'harry') | ||
self.assertEqual(len(cs.clusters), 2) | ||
self.assertEqual(len(cs.clusters[0]), 2) | ||
self.assertEqual(len(cs.clusters[1]), 1) | ||
|
||
self.assertEqual(cs.clusters[0].mass, 2) | ||
self.assertEqual(cs.clusters[1].mass, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[tox] | ||
envlist= | ||
py26, | ||
py27, | ||
py33, | ||
py34 | ||
|
||
|
||
[testenv] | ||
deps = | ||
unittest2 | ||
commands = unit2.py pygvm.tests {posargs} | ||
|
||
[testenv:py26] | ||
basepython=python2.6 | ||
|
||
[testenv:py27] | ||
basepython=python2.7 | ||
|
||
[testenv:py33] | ||
basepython=python3.3 | ||
|
||
[testenv:py34] | ||
basepython=python3.4 |