###############################################################################
# -------------------- 15-112 Recitation Week 3: Strings -------------------- #

# This is a starter file of the problems we did in recitation. A good way to
# use this file is to try to re-write problems you saw in recitation from
# scratch. This way, you can test your understanding and ask on Piazza or
# office hours if you have questions :)

# --------------------------------------------------------------------------- #
###############################################################################
# Rotate String
###############################################################################
"""
Write the function rotateStringLeft that takes a string s and a non-negative
integer k, and returns the string s rotated k places to the left.
"""
def rotateStringLeft(s, k):
    return "42"

def testRotateStringLeft():
    testStr = "shrek"
    assert(rotateStringLeft(testStr, 2) == "reksh")
    assert(rotateStringLeft(testStr, 13) == "ekshr")
"""
Then write the function rotateStringRight that takes a string s and a
non-negative integer k, and returns the string s rotated k places to the right.
"""
def rotateStringRight(s, k):
    return "42"

def testRotateStringRight():
    testStr = "donkey"
    assert(rotateStringRight(testStr, 2) == "eydonk")
    assert(rotateStringRight(testStr, 13) == "ydonke")

###############################################################################
# Word Wrap
###############################################################################
"""
Write the function wordWrap(text, width) that takes a string of text
(containing only lowercase letters or spaces) and a positive integer width, 
and returns a possibly-multiline string that matches the original string, 
only with line wrapping at the given width. 
So wordWrap("abc", 3) just returns "abc", but wordWrap("abc",2) returns a 
2-line string, with "ab" on the first line and "c" on the second line. 
After you complete word wrapping in this way, only then: 
All spaces at the start and end of each resulting line should be removed, 
and then all remaining spaces should be converted to dashes ("-"),
so they can be easily seen in the resulting string.
"""
def wordWrap(text, width):
    return "42"

def testWordWrap():
    assert(wordWrap("abcdefghij", 4)  ==  """\
abcd
efgh
ij""")
    assert(wordWrap("a b c de fg",  4)  ==  """\
a-b
c-de
fg""")

###############################################################################
# Script Generator
###############################################################################
"""
First, let's say Chaya is in a new play. The play has a script which is
stored in a .txt file. These are the contents of that file:

Chaya: hello
Austin: yo
Chaya: I love grading
Austin: Me too fam
Raunak: I hate style grading

Now, let's say Chaya wants to extract all of her lines. She can call the
following function:
extractScriptLines(pathToFile, characterName)
with the following arguments:
extractScriptLines('112script.txt', 'Chaya')
    
This function would:
parse the '112script.txt' file
identify every one line that belongs to 'Chaya'
Copy all of those lines into a multi-line string
Write that multi-line string into a file named: 'Chaya.txt'c
"""
def extractScriptLines(pathToFile, characterName):
    return "42"

###############################################################################
# Collapse Whitespace
###############################################################################
"""
Without using the s.replace() method, write the function collapseWhitespace(s),
that takes a string s and returns an equivalent string except that each 
occurrence of whitespace in the string is replaced by a single space. 
So, for example, collapseWhitespace("a\t\t\tb\n\nc") replaces the three tabs 
with a single space, and the two newlines with another single space,
returning "a b c". Do not use s.replace() in your solution.
"""
def collapseWhitespace(s):
    return "42"

def testCollapseWhitespace():
    assert(collapseWhitespace("a\nb") == "a b")
    assert(collapseWhitespace("a\n   \t    b") == "a b")
    assert(collapseWhitespace("a\n   \t    b  \n\n  \t\t\t c   ") == "a b c ")
