# Path: monty/string.py
# def remove_non_ascii(s):
#     """
#     Remove non-ascii characters in a file. Needed when support for non-ASCII
#     is not available.
# 
#     Args:
#         s (str): Input string
# 
#     Returns:
#         String with all non-ascii characters removed.
#     """
#     return "".join(i for i in s if ord(i) < 128)
# 
# def unicode2str(s):
#     """
#     Forces a unicode to a string in Python 2, but transparently handles
#     Python 3.
# 
#     Args:
#         s (str/unicode): Input string / unicode.
# 
#     Returns:
#         str in Python 2. Unchanged otherwise.
#     """
#     return s.encode("utf-8") if sys.version_info.major < 3 else s


import unittest
import random
import sys
from monty.string import remove_non_ascii, unicode2str
"""
TODO: Modify unittest doc.
"""




class FuncTest(unittest.TestCase):
    def test_remove_non_ascii(self):
        s = "".join(chr(random.randint(0, 127)) for i in range(10))
        s += "".join(chr(random.randint(128, 150)) for i in range(10))
        clean = remove_non_ascii(s)
        self.assertEqual(len(clean), 10)

    def test_unicode2str(self):
        if sys.version_info.major < 3:
            self.assertEqual(type(unicode2str("a")), str)
        else:

# Path: monty/string.py
# def remove_non_ascii(s):
#     """
#     Remove non-ascii characters in a file. Needed when support for non-ASCII
#     is not available.
# 
#     Args:
#         s (str): Input string
# 
#     Returns:
#         String with all non-ascii characters removed.
#     """
#     return "".join(i for i in s if ord(i) < 128)
# 
# def unicode2str(s):
#     """
#     Forces a unicode to a string in Python 2, but transparently handles
#     Python 3.
# 
#     Args:
#         s (str/unicode): Input string / unicode.
# 
#     Returns:
#         str in Python 2. Unchanged otherwise.
#     """
#     return s.encode("utf-8") if sys.version_info.major < 3 else s


# Path: tests/test_string.py
import unittest
import random
import sys
from monty.string import remove_non_ascii, unicode2str

"""
TODO: Modify unittest doc.
"""




class FuncTest(unittest.TestCase):
    def test_remove_non_ascii(self):
        s = "".join(chr(random.randint(0, 127)) for i in range(10))
        s += "".join(chr(random.randint(128, 150)) for i in range(10))
        clean = remove_non_ascii(s)
        self.assertEqual(len(clean), 10)

    def test_unicode2str(self):
        if sys.version_info.major < 3:
            self.assertEqual(type(unicode2str("a")), str)
        else:

            self.assertEqual(type(unicode2str("a")), str)