| 1 | # |
| 2 | # This is part of "python-cluster". A library to group similar items together. |
| 3 | # Copyright (C) 2006 Michel Albert |
| 4 | # |
| 5 | # This library is free software; you can redistribute it and/or modify it under |
| 6 | # the terms of the GNU Lesser General Public License as published by the Free |
| 7 | # Software Foundation; either version 2.1 of the License, or (at your option) |
| 8 | # any later version. |
| 9 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 12 | # details. |
| 13 | # You should have received a copy of the GNU Lesser General Public License |
| 14 | # along with this library; if not, write to the Free Software Foundation, Inc., |
| 15 | # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | # |
| 17 | |
| 18 | import unittest |
| 19 | |
| 20 | from cluster import KMeansClustering |
| 21 | try: |
| 22 | import numpy |
| 23 | NUMPY_AVAILABLE = True |
| 24 | except: |
| 25 | NUMPY_AVAILABLE = False |
| 26 | |
| 27 | |
| 28 | @unittest.skipUnless(NUMPY_AVAILABLE, |
| 29 | 'numpy not available. Associated test will not be loaded!') |
| 30 | class NumpyTests(unittest.TestCase): |
| 31 | |
| 32 | def testNumpyRandom(self): |
| 33 | data = numpy.random.rand(500, 2) |
| 34 | cl = KMeansClustering(data, lambda p0, p1: ( |
| 35 | p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2, numpy.array_equal) |
| 36 | cl.getclusters(10) |