File: test_ace.py

package info (click to toggle)
python-skbio 0.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,924 kB
  • sloc: python: 67,527; ansic: 672; makefile: 225
file content (40 lines) | stat: -rw-r--r-- 1,496 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# ----------------------------------------------------------------------------
# Copyright (c) 2013--, scikit-bio development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE.txt, distributed with this software.
# ----------------------------------------------------------------------------

import unittest

import numpy as np
import numpy.testing as npt

from skbio.diversity.alpha import ace


class AceTests(unittest.TestCase):
    def test_ace(self):
        npt.assert_almost_equal(ace(np.array([2, 0])), 1.0)
        npt.assert_almost_equal(ace(np.array([12, 0, 9])), 2.0)
        npt.assert_almost_equal(ace(np.array([12, 2, 8])), 3.0)
        npt.assert_almost_equal(ace(np.array([12, 2, 1])), 4.0)
        npt.assert_almost_equal(ace(np.array([12, 1, 2, 1])), 7.0)
        npt.assert_almost_equal(ace(np.array([12, 3, 2, 1])), 4.6)
        npt.assert_almost_equal(ace(np.array([12, 3, 6, 1, 10])), 5.62749672)

        # Just return the number of taxa when all are abundant.
        npt.assert_almost_equal(ace(np.array([12, 12, 13, 14])), 4.0)

        # Border case: only singletons and 10-tons, no abundant taxa.
        npt.assert_almost_equal(ace([0, 1, 1, 0, 0, 10, 10, 1, 0, 0]),
                                9.35681818182)

    def test_ace_only_rare_singletons(self):
        with self.assertRaises(ValueError):
            ace([0, 0, 43, 0, 1, 0, 1, 42, 1, 43])


if __name__ == '__main__':
    unittest.main()