-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
70 lines (55 loc) · 2 KB
/
Copy pathtesting.py
File metadata and controls
70 lines (55 loc) · 2 KB
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
60
61
62
63
64
65
66
67
68
69
70
import unittest
from compress import *
class MyTests(unittest.TestCase):
def test_isNum(self):
"""
Test that a string is correclty identified as a number
"""
data = '4'
result = obj.is_number(data)
self.assertEqual(result, True)
data2 = '@'
result2 = obj.is_number(data2)
self.assertEqual(result2, False)
def test_compressString(self):
"""
Test that a string is correctly compressed
"""
#Test with newline character
string = ",+@+,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:'@@#@#',,,,,,+@+,\n"
result = obj.compress_string(string)
self.assertEqual(result, ",+@+,32:'@2#@#',6+@+,")
#Test without newline character
string2 = ",#@',,,,,,,,,,,,,,,,,,,+@##@@;,,,,,,,,,,,,,,,,,,,,,,+@+"
result2 = obj.compress_string(string2)
self.assertEqual(result2, ",#@',19+@#2@2;,22+@+")
def test_decompString(self):
"""
Test that a string is correclty decompressed
"""
#Basic test
string = ",#@4+,"
result = obj.decompress_string(string)
self.assertEqual(result, ",#@@@@+,")
#Test if decompress works with double digit repeated characters
string2 = ",+@+,32:'@2#@#',6+@+,"
result2 = obj.decompress_string(string2)
self.assertEqual(result2, ",+@+,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:'@@#@#',,,,,,+@+,")
#Testing for index out of bounds errors
string3 = ",2"
result3 = obj.decompress_string(string3)
self.assertEqual(result3, ",,")
def test_repeated(self):
"""
Tests to ensure the correct number of times a character is reapeated
"""
string = ",+@+,28+@2,25+@+,"
result = obj.get_repeated(string)
self.assertEqual(result, '28')
string2 = "32+@+,"
result2 = obj.get_repeated(string2)
self.assertEqual(result2, '32')
# Main Function
if __name__ == '__main__':
obj = Compression()
unittest.main()