-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathut_photon_count.py
59 lines (45 loc) · 1.95 KB
/
ut_photon_count.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""Unit tests for read_metadata."""
from __future__ import absolute_import, division, print_function
import unittest
import numpy as np
from PhotonCount.photon_count import photon_count
from PhotonCount.photon_count import PhotonCountException
class TestPhotonCount(unittest.TestCase):
"""Unit tests for photon_count function."""
def setUp(self):
self.thresh = 0.
def test_empty_array(self):
"""Verify that function works for an empty array."""
e_image = np.array([]).astype(float)
pc_image = photon_count(e_image, self.thresh)
self.assertTrue((pc_image == e_image).all())
def test_single_array(self):
"""Verify that function works for an array with only one element."""
e_image = np.ones(1)
pc_image = photon_count(e_image, self.thresh)
self.assertTrue((pc_image == e_image).all())
def test_long_array(self):
"""Verify that function works for a very long array."""
e_image = np.ones(1000000)
pc_image = photon_count(e_image, self.thresh)
self.assertTrue((pc_image == e_image).all())
def test_two_dimensional_array(self):
"""Verify that function works for a two dimensional array."""
e_image = np.ones([10, 10])
pc_image = photon_count(e_image, self.thresh)
self.assertTrue((pc_image == e_image).all())
def test_thresh(self):
"""Verify that function correctly trims values."""
e_image = np.array([1, 2, 3, 4, 5])
thresh = 2.
pc_image = photon_count(e_image, thresh)
expected = np.array([0, 0, 1, 1, 1]).astype(float)
self.assertTrue((pc_image == expected).all())
def test_exception_not_array(self):
"""Verify that exception is thrown if input is not an array."""
e_image = 1
with self.assertRaises(PhotonCountException):
photon_count(e_image, self.thresh)
if __name__ == '__main__':
unittest.main()