Commit c2e2a560482f231947e8e4cc819129c504c5faed
1 parent
2b3fb488
add unit tests for printing functions
Showing
3 changed files
with
46 additions
and
2 deletions
Show diff stats
.coverage
1 | -!coverage.py: This is a private format, don't read it directly!{"lines":{"C:\\Users\\achil\\Desktop\\TD5\\test_structure.py":[1,3,4,5,7,8,9,13,19,26,36,44,49,57,65,71,14,15,16,17,21,22,23,24,27,28,29,30,31,32,33,34,37,38,39,40,41,42,45,46,47,50,51,52,53,54,55,58,59,60,61,62,63,66,67,68,69,72,73,74,75,76,77,78],"C:\\Users\\achil\\Desktop\\TD5\\structure.py":[1,2,4,5,6,18,22,23,28,34,41,44,51,54,61,64,74,75,90,91,99,100,108,109,122,132,139,149,171,191,199,215,224,237,260,235,13,14,15,16,24,25,26,96,97,244,245,246,250,251,252,253,254,255,256,62,267,271,42,35,36,37,38,39,45,46,47,48,49,29,30,52,113,114,115,116,117,118,119,105,106,120,127,128,129,145,146,147,130,137,69,70,55,56,57,58,59,71,72,19,20,220,221,81,82,83,84,85,86,87,88,197,207,208,209,210,211,212,213],"C:\\Users\\achil\\Desktop\\TD5\\main.py":[]}} | |
2 | 1 | \ No newline at end of file |
2 | +!coverage.py: This is a private format, don't read it directly!{"lines":{"C:\\Users\\achil\\Desktop\\TD5\\test_structure.py":[1,2,3,5,6,7,9,10,11,15,21,28,38,46,51,59,67,73,82,91,101,103,107,112,115,119,16,17,18,19,23,24,25,26,29,30,31,32,33,34,35,36,39,40,41,42,43,44,47,48,49,52,53,54,55,56,57,60,61,62,63,64,65,68,69,70,71,74,75,76,77,78,79,80,83,84,86,104,105,108,109,110,87,113,88,117,89,92,93,95,96,97,98],"C:\\Users\\achil\\Desktop\\TD5\\structure.py":[1,2,4,5,6,18,22,23,28,34,41,44,51,54,61,64,74,75,90,91,99,100,108,109,122,132,139,149,171,191,199,215,224,237,260,235,13,14,15,16,24,25,26,96,97,244,245,246,250,251,252,253,254,255,256,62,267,271,42,35,36,37,38,39,45,46,47,48,49,29,30,52,113,114,115,116,117,118,119,105,106,120,127,128,129,145,146,147,130,137,69,70,55,56,57,58,59,71,72,19,20,220,221,81,82,83,84,85,86,87,88,197,207,208,209,210,211,212,213,153,154,156,157,158,161,162,163,164,167,168,159,166,169,175,176,178,179,180,181,183,184,187,188,182,186,189],"C:\\Users\\achil\\Desktop\\TD5\\main.py":[]}} | |
3 | 3 | \ No newline at end of file | ... | ... |
.gitignore
test_structure.py
1 | 1 | from structure import * |
2 | +from io import StringIO | |
3 | +import sys | |
2 | 4 | |
3 | 5 | Tf = [[newCell(-38,-27,-54,-13,2,2),newCell(-74,-62,-48,-33,2,6),newCell(-13,-28,-12,-40,2,10) ],\ |
4 | 6 | [newCell(-34,-27,-38,-41,6,2), newCell(-64,-48,-72,-35,6,6), newCell(-45,-37,-20,-15,6,10)], \ |
... | ... | @@ -75,4 +77,45 @@ def test_getModeLikely(): |
75 | 77 | test_MM.path([5,6,7,6,7,6,7,5,6]) |
76 | 78 | assert test_MM.getMostLikely() == 7 |
77 | 79 | test_MM.path([4,4,4,4,4,4,4]) |
78 | - assert test_MM.getMostLikely() == 4 | |
79 | 80 | \ No newline at end of file |
81 | + assert test_MM.getMostLikely() == 4 | |
82 | + | |
83 | +def test_printValues(): | |
84 | + test_MM = MarkovModel(Tf) | |
85 | + test_MM.path([1,2,3,2,3,4,3,4]) | |
86 | + | |
87 | + with OutputBuffer() as output: | |
88 | + test_MM.printValues() | |
89 | + assert len(output.out) > 2500 | |
90 | + print(len(output.out)) | |
91 | + | |
92 | +def test_printPercentage(): | |
93 | + test_MM = MarkovModel(Tf) | |
94 | + test_MM.path([1,2,3,2,3,4,3,4]) | |
95 | + | |
96 | + with OutputBuffer() as output: | |
97 | + test_MM.printPercentages() | |
98 | + assert len(output.out) > 2000 | |
99 | + print(len(output.out)) | |
100 | + | |
101 | + | |
102 | +class OutputBuffer(object): | |
103 | + | |
104 | + def __init__(self): | |
105 | + self.stdout = StringIO() | |
106 | + self.stderr = StringIO() | |
107 | + | |
108 | + def __enter__(self): | |
109 | + self.original_stdout, self.original_stderr = sys.stdout, sys.stderr | |
110 | + sys.stdout, sys.stderr = self.stdout, self.stderr | |
111 | + return self | |
112 | + | |
113 | + def __exit__(self, exception_type, exception, traceback): | |
114 | + sys.stdout, sys.stderr = self.original_stdout, self.original_stderr | |
115 | + | |
116 | + @property | |
117 | + def out(self): | |
118 | + return self.stdout.getvalue() | |
119 | + | |
120 | + @property | |
121 | + def err(self): | |
122 | + return self.stderr.getvalue() | |
80 | 123 | \ No newline at end of file | ... | ... |