Skip to content

Instantly share code, notes, and snippets.

@josezambrana
Created December 1, 2010 02:38
Show Gist options
  • Save josezambrana/722836 to your computer and use it in GitHub Desktop.
Save josezambrana/722836 to your computer and use it in GitHub Desktop.
__author__ = "Jose Maria Zambrana Arze "
__email__ = "contact@josezambrana.com"
import unittest
import math
def absDistinct ( A ):
""" return count of unique abs values in A """
res = {}
for n in A:
res[math.fabs(n)] = math.fabs(n)
return len(res.items())
class ProgramTestCase(unittest.TestCase):
def setUp(self):
self.serie1 = [2,3,1,1,3]
self.serie2 = []
def test_success(self):
res = absDistinct(self.serie1)
self.assertEqual(res, 3, "1,2,3,3 -> 3 error");
def test_empty(self):
res = absDistinct(self.serie2)
self.assertEqual(res, 0, "[] -> 0 error")
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment