Exemplo n.º 1
0
 def test_escaped_ascii_string(self):
     input = "\"\\x27\""
     print(input)
     result = MemoryString.countEncodedCharacters(input)
     print(result)
     self.assertEqual(6, result['unencodedCharacters'])
     self.assertEqual(11, result['encodedCharacters'])
Exemplo n.º 2
0
 def test_abc_string(self):
     input = "\"abc\""
     print(input)
     result = MemoryString.countEncodedCharacters(input)
     print(result)
     self.assertEqual(5, result['unencodedCharacters'])
     self.assertEqual(9, result['encodedCharacters'])
Exemplo n.º 3
0
 def test_escaped_quote_string(self):
     input = "\"aaa\\\"aaa\""
     print(input)
     result = MemoryString.countEncodedCharacters(input)
     print(result)
     self.assertEqual(10, result['unencodedCharacters'])
     self.assertEqual(16, result['encodedCharacters'])
Exemplo n.º 4
0
 def test_empty_string(self):
     input = "\"\""
     print(input)
     result = MemoryString.countCharacters(input)
     print(result)
     self.assertEqual(0, result['memoryCharacters'])
     self.assertEqual(2, result['codeCharacters'])
Exemplo n.º 5
0
 def test_empty_string(self):
     input = "\"\""
     print(input)
     result = MemoryString.countEncodedCharacters(input)
     print(result)
     self.assertEqual(2, result['unencodedCharacters'])
     self.assertEqual(6, result['encodedCharacters'])
Exemplo n.º 6
0
 def test_abc_string(self):
     input = "\"abc\""
     print(input)
     result = MemoryString.countCharacters(input)
     print(result)
     self.assertEqual(3, result['memoryCharacters'])
     self.assertEqual(5, result['codeCharacters'])
Exemplo n.º 7
0
from memoryString import MemoryString

# compare the length of the string in code to the length of the string in memory:
# string is always quoted: "string"
# string can contain:
#   escaped quotes \"
#   escaped slashes \\
#   single ascii characters expressed as \x{0-f}{0-f}
#  "" is 2 characters of code and 0 characters in memory
#  "aaa\"aaa" is 10 characters of code and 7 characters of memory

totalCodeLength = 0
totalMemoryLength = 0
f = open('input.txt','r')
for line in f:
    trimmed = line.strip()
    result = MemoryString.countCharacters(trimmed)
    #text = "{l} {code} {memory}".format(l=trimmed, code=result['codeCharacters'], memory=result['memoryCharacters'])
    #print(text)
    totalCodeLength += result['codeCharacters']
    totalMemoryLength += result['memoryCharacters']

print(totalCodeLength)
print(totalMemoryLength)
print(totalCodeLength - totalMemoryLength)
Exemplo n.º 8
0
from memoryString import MemoryString

# compare the length of the string in code to the encoded length of the string:
# string is always quoted: "string"
# string can contain:
#   quotes " --> \"
#   slashes \ --> \\

totalUnencodedLength = 0
totalEncodedLength = 0
f = open('input.txt','r')
for line in f:
    trimmed = line.strip()
    result = MemoryString.countEncodedCharacters(trimmed)
    #text = "{l} {code} {memory}".format(l=trimmed, code=result['codeCharacters'], memory=result['memoryCharacters'])
    #print(text)
    totalUnencodedLength += result['unencodedCharacters']
    totalEncodedLength +=  result['encodedCharacters']

print(totalUnencodedLength)
print(totalEncodedLength)
print(totalEncodedLength - totalUnencodedLength)