diff trafficintelligence/tests/utils.txt @ 1028:cc5cb04b04b0

major update using the trafficintelligence package name and install through pip
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 15 Jun 2018 11:19:10 -0400
parents python/tests/utils.txt@4f3387a242a1
children aafbc0bab925
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trafficintelligence/tests/utils.txt	Fri Jun 15 11:19:10 2018 -0400
@@ -0,0 +1,144 @@
+>>> from utils import *
+>>> from moving import Point
+
+>>> upperCaseFirstLetter('mmmm... donuts')
+'Mmmm... Donuts'
+>>> s = upperCaseFirstLetter('much ado about nothing')
+>>> s == 'Much Ado About Nothing'
+True
+>>> upperCaseFirstLetter(s) == s
+True
+
+>>> computeChi2([],[])
+0
+>>> computeChi2(list(range(1,10)),list(range(1,10)))
+0.0
+>>> computeChi2(list(range(1,9)),list(range(1,10)))
+0.0
+
+>>> ceilDecimals(1.23, 0)
+2.0
+>>> ceilDecimals(1.23, 1)
+1.3
+
+>>> inBetween(1,2,1.5)
+True
+>>> inBetween(2.1,1,1.5)
+True
+>>> inBetween(1,2,0)
+False
+
+>>> removeExtension('test-adfasdf.asdfa.txt')
+'test-adfasdf.asdfa'
+>>> removeExtension('test-adfasdf')
+'test-adfasdf'
+
+>>> values = line2Ints('1 2 3 5 6')
+>>> values[0]
+1
+>>> values[-1]
+6
+>>> values = line2Floats('1.3 2.45 7.158e+01 5 6')
+>>> values[0]
+1.3
+>>> values[2] #doctest: +ELLIPSIS
+71.5...
+>>> values[-1]
+6.0
+
+>>> stepPlot([3, 5, 7, 8], 1, 10, 0)
+([1, 3, 3, 5, 5, 7, 7, 8, 8, 10], [0, 0, 1, 1, 2, 2, 3, 3, 4, 4])
+
+>>> mostCommon(['a','b','c','b'])
+'b'
+>>> mostCommon(['a','b','c','b', 'c'])
+'b'
+>>> mostCommon(list(range(10))+[1])
+1
+>>> mostCommon([list(range(2)), list(range(4)), list(range(2))])
+[0, 1]
+
+>>> res = sortByLength([list(range(3)), list(range(4)), list(range(1))])
+>>> [len(r) for r in res]
+[1, 3, 4]
+>>> res = sortByLength([list(range(3)), list(range(4)), list(range(1)), list(range(5))], reverse = True)
+>>> [len(r) for r in res]
+[5, 4, 3, 1]
+
+>>> lcss = LCSS(similarityFunc = lambda x,y: abs(x-y) <= 0.1)
+>>> lcss.compute(list(range(5)), list(range(5)))
+5
+>>> lcss.compute(list(range(1,5)), list(range(5)))
+4
+>>> lcss.compute(list(range(5,10)), list(range(5)))
+0
+>>> lcss.compute(list(range(5)), list(range(10)))
+5
+>>> lcss.similarityFunc = lambda x,y: x == y
+>>> lcss.compute(['a','b','c'], ['a','b','c', 'd'])
+3
+>>> lcss.computeNormalized(['a','b','c'], ['a','b','c', 'd']) #doctest: +ELLIPSIS
+1.0
+>>> lcss.computeNormalized(['a','b','c','x'], ['a','b','c', 'd']) #doctest: +ELLIPSIS
+0.75
+>>> lcss.compute(['a','b','c'], ['a','b','c', 'd'])
+3
+>>> lcss.compute(['a','x','b','c'], ['a','b','c','d','x'])
+3
+>>> lcss.compute(['a','b','c','x','d'], ['a','b','c','d','x'])
+4
+>>> lcss.delta = 1
+>>> lcss.compute(['a','b','c'], ['a','b','x','x','c'])
+2
+
+>>> lcss.delta = float('inf')
+>>> lcss.compute(['a','b','c'], ['a','b','c', 'd'], computeSubSequence = True)
+3
+>>> lcss.subSequenceIndices
+[(0, 0), (1, 1), (2, 2)]
+>>> lcss.compute(['a','b','c'], ['x','a','b','c'], computeSubSequence = True)
+3
+>>> lcss.subSequenceIndices
+[(0, 1), (1, 2), (2, 3)]
+>>> lcss.compute(['a','g','b','c'], ['a','b','c', 'd'], computeSubSequence = True)
+3
+>>> lcss.subSequenceIndices
+[(0, 0), (2, 1), (3, 2)]
+
+>>> alignedLcss = LCSS(lambda x,y:(abs(x-y) <= 0.1), delta = 2, aligned = True)
+>>> alignedLcss.compute(list(range(5)), list(range(5)))
+5
+>>> alignedLcss.compute(list(range(1,5)), list(range(5)))
+4
+
+>>> alignedLcss.compute(list(range(5,10)), list(range(10)))
+5
+
+>>> lcss.delta = 2
+>>> lcss.compute(list(range(5,10)), list(range(10)))
+0
+>>> alignedLcss.delta = 6
+>>> alignedLcss.compute(list(range(5)), list(range(5)))
+5
+>>> alignedLcss.compute(list(range(5)), list(range(6)))
+5
+>>> lcss.delta = 10
+>>> alignedLcss.compute(list(range(1,7)), list(range(6)))
+5
+>>> lcss = LCSS(lambda x,y: x == y, delta = 2, aligned = True)
+>>> lcss.compute(list(range(20)), [2,4,6,7,8,9,11,13], True)
+8
+>>> lcss.subSequenceIndices
+[(2, 0), (4, 1), (6, 2), (7, 3), (8, 4), (9, 5), (11, 6), (13, 7)]
+
+>>> lcss = LCSS(metric = 'cityblock', epsilon = 0.1)
+>>> lcss.compute([[i] for i in range(5)], [[i] for i in range(5)])
+5
+>>> lcss.compute([[i] for i in range(1,5)], [[i] for i in range(5)])
+4
+>>> lcss.compute([[i] for i in range(5,10)], [[i] for i in range(5)])
+0
+>>> lcss.compute([[i] for i in range(5)], [[i] for i in range(10)])
+5
+
+